Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
moved _GetResourceIcon into Icons.Icon
No edit summary
(moved _GetResourceIcon into Icons.Icon)
Line 6: Line 6:


local resource_data = {
local resource_data = {
['melvorF:GP'] = {icon = {'Coins'}, skill = nil},
['melvorF:GP'] = {skill = nil},
['melvorF:Food'] = {icon = {'Raw Beef', type='item'}, skill = 'melvorD:Cooking'},
['melvorF:Food'] = {skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {icon = {'Wood', type='resource'}, skill = 'melvorD:Woodcutting'},
['melvorF:Wood'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {icon = {'Stone', type='resource'}, skill = 'melvorD:Mining'},
['melvorF:Stone'] = {skill = 'melvorD:Mining'},
['melvorF:Ore'] = {icon = {'Iron', type='rock'}, skill = 'melvorD:Mining'},
['melvorF:Ore'] = {skill = 'melvorD:Mining'},
['melvorF:Coal'] = {icon = {'Coal', type='resource'}, skill = 'melvorD:Mining'},
['melvorF:Coal'] = {skill = 'melvorD:Mining'},
['melvorF:Bar'] = {icon = {'Iron Bar', type='item'}, skill = 'melvorD:Smithing'},
['melvorF:Bar'] = {skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {icon = {'Garum Herb', type='item'}, skill = 'melvorD:Farming'},
['melvorF:Herbs'] = {skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {icon = {'Rune Essence', type='item'}, skill = 'melvorD:Mining'},
['melvorF:Rune_Essence'] = {skill = 'melvorD:Mining'},
['melvorF:Leather'] = {icon = {'Leather', type='item'}, skill = nil},
['melvorF:Leather'] = {skill = nil},
['melvorF:Potions'] = {icon = {'Potion', type='resource'}, skill = 'melvorD:Herblore'},
['melvorF:Potions'] = {skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {icon = {'Planks', type='resource'}, skill = 'melvorD:Woodcutting'},
['melvorF:Planks'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {icon = {'Leather Body', type='item'}, skill = 'melvorD:Crafting'}
['melvorF:Clothing'] = {skill = 'melvorD:Crafting'}
}
}


Line 275: Line 275:
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.toTownship .. '"|'..Icons.Icon({item.name, type='item', notext=true})..' '..Shared.formatnum(item.toTownship))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.toTownship .. '"|'..Icons.Icon({item.name, type='item', notext=true})..' '..Shared.formatnum(item.toTownship))
-- Take From
-- Take From
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.fromTownship .. '"|'..Icons.Icon(p._GetResourceIcon(resource.id))..' '..Shared.formatnum(item.fromTownship))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.fromTownship .. '"|'..Icons.Icon({resource.name, type='resource', notext=true})..' '..Shared.formatnum(item.fromTownship))
-- Value
-- Value
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor .. '"|'..Icons.GP(item.sellsFor))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor .. '"|'..Icons.GP(item.sellsFor))
Line 294: Line 294:
end
end
return table.concat(ret)
return table.concat(ret)
end
-- TODO integrate into Icons.imgOverrides
-- Gets the icon of a resource
-- e.g. Icons.Icon(_GetResourceIcon('melvorF:Bar'))
function p._GetResourceIcon(id)
local resource_icon = Shared.clone(resource_data[id].icon)
resource_icon.notext = true
resource_icon.nolink = true
return resource_icon
end
end


Line 357: Line 347:
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({resource.name, type='resource', notext=true})..' '..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 361:
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))..'&nbsp;'..resource.quantity)
table.insert(upgrade_cost, Icons.Icon({resource.name, type='resource', notext=true})..'&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 406: Line 396:
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))..'&nbsp;+'..production..'</span>')
table.insert(retProduction, '<span style="color:green">'..Icons.Icon({resource.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
table.insert(retProduction, '<span style="color:red">'..Icons.Icon(p._GetResourceIcon(required_resource.id))..'&nbsp;-'..demand..'</span>')
table.insert(retProduction, '<span style="color:red">'..Icons.Icon({required_resource.name, type='resource', notext=true})..'&nbsp;-'..demand..'</span>')
end
end
end
end
572

edits