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 id = p.findItemID(name) | |
− | + | local item = p.loadData('item')[id] | |
− | + | local url = 'https://idlescape.com' .. item['itemImage'] | |
− | + | local rname = item['name'] | |
+ | local s = url | ||
+ | |||
+ | if only_url then return s end | ||
+ | s = 'src="' .. s .. '"' | ||
+ | s = s .. ' alt="' .. rname .. '"' | ||
+ | s = s .. ' width="' .. width .. '"' | ||
+ | s = s .. ' height="' .. height .. '"' | ||
+ | s = '<img ' .. s .. '>' | ||
− | + | if add_word then | |
− | + | s = s .. ' ' .. rname | |
− | + | end | |
− | + | if no_link then return s end | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | if link then link = rname end | |
− | + | s = '[[' .. link .. '|' .. s .. ']]' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | return s | |
− | |||
− | |||
− | return | ||
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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
name = origArgs[1] | name = origArgs[1] | ||
− | + | if origArgs[2] then width = origArgs[2] end | |
− | + | if origArgs[3] then height = origArgs[3] end | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
add_word = origArgs['word'] | add_word = origArgs['word'] | ||
only_url = origArgs['url'] | only_url = origArgs['url'] | ||
Line 139: | Line 78: | ||
link = origArgs['link'] | link = origArgs['link'] | ||
− | |||
return _image() | return _image() | ||
end | end | ||
+ | |||
return p | return p |