432
edits
(Added getDiscoveryRewardsTable for showing item sources from POIs) |
No edit summary |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 16: | Line 16: | ||
end | end | ||
return nil | return nil | ||
end | |||
function p.getPointOfInterestByXY(X, Y) | |||
local hex = p.getHexByXY(X, Y) | |||
if hex == nil then | |||
return nil | |||
end | |||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | |||
if (POI.coords.q == hex.coordinates.q and | |||
POI.coords.r == hex.coordinates.r) then | |||
return POI | |||
end | |||
end | |||
return hex | |||
end | end | ||
Line 125: | Line 139: | ||
end | end | ||
return rewardTable | return rewardTable | ||
end | |||
function p.sortPOIByCoords(array) | |||
table.sort(array, function(a, b) | |||
local aX, aY = p.convertAxialToXY(a.coords) | |||
local bX, bY = p.convertAxialToXY(b.coords) | |||
if aX ~= bX then | |||
return aX < bX | |||
else | |||
return aY < bY | |||
end | |||
end) | |||
return array | |||
end | end | ||
Line 137: | Line 164: | ||
table.insert(POIs, POI) | table.insert(POIs, POI) | ||
end | end | ||
POIs = p.sortPOIByCoords(POIs) | |||
for i, POI in pairs(POIs) do | for i, POI in pairs(POIs) do | ||
Line 203: | Line 222: | ||
end | end | ||
function p._getDiscoveryRewardsTable( | function p._getDiscoveryRewardsTable(items) | ||
local POIs = {} | local POIs = {} | ||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | ||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | ||
for i, reward in pairs(POI.discoveryRewards.items) do | for i, reward in pairs(POI.discoveryRewards.items) do | ||
if reward.id == item.id then | for j, item in ipairs(items) do | ||
if reward.id == item.id then | |||
table.insert(POIs, POI) | |||
break | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
POIs = p.sortPOIByCoords(POIs) | |||
-- Build the table | -- Build the table | ||
local resultTable = | local resultTable = mw.html.create('table') | ||
resultTable:addClass('wikitable sortable') | |||
resultTable:tag('tr'):addClass('headerRow-0') | |||
:tag('th'):wikitext('Point of Interest') | |||
:tag('th'):wikitext('X') | |||
:tag('th'):wikitext('Y') | |||
:tag('th'):wikitext('Requirements') | |||
:tag('th'):wikitext('Discovery Rewards') | |||
for _, POI in ipairs(POIs) do | for _, POI in ipairs(POIs) do | ||
local X, Y = p.convertAxialToXY(POI.coords) | local X, Y = p.convertAxialToXY(POI.coords) | ||
local tr = mw.html.create('tr') | |||
tr:tag('td'):wikitext(Icons.Icon({POI.name, type='poi'})) | |||
tr:tag('td'):wikitext(X) | |||
tr:tag('td'):wikitext(Y) | |||
tr:tag('td'):wikitext(table.concat(p._getPOIRequirements(POI), '<br/>')) | |||
tr:tag('td'):wikitext(table.concat(p._getDiscoveryRewards(POI), '<br/>')) | |||
resultTable:node(tr) | |||
end | end | ||
return tostring(resultTable) | |||
return | |||
end | end | ||
function p.getDiscoveryRewardsTable(frame) | function p.getDiscoveryRewardsTable(frame) | ||
local | local itemNames = frame.args ~= nil and frame.args[1] or frame | ||
local item = Items.getItem(itemName) | local items = {} | ||
if | for itemName in string.gmatch(itemNames, "[^,]*") do | ||
return Shared.printError('No | item = Items.getItem(itemName) | ||
if item ~= nil then | |||
table.insert(items, item) | |||
end | |||
end | |||
if #items == nil then | |||
return Shared.printError('No items found for with names: "' .. itemNames .. '"') | |||
end | end | ||
return p._getDiscoveryRewardsTable(item) | return '==POI Discovery Rewards==\n' .. p._getDiscoveryRewardsTable(items) | ||
end | |||
function p.testDiscoveryRewards() | |||
local testTable = {} | |||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | |||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | |||
local item = Items.getItemByID(POI.discoveryRewards.items[1].id) | |||
table.insert(testTable, p._getDiscoveryRewardsTable({item})) | |||
end | |||
end | |||
return table.concat(testTable) | |||
end | |||
function p.hex(frame) | |||
-- Default behavior, when no coords supplied | |||
if (frame == nil or frame.args['x'] == nil or frame.args['y'] == nil) then | |||
return 'Hex' | |||
end | |||
local X = tonumber(frame.args['x']) | |||
local Y = tonumber(frame.args['y']) | |||
if X == nil or Y == nil then | |||
return '<invalid XY format>' | |||
end | |||
local hex = p.getPointOfInterestByXY(X, Y) | |||
-- nil means coord is invalid | |||
if hex == nil then | |||
return '<invalid XY coord>' | |||
end | |||
local notext = frame.args['notext'] or false | |||
local noicon = frame.args['noicon'] or false | |||
local nolink = frame.args['nolink'] or false | |||
local coords = '<span>(' .. X .. ',' .. Y .. ')</span>' | |||
-- Valid, but not a POI | |||
if hex['id'] == nil or noicon then | |||
return coords | |||
end | |||
-- Valid POI | |||
local poi_icon = Icons.Icon({hex['name'], type='poi', notext=notext or nil, nolink=nolink or nil, size='25'}) | |||
return '<span>' .. poi_icon .. ' ' .. coords .. '</span>' | |||
end | end | ||
edits