Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
Refactoring
No edit summary
(Refactoring)
Line 84: Line 84:
return resources
return resources
end
end
p.resources = p._ResourcesData()


-- Returns a list of all the Township resources along with the Trader's trade ratios
-- Returns a list of all the Township resources along with the Trader's trade ratios
Line 185: Line 184:
return resources
return resources
end
end
p.resources = p._TraderData()


-- Builds the table of trader items
-- Builds the table of trader items
function p.GetTraderTable(frame)
function p.GetTraderTable(frame)
-- Get the resources data with associated trader data
-- Get the resources data with associated trader data
local resources = p._TraderData()
-- Build the text
-- Build the text
local ret = {}
local ret = {}
for _, resource in ipairs(resources) do
for _, resource in ipairs(p.resources) do
if #resource.itemConversions ~= 0 then -- Skips GP
if #resource.itemConversions ~= 0 then -- Skips GP
local ret_resource = {}
local ret_resource = {}
Line 415: Line 414:
function p._GetBuildingBaseProduction(building)
function p._GetBuildingBaseProduction(building)
local production = Shared.clone(building.provides.resources)
local production = Shared.clone(building.provides.resources)
local resources = p._ResourcesData()
if #production == 0 then
if #production == 0 then
Line 428: Line 426:
-- Sourced from township.js -> Township.computeTownResourceGain()
-- Sourced from township.js -> Township.computeTownResourceGain()
local production = resource.quantity*100*(Township.tickLength/10)
local production = resource.quantity*100*(Township.tickLength/10)
local resource_data = GameData.getEntityByID(resources, resource.id)
local resource_data = p._GetResourceByID(resource.id)
table.insert(retProduction, '<span style="color:green">'..Icons.Icon({resource_data.name, type='resource', notext=true})..'&nbsp;+'..production..'</span>')
table.insert(retProduction, '<span style="color:green">'..Icons.Icon({resource_data.name, type='resource', notext=true})..'&nbsp;+'..production..'</span>')
if resource_data.requires ~= nil and #resource_data.requires > 0 then
if resource_data.requires ~= nil and #resource_data.requires > 0 then
for _, required_resource in ipairs(resource_data.requires) do
for _, required_resource in ipairs(resource_data.requires) do
local demand = production*required_resource.quantity*100
local demand = production*required_resource.quantity*100
local required_resource_data = GameData.getEntityByID(resources, resource.id)
local required_resource_data = p._GetResourceByID(required_resource.id)
table.insert(retProduction, '<span style="color:red">'..Icons.Icon({required_resource_data.name, type='resource', notext=true})..'&nbsp;-'..demand..'</span>')
table.insert(retProduction, '<span style="color:red">'..Icons.Icon({required_resource_data.name, type='resource', notext=true})..'&nbsp;-'..demand..'</span>')
end
end
572

edits