Module:ItemData: Difference between revisions

cleanup, separate functions
split up get type function
Line 19: Line 19:
end
end


--  
--- Get cost of an item
-- @function  get_cost
-- @param      {string}
-- @return    {number}
local function get_cost(item_name)
local function get_cost(item_name)
local item = get_json_item(item_name)
local item = get_json_item(item_name)
Line 37: Line 40:
end
end


--- Get type/slot/category of an item
-- @function  get_type
-- @param      {string}
-- @return    {number}
local function get_type(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["Slot"] == "Weapon") then
return "Weapon"
elseif (item["Slot"] == "Armor") then
return "Vitality"
elseif (item["Slot"] == "Tech") then
return "Spirit"
else
return nil
end
end


---------------------------------------- Invocable functions
---------------------------------------- Invocable functions


--- Get cost of an item {{#invoke:ItemData|get_cost|ITEM_NAME}}
--- {{#invoke:ItemData|get_cost|ITEM_NAME}} access point
-- @function  p.get_cost
-- @param      Frame object
-- @return    {number}
p.get_cost = function(frame)
p.get_cost = function(frame)
local item_name = frame.args[1]
local item_name = frame.args[1]
Line 55: Line 74:
end
end


--{{#invoke:ItemData|get_type|ITEM_NAME}}--
-- {{#invoke:ItemData|get_type|ITEM_NAME}} access point
p.get_type = function(frame)
p.get_type = function(frame)
local item_name = frame.args[1]
local item_name = frame.args[1]
local item = get_json_item(item_name)
return get_type(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
end
 
if (item["Slot"] == "Weapon") then
function p._get_type(a)
return "Weapon"
a = tostring(a) or ""
elseif (item["Slot"] == "Armor") then
return get_type(a)
return "Vitality"
elseif (item["Slot"] == "Tech") then
return "Spirit"
else
return nil
end
end
end