Module:Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 3: Line 3:
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')


local p = {}


local Data = {}
-- Returns the namespace name (eventually we should use an icon)
 
function p.PLACEHOLDER_NAMESPACE_ICON(namespace)
 
 
-- Returns the namespace name (eventually we should use an icon?)
function Data.PLACEHOLDER_NAMESPACE_ICON(namespace)
local namespaces = {
local namespaces = {
melvorD = 'Demo',
melvorD = 'Demo',
Line 17: Line 14:
return namespaces[namespace]
return namespaces[namespace]
end
end
Data.Item = {}


-- Returns the recipe for the item of a desired skill.
-- Returns the recipe for the item of a desired skill.
function Data.Item.FindRecipes(itemid, skill)
-- Unfortunately Module:Items/SourceTables.getItemSources does not provide parseable data so we instead use this quick function
function p._FindItemRecipes(itemid, skill)
-- No skill? No recipes
-- No skill? No recipes
Line 76: Line 70:
end
end


Data.Township = {}
-- Returns a list of all the Township resources
-- Returns a list of all the Township resources
function Data.Township.Resources()
function p._ResourcesData()
-- Get a sorted list of all the resources
-- Get a sorted list of all the resources
Line 94: Line 87:
['melvorF:Ore'] = {_icon = {'Iron Ore', type='rock'}, _skill = 'melvorD:Mining'},
['melvorF:Ore'] = {_icon = {'Iron Ore', type='rock'}, _skill = 'melvorD:Mining'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'melvorD:Mining'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'melvorD:Farming'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'melvorD:Mining'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'melvorD:Mining'},
Line 113: Line 106:


-- 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
function Data.Township.Trader()
function p._TraderData()
-- Get the list of resources
-- Get the list of resources
local resources = Data.Township.Resources()
local resources = p._ResourcesData()
-- Get the list of tradeable items
-- Get the list of tradeable items
Line 213: Line 206:


-- Builds the table of trader items
-- Builds the table of trader items
function Data.Township.getTraderTable(frame)
function p.getTraderTable(frame)
-- Get the resources data with associated trader data
-- Get the resources data with associated trader data
local resources = Data.Township.Trader()
local resources = p._TraderData()
-- Build the text
-- Build the text
Line 253: Line 246:
}
}
local skill = skill_overrides[item.id] or resource._skill
local skill = skill_overrides[item.id] or resource._skill
local _namespace, local_skillname = GameData.getLocalID(skill or '')
local skill_namespace, skill_localid = GameData.getLocalID(skill or '')
-- Check for upgraded Crafting items and downgrade them so we can display the crafting level for the base item
-- Check for upgraded Crafting items and downgrade them so we can display the crafting level for the base item
Line 263: Line 256:
-- Find the recipe's level
-- Find the recipe's level
local recipes = Data.Item.FindRecipes(lookup_id, skill)
local recipes = p._FindItemRecipes(lookup_id, skill)
if #recipes == 1 then
if #recipes == 1 then
required_level = recipes[1].level
required_level = recipes[1].level
Line 275: Line 268:
table.insert(ret_resource, '\r\n|style="text-align:left"|'..Icons.Icon({item.name, type='item', noicon=true}))
table.insert(ret_resource, '\r\n|style="text-align:left"|'..Icons.Icon({item.name, type='item', noicon=true}))
-- DLC
-- DLC
table.insert(ret_resource, '\r\n|style="text-align:center"|'..'XXX')
local item_namespace, item_localid = GameData.getLocalID(item.id)
table.insert(ret_resource, '\r\n|style="text-align:center"|'..p.PLACEHOLDER_NAMESPACE_ICON(item_namespace))
-- Level
-- Level
if required_level == nil then
if required_level == nil then
Line 281: Line 275:
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="0"|N/A')
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="0"|N/A')
else
else
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. required_level .. '"|'..Icons.Icon({local_skillname, type="skill", notext=true})..' '..required_level)
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. required_level .. '"|'..Icons.Icon({skill_localid, type="skill", notext=true})..' '..required_level)
end
end
-- Give To
-- Give To
Line 306: Line 300:
return table.concat(ret)
return table.concat(ret)
end
end
local p = {}
p.getTraderTable = Data.Township.getTraderTable


return p
return p
572

edits