Anonymous

Module:Township: Difference between revisions

From Melvor Idle
no edit summary
m (Gau Cho moved page Module:GauTest/Township to Module:Township without leaving a redirect)
No edit summary
Line 2: Line 2:
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local resource_data = {
['melvorF:GP'] = {icon = {'Coins'}, skill = nil},
['melvorF:Food'] = {icon = {'Raw Beef', type='item'}, skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {icon = {'Wood', type='resource'}, skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {icon = {'Stone', type='resource'}, skill = 'melvorD:Mining'},
['melvorF:Ore'] = {icon = {'Iron', type='rock'}, skill = 'melvorD:Mining'},
['melvorF:Coal'] = {icon = {'Coal', type='resource'}, skill = 'melvorD:Mining'},
['melvorF:Bar'] = {icon = {'Iron Bar', type='item'}, skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {icon = {'Garum Herb', type='item'}, skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {icon = {'Rune Essence', type='item'}, skill = 'melvorD:Mining'},
['melvorF:Leather'] = {icon = {'Leather', type='item'}, skill = nil},
['melvorF:Potions'] = {icon = {'Potion', type='resource'}, skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {icon = {'Planks', type='resource'}, skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {icon = {'Leather Body', type='item'}, skill = 'melvorD:Crafting'}
}


local p = {}
local p = {}
Line 77: Line 94:
local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder[1].ids)
local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder[1].ids)
resources = Shared.clone(resources)
resources = Shared.clone(resources)
-- Append the icon reference to each resource, as well as the associated skill for the recipes
-- From https://melvoridle.com/assets/data/melvorFull.json -> data.skillData -> Township.data.resources.media
local resource_data = {
['melvorF:GP'] = {_icon = {'Coins'}, _skill = nil},
['melvorF:Food'] = {_icon = {'Raw Beef', type='item'}, _skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {_icon = {'Wood', type='resource'}, _skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {_icon = {'Stone', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Ore'] = {_icon = {'Iron', type='rock'}, _skill = 'melvorD:Mining'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'melvorD:Mining'},
['melvorF:Leather'] = {_icon = {'Leather', type='item'}, _skill = nil},
['melvorF:Potions'] = {_icon = {'Potion', type='resource'}, _skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {_icon = {'Planks', type='resource'}, _skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {_icon = {'Leather Body', type='item'}, _skill = 'melvorD:Crafting'}
}
for _, resource in ipairs(resources) do
resource._skill = resource_data[resource.id]._skill
resource._icon = resource_data[resource.id]._icon
resource._icon.notext = true
resource._icon.nolink = true
end
return resources
return resources
Line 152: Line 145:
end
end


local resource_data = {
local traderMatchesList = {
['melvorF:GP'] = {traderMatches = matchNone},
['melvorF:GP'] = {traderMatches = matchNone},
['melvorF:Food'] = {traderMatches = matchFood},
['melvorF:Food'] = {traderMatches = matchFood},
Line 169: Line 162:


for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id].traderMatches))
resource.itemConversions = Shared.clone(GameData.getEntities('items', traderMatchesList[resource.id].traderMatches))
end
end
Line 206: Line 199:


-- 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()
local resources = p._TraderData()
Line 245: Line 238:
['melvorF:Apple'] = 'melvorD:Farming',
['melvorF:Apple'] = 'melvorD:Farming',
}
}
local skill = skill_overrides[item.id] or resource._skill
local skill = skill_overrides[item.id] or p._GetResourceSkill(resource.id)
local skill_namespace, skill_localid = GameData.getLocalID(skill or '')
local skill_namespace, skill_localid = GameData.getLocalID(skill or '')
Line 280: Line 273:
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(resource._icon)..' '..Shared.formatnum(item.fromTownship))
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))
-- 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 299: Line 292:
end
end
return table.concat(ret)
return table.concat(ret)
end
-- 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
-- Gets the associated skill of a resource by id
function p._GetResourceSkill(id)
return resource_data[id].skill
end
-- Gets a Township building by ID, e.g. melvorF:Hunters_Cabin
function p._GetBuildingByID(id)
GameData.getEntityByID(GameData.getSkillData('melvorD:Township').buildings, id)
end
-- Gets a building and prepares all the relevant stats for the building
function p._GetBuildingProfile(id)
local building = p._GetBuildingByID(id)
local resources = p._ResourcesData()
end
end


return p
return p
572

edits