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 10: | Line 10: | ||
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 23: | ||
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 | ||
Line 40: | Line 37: | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local function _image() | local function _image() | ||
− | local | + | local id = p.findItemID(name) |
local s = '' | local s = '' | ||
local rs = nil | local rs = nil | ||
− | + | if id ~= '0' then | |
− | if | + | local item = p.loadData('item')[id] |
− | local | + | local url = 'https://idlescape.com' .. item['itemImage'] |
− | local | + | local rname = item['name'] |
− | |||
− | |||
s = url | s = url | ||
if only_url == '1' then rs = s end | if only_url == '1' then rs = s end | ||
− | |||
s = 'src="' .. s .. '"' | s = 'src="' .. s .. '"' | ||
− | s = s .. ' alt="' .. | + | s = s .. ' alt="' .. rname .. '"' |
s = s .. ' width="' .. width .. '"' | s = s .. ' width="' .. width .. '"' | ||
s = s .. ' height="' .. height .. '"' | s = s .. ' height="' .. height .. '"' | ||
Line 105: | Line 56: | ||
if add_word == '1' then | if add_word == '1' then | ||
− | s = s .. ' ' .. | + | s = s .. ' ' .. rname |
end | end | ||
− | |||
if no_link == '1' then rs = s end | if no_link == '1' then rs = s end | ||
− | if not (link and link:match('%S')) then link = | + | if not (link and link:match('%S')) then link = rname end |
s = '[[' .. link .. '|' .. s .. ']]' | s = '[[' .. link .. '|' .. s .. ']]' | ||
else | else | ||
− | s = '[[' .. name .. ']]' .. '{{?}}' | + | s = '[[' .. name .. ']]' .. '{{{?}}}' |
end | end | ||
if not rs then rs = s end | if not rs then rs = s end | ||
Line 119: | Line 69: | ||
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) | function p.image(frame) | ||
− | + | if frame == mw.getCurrentFrame() then | |
− | + | origArgs = frame:getParent().args | |
− | + | else | |
− | + | origArgs = frame | |
− | origArgs = frame | + | end |
name = origArgs[1] | name = origArgs[1] | ||
arg = origArgs[2] | arg = origArgs[2] | ||
− | if | + | if arg then |
width = 20 | width = 20 | ||
else arg:match('%S') | else arg:match('%S') | ||
Line 138: | Line 90: | ||
no_link = origArgs['nolink'] | no_link = origArgs['nolink'] | ||
link = origArgs['link'] | link = origArgs['link'] | ||
− | |||
if not name then return '' end | if not name then return '' end | ||
return _image() | return _image() |