Module:ItemData: Difference between revisions

Jump to navigation Jump to search
reverted is_active to use false instead of nil
Tag: Manual revert
add color to error, return values of subtable in properties
Line 2: Line 2:
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")


-- returns the table of a specific item
-- returns the value of a specific item
function get_json_item(name)
function get_json_item(name)
for i,v in pairs(data) do
for i,v in pairs(data) do
Line 16: Line 16:
local item_name = frame.args[1]
local item_name = frame.args[1]
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "<span style=\"color:red;\">\"Item Not Found.</span>" end
local cost = 0
local cost = 0
Line 35: Line 35:
local item_name = frame.args[1]
local item_name = frame.args[1]
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "<span style=\"color:red;\">\"Item Not Found.</span>" end
if (item["Slot"] == "Weapon") then
if (item["Slot"] == "Weapon") then
Line 52: Line 52:
local item_name = frame.args[1]
local item_name = frame.args[1]
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "<span style=\"color:red;\">\"Item Not Found.</span>" end
if (item["Activation"] == "Passive") then
if (item["Activation"] == "Passive") then
Line 64: Line 64:
--check Data:ItemData.json for properties
--check Data:ItemData.json for properties
p.get_prop = function(frame)
p.get_prop = function(frame)
local tableValues = {}
local item_name = frame.args[1]
local item_name = frame.args[1]
local property = frame.args[2]
local property = frame.args[2]
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "<span style=\"color:red;\">\"Item Not Found.</span>" end
if(type(item[property]) == "table") then
for i,v in pairs(item[property]) do
local tableValues = table.insert(tableValues, v)
end
return table.concat(tableValues, ", ")
end
return item[property]
return item[property]
end
end


p.get_component_name = function(frame)
p.get_component_name = function(frame)
local item_name = frame.args[1]
local item_name = frame.args[1]
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "<span style=\"color:red;\">\"Item Not Found.</span>" end
local components = item['Components']
local components = item['Components']