Module:ItemData: Difference between revisionsGive feedback
tidy, replace commas with language |
cleanup, separate functions |
||
| 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 | ||
function get_json_item(name) | local function get_json_item(name) | ||
for _, v in pairs(data) do | for _, v in pairs(data) do | ||
if (v["Name"] == name) then | if (v["Name"] == name) then | ||
| Line 19: | Line 19: | ||
end | 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 | ||
| Line 37: | Line 35: | ||
return Format(cost) | return Format(cost) | ||
end | |||
---------------------------------------- Invocable functions | |||
--- Get cost of an item {{#invoke:ItemData|get_cost|ITEM_NAME}} | |||
-- @function p.get_cost | |||
-- @param Frame object | |||
-- @return {number} | |||
p.get_cost = function(frame) | |||
local item_name = frame.args[1] | |||
return get_cost(item_name) | |||
end | |||
-- Module access point | |||
function p._get_cost(a) | |||
a = tostring(a) or '0' | |||
return get_cost(a) | |||
end | end | ||