Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 374: Line 374:


-- Production (todo)
-- Production (todo)
table.insert(ret, '\r\n|-\r\n| <b>Produces:</b><br>')
local retProduction = {}
local production = Shared.clone(building.provides.resources)
for _, resource in ipairs(production) do
local job = p._GetJobFromResource(resource.id)
local workers = GameData.getEntityByID(building.provides.workers, job).quantity
-- township.js -> Township.computeTownResourceGain()
local production = workers*resource.quantity*100*(Township.tickLength/10)
local resource_data = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:green">'..Icons.Icon(p._GetResourceIcon(resource.id))..' -'..production..'</span>')
if resource_data.requires ~= nil and #resource_data.requires > 0 then
for _, required_resource in ipairs(resource_data.requires) do
local demand = workers*resource.quantity*100*(Township.tickLength/10)
table.insert(retProduction, '<br><span style="color:red">'..Icons.Icon(p._GetResourceIcon(required_resource.id))..' -'..demand..'</span>')
end
end
end


-- Modifiers
-- Modifiers
Line 385: Line 402:
end
end


-- Todo - integrate into Icons.Icon?
-- Todo - integrate into Icons.Icon
-- Township Icons are licensed from Font Awesome Free 5.14.0 under CC BY 4.0 (https://github.com/FortAwesome/Font-Awesome/tree/5.14.0)
-- Township Icons are licensed from Font Awesome Free 5.14.0 under CC BY 4.0 (https://github.com/FortAwesome/Font-Awesome/tree/5.14.0)
function p.GetTownshipStatIcon(stat)
function p.GetTownshipStatIcon(stat)
Line 400: Line 417:
local class = changing_color[stat] and ' class="township-colortoggle"' or ''
local class = changing_color[stat] and ' class="township-colortoggle"' or ''
return '<span style="display:inline-block"'..class..'>[[File:'..stat..'_(township).svg|25x25px|link='..stat..']]</span>'
return '<span style="display:inline-block"'..class..'>[[File:'..stat..'_(township).svg|25x25px|link='..stat..']]</span>'
end
-- Given a resource id, return the job id
-- e.g. melvorF:Bar -> melvorF:Blacksmith
function p._GetJobFromResource(resource_id)
local job = GameData.getEntityByProperty(Township.jobs, 'produces', resource_id)
return job.id
end
end


Line 407: Line 432:
p.Township = Township
p.Township = Township


function p.Test()
for _, building in ipairs(Township.buildings) do
if building.modifiers ~= nil then
mw.log(building.name)
mw.logObject(building.modifiers)
end
end
end


return p
return p
572

edits