Module:ItemTables: Difference between revisions

Jump to navigation Jump to search
moving function out to be accessible for other modules
cleanup, remove local functions in favor for main module passing functionality
Line 1: Line 1:
local p = {};
local p = {};
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")
local get_cost = require("Module:ItemData")._get_cost


-- returns the table of a specific item
-- returns the table of a specific item
Line 42: Line 43:
end
end


 
local function get_type(item_name)
 
--{{#invoke:Sandbox/Sylphoid|get_prop|ITEM_NAME|PROPERTY}}--
--check Data:ItemData.json for properties
p.get_prop = function(frame)
local item_name = frame.args[1]
local property = frame.args[2]
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
return Deepcopy(item[property])
end
 
local function get_cost(item_name)
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
local cost = 0
if (item["Slot"] == "Weapon") then
local cur_item = item
return "Weapon"
repeat
elseif (item["Slot"] == "Armor") then
cost = cost + cur_item["Cost"]
return "Vitality"
if(cur_item["Components"] == nil) then
elseif (item["Slot"] == "Tech") then
break
return "Spirit"
end
else
cur_item = data[cur_item["Components"][1]]
return nil
until cur_item == nil
end
 
return Format(cost)
end
end


--{{#invoke:ItemData|get_cost|ITEM_NAME}}--
p.get_type = function(frame)
function p.get_cost(frame)
local item_name = frame.args[1]
local item_name = frame.args[1]
return get_cost(item_name)
return get_type(item_name)
end
end


local link_patterns = {}
local link_patterns = {}
Line 110: Line 95:
local createTable = mw.html.create('table')
local createTable = mw.html.create('table')
:addClass('wikitable sortable')
:addClass('wikitable sortable')
:tag('caption'):wikitext("List of Items"):done()
local createTableRow = mw.html.create('tr')
local createTableRow = mw.html.create('tr')
Line 115: Line 101:
:tag('th'):wikitext('Name'):done()
:tag('th'):wikitext('Name'):done()
:tag('th'):wikitext('Cost'):done()
:tag('th'):wikitext('Cost'):done()
:tag('th'):wikitext('Category'):done()
createTable:node(createTableRow)
createTable:node(createTableRow)




for internalName, statName in pairs(data) do --statName is the key. go through whole table. in this case itemName can be upgrade_improved_stamina
for internalName, statName in pairs(data) do --statName is the key. go through whole table. in this case itemName can be upgrade_improved_stamina
Line 136: Line 122:
:tag('td'):wikitext(display):done()
:tag('td'):wikitext(display):done()
:tag('td'):wikitext(get_cost(statName["Name"])):done()
:tag('td'):wikitext(get_cost(statName["Name"])):done()
:tag('td'):wikitext(get_type(statName["Name"])):done()
table.insert(requirements, tableData)
table.insert(requirements, tableData)