Module:ItemData: Difference between revisionsGive feedback
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 | ||
--- | --- {{#invoke:ItemData|get_cost|ITEM_NAME}} access point | ||
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] | ||
return get_type(item_name) | |||
end | |||
function p._get_type(a) | |||
a = tostring(a) or "" | |||
return get_type(a) | |||
end | end | ||