Anonymous

Module:Township: Difference between revisions

From Melvor Idle
Fix township building sticky header and add cell borders
(Unhide Lemon Season)
(Fix township building sticky header and add cell borders)
Line 6: Line 6:
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 333: Line 334:
-- Skips upgraded buildings
-- Skips upgraded buildings
function p.getBuildingBiomeTable(frame)
function p.getBuildingBiomeTable(frame)
-- Setup the table
local tbl = mw.html.create('table')
local ret = {}
:addClass('wikitable sortable stickyHeader')
table.insert(ret, '{| class="wikitable sortable stickyHeader" style="text-align:center"')
:css('text-align', 'center')


-- Generate the table header, one column per biome
local header = mw.html.create('tr'):addClass('headerRow-0')
local biomeRows = {
local level = mw.html.create('tr'):addClass('sorttop')
['head'] = { '\n|- class="headerRow-0"\n! Building' },
local pop = mw.html.create('tr'):addClass('sorttop')
['level'] = { '\n|- class="sorttop"\n! ' .. Icons.Icon({'Township', 'Level', type='skill', nolink=true}) },
 
['pop'] = { '\n|- class="sorttop"\n! ' .. Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' }) }
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)
local reqs = p._getTierRequirements(biome.tier)
table.insert(biomeRows.head,  '\n! ' .. Icons.Icon({biome.name, type='biome', notext=true, nolink=true}) .. '<br/>' .. biome.name)
header:tag('th')
table.insert(biomeRows.level, '\n| ' .. Shared.formatnum(reqs.level))
:wikitext(Icons.Icon({biome.name, type='biome', notext=true, nolink=true}).. '<br/>' .. biome.name)
table.insert(biomeRows.pop, '\n| ' .. Shared.formatnum(reqs.population))
level:tag('td')
:wikitext(Num.formatnum(reqs.level))
pop:tag('td')
:wikitext(Num.formatnum(reqs.population))
end
end
table.insert(ret, table.concat(biomeRows.head))
table.insert(ret, table.concat(biomeRows.level))
tbl:node(header)
table.insert(ret, table.concat(biomeRows.pop))
tbl:node(level)
biomeRows = nil
tbl:node(pop)


for _, _building in ipairs(p._sortedBuildings(false)) do
for _, _building in ipairs(p._sortedBuildings(false)) do
Line 366: Line 376:
end
end


-- Build the row
local trow = tbl:tag('tr')
table.insert(ret, '\n|-')
trow:tag('th')
table.insert(ret, '\n!data-sort-value="' .. building.name .. '" style="text-align:left"| ' .. Icons.Icon({building.name, type='building'}))
: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
-- Buildable
trow:tag('td')
table.insert(ret, '\n|class="table-positive"| ✓')
:addClass('table-positive')
:wikitext('✓')
else
else
-- Invalid biome
trow:tag('td')
table.insert(ret, '\n|style="border:0px"|')
end
end
end
end
end
end
end
end
table.insert(ret, '\n|}')


return table.concat(ret)
return tostring(tbl)
end
end


2,875

edits