Module:Sandbox/GauTest/Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:GauTest/Icons')
local Icons = require('Module:Icons')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')




local p = {}


local Township = GameData.getSkillData('melvorD:Township')
local Township = GameData.getSkillData('melvorD:Township')
 
p.Township = Township
local p = {}


-- Returns the namespace name (eventually we should use an icon)
-- Returns the namespace name (eventually we should use an icon)
Line 369: Line 369:


-- Fixed benefits
-- Fixed benefits
local benefits = {}
local benefits = p._GetBuildingBenefits(building)
local stats = {
if benefits ~= nil then
population = 'Population',
table.insert(ret, '\r\n|-\r\n| <b>Provides:</b> '..benefits)
happiness = 'Happiness',
education = 'Education',
storage = 'Storage',
deadStorage = 'Dead Storage'
}
for key, stat in pairs(stats) do
if building.provides[key] ~= nil and building.provides[key] ~= 0 then
table.insert(benefits, Icons.Icon({stat, type='township', notext=true})..'&nbsp;'..building.provides[key])
end
end
if #benefits > 0 then
table.insert(ret, '\r\n|-\r\n| <b>Provides:</b> '..table.concat(benefits, ', '))
end
end


Line 428: Line 416:
end
end


-- Gets a string displaying the base production of a building
-- Gets a string displaying the base production of a building, or nil if no production
function p._GetBuildingBaseProduction(building)
function p._GetBuildingBaseProduction(building)
local production = Shared.clone(building.provides.resources)
local production = Shared.clone(building.provides.resources)
Line 459: Line 447:
end
end


-- Testing
-- Gets a string displaying the building's benefits, or nil if no benefits
p.GameData = GameData
function p._GetBuildingBenefits(building)
p.Icons = Icons
local stats = {
p.Township = Township
population = 'Population',
 
happiness = 'Happiness',
education = 'Education',
storage = 'Storage',
deadStorage = 'Dead Storage'
}
for key, stat in pairs(stats) do
if building.provides[key] ~= nil and building.provides[key] ~= 0 then
table.insert(benefits, Icons.Icon({stat, type='township', notext=true})..'&nbsp;'..building.provides[key])
end
end
if #benefits > 0 then
return table.concat(benefits, ', ')
end
return nil
end


return p
return p
572

edits