Module:Sandbox/GauTest/Township: Difference between revisions

Tasks
(Maps)
(Tasks)
Line 706: Line 706:
end
end
end
end
end
end
table.insert(ret, '\r\n|}')
return table.concat(ret)
end
-- Generates a table showing all the maps and the number of biomes
-- Skips upgraded buildings
function p.GetMapTable()
-- Setup the table
local ret = {}
table.insert(ret, '\r\n{| class="wikitable sortable" style="text-align:center"')
table.insert(ret, '\r\n!Map')
-- Make two table that will keep track of the max/min amount of land for each biome
-- At the same time, make the output table header
local biomeMax = {}
local biomeMin = {}
for _, biome in ipairs(Township.biomes) do
table.insert(ret, '\r\n!'..Icons.Icon({biome.name, type='biome', notext=true, nolink=true})..'<br>'..biome.name)
biomeMax[biome.id] = -1
biomeMin[biome.id] = Township.maxTownSize + 1
end
-- Find the min and max amount for each biome
for _, map in ipairs(Township.maps) do
for _, biome in ipairs(map.biomes) do
biomeMax[biome.biomeID] = math.max(biomeMax[biome.biomeID], biome.count)
biomeMin[biome.biomeID] = math.min(biomeMin[biome.biomeID], biome.count)
end
end
-- Draw all the map rows
for _, map in ipairs(Township.maps) do
table.insert(ret, '\r\n|-')
table.insert(ret, '\r\n!style="text-align:left"|'..map.name)
for _, biome in ipairs(map.biomes) do
-- Color the cell if min or max value
local max = biomeMax[biome.biomeID]
local min = biomeMin[biome.biomeID]
local count = biome.count
local class = count == max and 'table-positive' or count == min and 'table-negative' or ''
-- Insert cell
table.insert(ret, '\r\n|class="'..class..'"|'..count)
end
end
end
end
572

edits