Difference between revisions of "Module:Silent1/sandbox"
Jump to navigation
Jump to search
m |
m |
||
Line 31: | Line 31: | ||
function p.getURL(id) | function p.getURL(id) | ||
− | return 'https://idlescape.com' .. p.loadData('item')[id][itemImage] | + | return 'https://idlescape.com' .. p.loadData('item')[tostring(id)]['itemImage'] |
end | end | ||
Line 43: | Line 43: | ||
end | end | ||
− | local id = | + | local id = p.findItemID(origArgs[1]) |
return p.getURL(id) | return p.getURL(id) | ||
end | end | ||
return p | return p |
Revision as of 10:41, 14 February 2022
local p = {} local origArgs = {} local data_module_names = { item = 'Module:Silent1/sandbox/data' } local loaded_data_modules = {} function p.loadData (data_type) local module_name = data_module_names[data_type] if loaded_data_modules[module_name] == nil then loaded_data_modules[module_name] = mw.loadData(module_name) end return loaded_data_modules[module_name] end function p.findItemID(name) local items = p.loadData('item') local lname = string.lower(name) local id = 0 for k,v in pairs(items) do if lname == string.lower(v[name]) then id = k return id end end return id end function p.getURL(id) return 'https://idlescape.com' .. p.loadData('item')[tostring(id)]['itemImage'] end -- If called via #invoke, use the args passed into the invoking template. -- Otherwise, for testing purposes, assume args are being passed directly in. function p.image(frame) if frame == mw.getCurrentFrame() then origArgs = frame:getParent().args else origArgs = frame end local id = p.findItemID(origArgs[1]) return p.getURL(id) end return p