Editing Module:Silent1/sandbox
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local origArgs = {} | local origArgs = {} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local data_module_names = { | local data_module_names = { | ||
− | + | item = 'Module:Silent1/sandbox/data' | |
− | item = 'Module:Silent1/sandbox | ||
− | |||
} | } | ||
local loaded_data_modules = {} | local loaded_data_modules = {} | ||
Line 25: | Line 16: | ||
end | end | ||
− | |||
function p.findItemID(name) | function p.findItemID(name) | ||
local items = p.loadData('item') | local items = p.loadData('item') | ||
local lname = string.lower(name) | local lname = string.lower(name) | ||
− | local id = | + | local id = 0 |
for k,v in pairs(items) do | for k,v in pairs(items) do | ||
− | if lname == string.lower(v[ | + | if lname == string.lower(v[name]) then |
id = k | id = k | ||
return id | return id | ||
Line 40: | Line 30: | ||
end | end | ||
− | + | function p.getURL(id) | |
− | + | return 'https://idlescape.com' .. p.loadData('item')[id][itemImage] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | 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 | |
− | |||
− | if | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
else | else | ||
− | + | origArgs = frame | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | local id = tostring(p.findItemID(origArgs[1])) | |
− | return | + | return p.getURL(id) |
end | end | ||
return p | return p |