918
edits
m (Remove testing code) |
(Fix township building sticky header and add cell borders) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Monsters = require('Module:Monsters') | |||
local Shop = require('Module:Shop') | local Shop = require('Module:Shop') | ||
local GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
local Num = require('Module:Number') | |||
local p = {} | local p = {} | ||
Line 278: | Line 280: | ||
local seasonReqs = { | local seasonReqs = { | ||
["Nightfall"] = Icons.Icon({'Township%23Worship', 'Bane Worship', img='Statue of Bane', type='building'}), | ["Nightfall"] = Icons.Icon({'Township%23Worship', 'Bane Worship', img='Statue of Bane', type='building'}), | ||
["SolarEclipse"] = Icons.Icon({'Township%23Worship', 'The Herald Worship', img='Statue of The Herald', type='building'}) | ["SolarEclipse"] = Icons.Icon({'Township%23Worship', 'The Herald Worship', img='Statue of The Herald', type='building'}), | ||
["Lemon"] = Icons.Icon({'Ancient_Relics', 'Ancient Relics', img='Ancient Relics'}) | |||
} | } | ||
Line 314: | Line 317: | ||
table.insert(resultPart, '\n|- class="headerRow-1"') | table.insert(resultPart, '\n|- class="headerRow-1"') | ||
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Level', type='skill', nolink=true})) | table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Level', type='skill', nolink=true})) | ||
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township | table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' })) | ||
for i, biome in ipairs(Township.biomes) do | for i, biome in ipairs(Township.biomes) do | ||
Line 331: | Line 334: | ||
-- Skips upgraded buildings | -- Skips upgraded buildings | ||
function p.getBuildingBiomeTable(frame) | function p.getBuildingBiomeTable(frame) | ||
local tbl = mw.html.create('table') | |||
local | :addClass('wikitable sortable stickyHeader') | ||
:css('text-align', 'center') | |||
local header = mw.html.create('tr'):addClass('headerRow-0') | |||
local level = mw.html.create('tr'):addClass('sorttop') | |||
local pop = mw.html.create('tr'):addClass('sorttop') | |||
- | header:tag('th') | ||
:css('z-index', '2') | |||
:wikitext('Building') | |||
level:tag('th') | |||
:wikitext(Icons.Icon({'Township', 'Level', type='skill', nolink=true})) | |||
pop:tag('th') | |||
:wikitext(Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' })) | |||
for _, biome in ipairs(Township.biomes) do | for _, biome in ipairs(Township.biomes) do | ||
local reqs = p._getTierRequirements(biome.tier) | |||
header:tag('th') | |||
:wikitext(Icons.Icon({biome.name, type='biome', notext=true, nolink=true}).. '<br/>' .. biome.name) | |||
level:tag('td') | |||
:wikitext(Num.formatnum(reqs.level)) | |||
pop:tag('td') | |||
:wikitext(Num.formatnum(reqs.population)) | |||
end | end | ||
tbl:node(header) | |||
tbl:node(level) | |||
tbl:node(pop) | |||
for _, _building in ipairs(p._sortedBuildings(false)) do | for _, _building in ipairs(p._sortedBuildings(false)) do | ||
Line 354: | Line 376: | ||
end | end | ||
local trow = tbl:tag('tr') | |||
trow:tag('th') | |||
:css('text-align', 'left') | |||
:attr('data-sort-value', building.name) | |||
:wikitext(Icons.Icon({building.name, type='building'})) | |||
for _, biome in ipairs(Township.biomes) do | for _, biome in ipairs(Township.biomes) do | ||
if buildingBiomes[biome.id] then | if buildingBiomes[biome.id] then | ||
trow:tag('td') | |||
:addClass('table-positive') | |||
:wikitext('✓') | |||
else | else | ||
trow:tag('td') | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
return | return tostring(tbl) | ||
end | end | ||
Line 386: | Line 410: | ||
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"') | table.insert(resultPart, '{| class="wikitable sortable stickyHeader"') | ||
table.insert(resultPart, '\n|- class="headerRow-0"') | table.insert(resultPart, '\n|- class="headerRow-0"') | ||
table.insert(resultPart, '\n!colspan="2"|Building\n!Requirements | table.insert(resultPart, '\n!colspan="2"|Building\n!Requirements\n!Max Built') | ||
table.insert(resultPart, '\n!Biomes\n!Cost\n!Provides') | table.insert(resultPart, '\n!Biomes\n!Cost\n!Provides') | ||
Line 405: | Line 429: | ||
table.insert(resultPart, '\n' .. rowSpanOnly .. '| ' .. Icons.getExpansionIcon(building.id) .. Icons.Icon({buildingName, type='building', noicon=true})) | table.insert(resultPart, '\n' .. rowSpanOnly .. '| ' .. Icons.getExpansionIcon(building.id) .. Icons.Icon({buildingName, type='building', noicon=true})) | ||
table.insert(resultPart, '\n|' .. 'data-sort-value="' .. building.tier .. '"' .. rowSpan .. '| ' .. (p._getTierText(building.tier) or '')) | table.insert(resultPart, '\n|' .. 'data-sort-value="' .. building.tier .. '"' .. rowSpan .. '| ' .. (p._getTierText(building.tier) or '')) | ||
table.insert(resultPart, '\n|style="text-align:right"' .. rowSpan .. '| ' .. building.maxUpgrades) | table.insert(resultPart, '\n|style="text-align:right"' .. rowSpan .. '| ' .. building.maxUpgrades) | ||
firstRow = false | firstRow = false | ||
Line 564: | Line 587: | ||
-- ID | -- ID | ||
table.insert(ret, '\n|-\n| <b>Building ID:</b> ' .. building.id) | table.insert(ret, '\n|-\n| <b>Building ID:</b> ' .. building.id) | ||
-- Tier | -- Tier | ||
local tier = p._getTierText(building.tier) | local tier = p._getTierText(building.tier) | ||
Line 611: | Line 632: | ||
end | end | ||
-- Maximum built | |||
local biomeCount = Shared.tableCount(building.biomes) | |||
local maxText = Shared.formatnum(building.maxUpgrades) | |||
if biomeCount > 1 then | |||
maxText = maxText .. ' per biome, ' .. Shared.formatnum(biomeCount * building.maxUpgrades) .. ' total' | |||
end | |||
table.insert(ret, '\n|-\n| <b>Maximum Built:</b><br/>' .. maxText) | |||
-- Benefits | -- Benefits | ||
local benefits = p._getBuildingGroupedBenefitText(building) | local benefits = p._getBuildingGroupedBenefitText(building) | ||
Line 742: | Line 771: | ||
-- Requirements | -- Requirements | ||
table.insert(ret, '\n|') | table.insert(ret, '\n|') | ||
local | -- Determines order of requirements output | ||
local reqOrder = { | |||
local | ["items"] = 10, | ||
["monsters"] = 20, | |||
["monsterWithItems"] = 30, | |||
["skillXP"] = 40, | |||
["buildings"] = 50, | |||
["numPOIs"] = 60, | |||
["numRefinements"] = 70 | |||
} | |||
local reqTextPart = {} | |||
local function getItemText(itemID) | |||
local item = Items.getItemByID(itemID) | |||
if item == nil then | |||
return Shared.printError('Unknown item: ' .. (itemID or 'nil')) | |||
else | |||
return Icons.Icon({item.name, type='item'}) | |||
end | |||
end | end | ||
local function getMonsterText(monsterID) | |||
local | local monster = Monsters.getMonsterByID(monsterID) | ||
if monster == nil then | |||
return Shared.printError('Unknown monster: ' .. (monsterID or 'nil')) | |||
else | |||
return Icons.Icon({Monsters.getMonsterName(monster), type='monster'}) | |||
end | |||
end | end | ||
for goalType, goalData in pairs(task.goals) do | |||
local typeOrder = reqOrder[goalType] or 0 | |||
local goalText = nil | |||
if type(goalData) == 'table' then | |||
local | -- Goal data is a table | ||
table.insert( | for goalIdx, goalObj in ipairs(goalData) do | ||
if goalType == 'items' then | |||
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getItemText(goalObj.id) | |||
elseif goalType == 'monsters' then | |||
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.id) | |||
elseif goalType == 'monsterWithItems' then | |||
local itemsText = {} | |||
for i, itemID in ipairs(goalObj.itemIDs) do | |||
table.insert(itemsText, getItemText(itemID)) | |||
end | |||
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.monsterID) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped' | |||
elseif goalType == 'skillXP' then | |||
local skillName = GameData.getSkillData(goalObj.id).name | |||
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({skillName, type='skill'}) .. ' XP' | |||
elseif goalType == 'buildings' then | |||
local buildingName = p._GetBuildingByID(goalObj.id).name | |||
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({buildingName, type='building'}) | |||
elseif goalType == 'numPOIs' then | |||
local mapName = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, goalObj.worldMapID).name | |||
goalText = 'Discover ' .. Shared.formatnum(goalObj.quantity) .. ' Points of Interest in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' world map of ' .. mapName | |||
else | |||
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil')) | |||
end | |||
table.insert(reqTextPart, { | |||
["goalOrder"] = typeOrder, | |||
["subOrder"] = goalIdx, | |||
["text"] = goalText | |||
}) | |||
end | |||
else | |||
-- Goal data is another value of some type | |||
if goalType == 'numRefinements' then | |||
goalText = 'Refine dig site maps in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' ' .. Shared.formatnum(goalData) .. ' times' | |||
else | |||
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil')) | |||
end | end | ||
table.insert( | table.insert(reqTextPart, { | ||
["goalOrder"] = typeOrder, | |||
["subOrder"] = 0, | |||
["text"] = goalText | |||
}) | |||
end | end | ||
end | end | ||
table.sort(reqTextPart, | |||
function(a, b) | |||
if a.goalOrder == b.goalOrder then | |||
for | return a.subOrder < b.subOrder | ||
else | |||
table.insert(requirements, | return a.goalOrder < b.goalOrder | ||
end | |||
end | |||
) | |||
local requirements = {} | |||
for i, req in ipairs(reqTextPart) do | |||
table.insert(requirements, req.text) | |||
end | end | ||
-- We don't check tasks.requirements (so far it's only used to enumerate the Tutorial tasks so you only see 1 at a time) | -- We don't check tasks.requirements (so far it's only used to enumerate the Tutorial tasks so you only see 1 at a time) | ||
Line 831: | Line 924: | ||
local taskcount = 0 | local taskcount = 0 | ||
local ret = {} | local ret = {} | ||
table.insert(ret, '{| class="wikitable lighttable" style="text-align:left"') | table.insert(ret, '{| class="wikitable lighttable stickyHeader" style="text-align:left"') | ||
table.insert(ret, '\n|- class="headerRow-0"') | |||
table.insert(ret, '\n!Task') | table.insert(ret, '\n!Task') | ||
table.insert(ret, '\n!Requirements') | table.insert(ret, '\n!Requirements') | ||
Line 873: | Line 967: | ||
end | end | ||
if referenceType == 'monster' then | if referenceType == 'monster' then | ||
IDs[ | IDs[Monsters.getMonster(referenceName).id] = true | ||
end | end | ||
return IDs | return IDs |
edits