Anonymous

Module:Township: Difference between revisions

From Melvor Idle
no edit summary
 
No edit summary
Line 1: Line 1:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local GameData = require('Module:GameData')


-- Data Module
-- Data Module
Line 159: Line 160:
-- Returns a list of all the Township resources
-- Returns a list of all the Township resources
function Data.Township.Resources()
function Data.Township.Resources()
-- Input for Module:Icons.Icon to generate the correct resource image
-- Get a sorted list of all the resources
local Township = GameData.getSkillData('melvorD:Township')
local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder[1].ids)
resources = Shared.clone(resources)
-- Append the icon reference to each resource
-- From https://melvoridle.com/assets/data/melvorFull.json -> data.skillData -> Township.data.resources.media
local resource_icons = {
local resource_icons = {
GP = {coins, notext=true, nolink=true},
['melvorF:GP'] = {'Coins'},
Food = {'Raw Beef', type='item', notext=true, nolink=true},
['melvorF:Food'] = {'Raw Beef', type='item'},
Wood = {'Wood', type='resource', notext=true, nolink=true},
['melvorF:Wood'] = {'Wood', type='resource'},
Stone = {'Stone', type='resource', notext=true, nolink=true},
['melvorF:Stone'] = {'Stone', type='resource'},
Ore = {'Iron Ore', type='rock', notext=true, nolink=true},
['melvorF:Ore'] = {'Iron Ore', type='rock'},
Coal = {'Coal', type='resource', notext=true, nolink=true},
['melvorF:Coal'] = {'Coal', type='resource'},
Bar = {'Iron Bar', type='item', notext=true, nolink=true},
['melvorF:Bar'] = {'Iron Bar', type='item'},
Herbs = {'Garum Herb', type='item', notext=true, nolink=true},
['melvorF:Herbs'] = {'Garum Herb', type='item'},
Rune_Essence = {'Rune Essence', type='item', notext=true, nolink=true},
['melvorF:Rune_Essence'] = {'Rune Essence', type='item'},
Leather = {'Leather', type='item', notext=true, nolink=true},
['melvorF:Leather'] = {'Leather', type='item'},
Potions = {'Potion', type='resource', notext=true, nolink=true},
['melvorF:Potions'] = {'Potion', type='resource'},
Planks = {'Planks', type='resource', notext=true, nolink=true},
['melvorF:Planks'] = {'Planks', type='resource'},
Clothing = {'Leather Body', type='item', notext=true, nolink=true}
['melvorF:Clothing'] = {'Leather Body', type='item'}
}
}
 
for _, resource in ipairs(resources) do
-- Save all the resources to a table
resource._icon = resource_icons[resource.id]
local resources = {}
resource._icon.notext = true
for namespace, data in pairs(Namespaces) do
resource._icon.nolink = true
local Township = Data.tableMatch(data.data.skillData, 'skillID', 'melvorD:Township')
if Township ~= nil and Township.data.resources ~= nil then
for _, resource in ipairs(Township.data.resources) do
local resourcecopy = Shared.clone(resource)
resourcecopy._namespace = namespace
resourcecopy._icon = resource_icons[resourcecopy.id]
table.insert(resources, resourcecopy)
end
end
end
end


-- Sort the resources according to the canonical sort order
return resources
-- We get the sort order from data.skillData -> Township.data.resourceDisplayOrder
local resources_sorted = {}
for namespace, data in pairs(Namespaces) do
local Township = Data.tableMatch(data.data.skillData, 'skillID', 'melvorD:Township')
if Township ~= nil and Township.data.resourceDisplayOrder ~= nil then
for _, resourceOrder in ipairs(Township.data.resourceDisplayOrder[1].ids) do
resourceOrder_split = Data.splitID(resourceOrder)
local target_resource = Data.tableMatch(resources, 'id', resourceOrder_split.id)
table.insert(resources_sorted, target_resource)
end
end
end
return resources_sorted
end
end


572

edits