Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
Migrate GetTownshipStatIcon to Icons.Icon
No edit summary
(Migrate GetTownshipStatIcon to Icons.Icon)
Line 1: Line 1:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:GauTest/Icons')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
Line 346: Line 346:
-- Tier
-- Tier
local tier = p._GetTierRequirements(building.tier)
local tier = p._GetTierRequirements(building.tier)
table.insert(ret, '\r\n|-\r\n| <b>Tier '..building.tier..'</b><ul><li>'..Icons._SkillReq('Township', tier.level, false)..'</li><li>'..p.GetTownshipStatIcon('Population')..' '..tier.population..'</li></ul>')
table.insert(ret, '\r\n|-\r\n| <b>Tier '..building.tier..'</b><ul><li>'..Icons._SkillReq('Township', tier.level, false)..'</li><li>'..Icons.Icon({'Population', type='township'})..'&nbsp;'..tier.population..'</li></ul>')
-- Upgrades From
-- Upgrades From
Line 357: Line 357:
local cost = {}
local cost = {}
for _, resource in ipairs(building.cost) do
for _, resource in ipairs(building.cost) do
table.insert(cost, Icons.Icon(p._GetResourceIcon(resource.id))..' '..resource.quantity)
table.insert(cost, Icons.Icon(p._GetResourceIcon(resource.id))..'&nbsp;'..resource.quantity)
end
end
table.insert(ret, '<b>Base Cost:</b> '..table.concat(cost, ', '))
table.insert(ret, '<b>Base Cost:</b> '..table.concat(cost, ', '))
Line 371: Line 371:
local upgrade_cost = {}
local upgrade_cost = {}
for _, resource in ipairs(upgradesTo[1].cost) do
for _, resource in ipairs(upgradesTo[1].cost) do
table.insert(upgrade_cost, Icons.Icon(p._GetResourceIcon(resource.id))..' '..resource.quantity)
table.insert(upgrade_cost, Icons.Icon(p._GetResourceIcon(resource.id))..'&nbsp;'..resource.quantity)
end
end
table.insert(ret, '<br><b>Upgrade Base Cost:</b> '..table.concat(upgrade_cost, ', '))
table.insert(ret, '<br><b>Upgrade Base Cost:</b> '..table.concat(upgrade_cost, ', '))
Line 385: Line 385:
deadStorage = 'Dead Storage'
deadStorage = 'Dead Storage'
}
}
for key, name in pairs(stats) do
for key, stat in pairs(stats) do
if building.provides[key] ~= nil and building.provides[key] ~= 0 then
if building.provides[key] ~= nil and building.provides[key] ~= 0 then
table.insert(benefits, p.GetTownshipStatIcon(name)..' '..building.provides[key])
table.insert(benefits, Icons.Icon({stat, type='township'})..'&nbsp;'..building.provides[key])
end
end
end
end
Line 406: Line 406:
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 = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:green">'..Icons.Icon(p._GetResourceIcon(resource.id))..' +'..production..'</span>')
table.insert(retProduction, '<span style="color:green">'..Icons.Icon(p._GetResourceIcon(resource.id))..'&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
table.insert(retProduction, '<span style="color:red">'..Icons.Icon(p._GetResourceIcon(required_resource.id))..' -'..demand..'</span>')
table.insert(retProduction, '<span style="color:red">'..Icons.Icon(p._GetResourceIcon(required_resource.id))..'&nbsp;-'..demand..'</span>')
end
end
end
end
retProduction = table.concat(retProduction, ', ')..'/t ('..p.GetTownshipStatIcon('Workers')..' '..workers..')'
retProduction = table.concat(retProduction, ', ')..'/t ('..Icons.Icon({'Workers', type='township'})..'&nbsp;'..workers..')'
table.insert(retResources, retProduction)
table.insert(retResources, retProduction)
end
end
Line 446: Line 446:
return table.concat(ret)
return table.concat(ret)
end
end
-- 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)
function p.GetTownshipStatIcon(stat)
local changing_color = {
Population = true,
Workers = true,
Storage = true,
Happiness = false,
Education = false,
Health = false,
Worship = false,
["Dead Storage"] = false,
}
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>'
end


-- Given a resource id, return the job id
-- Given a resource id, return the job id
572

edits