Module:Sandbox/GauTest/Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 502: Line 502:
function p._GetResourceByID(id)
function p._GetResourceByID(id)
return GameData.getEntityByID(p.resources, id)
return GameData.getEntityByID(p.resources, id)
end
-- Gets text for only the biomes that have a modifier for a building
function p._GetBiomeModifiers(building)
if #building.biomeModifiers == 0 then
return nil
end
local biomeRet = {}
table.insert(biomeRet, '<ul>')
for _, biome in ipairs(building.biomeModifiers) do
local biomename = GameData.getEntityByID(Township.biomes, biome.biomeID).name
local color = biome.value < 0 and 'red' or 'green'
local biome_value = Shared.numStrWithSign(biome.value)
table.insert(biomeRet, '<li style="color:'..color..'">'..biomename..' ('..biome_value..'%)</li>')
end
table.insert(biomeRet, '</ul>')
return table.concat(biomeRet)
end
end


Line 569: Line 587:
-- Production
-- Production
table.insert(ret, '\r\n|-')
local production = {}
local hasProduction = false
for _, building in ipairs(buildingList) do
for _, building in ipairs(buildingList) do
local production = p._GetBuildingBaseProduction(building)
local product = p._GetBuildingBaseProduction(building)
production = production ~= nil and production or ''
hasProduction = hasProduction == true or product ~= nil
table.insert(ret, '\r\n|'..production)
product = product ~= nil and product or ''
table.insert(production, product)
end
if hasProduction == true then
production = table.concat(production, '\r\n|')
table.insert(ret, '\r\n|-\r\n! Production\r\n|'..production)
end
end
-- Biomes Modifiers
-- Biomes Modifiers
table.insert(ret, '\r\n|-')
local biomeModifiers = {}
local hasBiomeModifiers = false
for _, building in ipairs(buildingList) do
for _, building in ipairs(buildingList) do
local biomeRet = {}
local biomeModifier = p._GetBiomeModifiers(building)
table.insert(biomeRet, '<ul>')
hasBiomeModifiers = hasBiomeModifiers == true or biomeModifier ~= nil
for _, biome in ipairs(building.biomeModifiers) do
biomeModifier = biomeModifier ~= nil and biomeModifier or ''
local biomename = GameData.getEntityByID(Township.biomes, biome.biomeID).name
table.insert(biomeModifiers, biomeModifier)
local color = biome.value < 0 and 'red' or 'green'
local biome_value = Shared.numStrWithSign(biome.value)
table.insert(biomeRet, '<li style="color:'..color..'">'..biomename..' ('..biome_value..'%)</li>')
end
table.insert(biomeRet, '</ul>')
table.insert(ret, '\r\n|'..table.concat(biomeRet))
end
end
if hasBiomeModifiers == true then
biomeModifiers = table.concat(biomeModifiers, '\r\n|')
table.insert(ret, '\r\n|-\r\n! Biome Modifiers\r\n|'..biomeModifiers)
end


-- End
-- End
572

edits