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:Items/data',
+
item = 'Module:Silent1/sandbox/data'
item = 'Module:Silent1/sandbox/data',
 
other = 'Module:OtherImages/data'
 
 
}
 
}
 
local loaded_data_modules = {}
 
local loaded_data_modules = {}
Line 25: Line 23:
 
end
 
end
  
--Search the item data for item name and return its id
 
 
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 = nil
+
local id = 0
 
 
 
for k,v in pairs(items) do
 
for k,v in pairs(items) do
Line 40: Line 37:
 
end
 
end
  
--Find the image from the name
+
local function _image()
-- function p.findImage(name)
+
local id = p.findItemID(name)
-- local id
+
local item = p.loadData('item')[id]
-- name = string.lower(name)
+
local url = 'https://idlescape.com' .. item['itemImage']
-- local image = p.loadData('other')[name]
+
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 name is a number, pass in as an item ID
+
if add_word then  
-- if tonumber(name) then
+
s = s .. ' ' .. rname
-- id = name
+
end
-- else
+
if no_link then return s end
-- id = p.findItemID(name)
 
-- end
 
 
-- --If id is valid
 
-- if id then
 
-- local item = p.loadData('item')[id]
 
-- local url = item['itemImage']
 
-- local icon = item['itemIcon']
 
-- local realname = item['name']
 
 
-- if icon then url = icon end
 
-- image = {name = realname, image = url}
 
 
-- if not (image['name'] and image['image']) then
 
-- image = nil
 
-- end
 
-- end
 
 
 
-- return image
+
if link then link = rname end
-- end
+
s = '[[' .. link .. '|' .. s .. ']]'
 
 
function p.findImage(name)
 
local id
 
name = string.lower(name)
 
local image = p.loadData('other')[name]
 
 
 
if not image then
+
return s
image = p.loadData('item')[name]
 
end
 
return image
 
 
end
 
end
  
--Create a string to output
+
-- If called via #invoke, use the args passed into the invoking template.
local function _image()
+
-- Otherwise, for testing purposes, assume args are being passed directly in.
local image = p.findImage(name)
+
function p.image(frame)
local s = ''
+
if frame == mw.getCurrentFrame() then
local rs = nil
+
origArgs = frame:getParent().args
 
if image then
 
local realname = image['name']
 
local url = image['image']
 
 
if url:sub(1,1) ~= '/' then url = '/' .. url end
 
url = 'https://idlescape.com' .. url
 
s = url
 
 
if only_url == '1' then rs = s end
 
 
s = 'src="' .. s .. '"'
 
s = s .. ' alt="' .. realname .. '"'
 
s = s .. ' width="' .. width .. '"'
 
s = s .. ' height="' .. height .. '"'
 
s = '<img ' .. s .. '>'
 
 
if add_word == '1' then
 
s = s .. ' ' .. realname
 
end
 
 
if no_link == '1' then rs = s end
 
 
if not (link and link:match('%S')) then link = realname end
 
s = '[[' .. link .. '|' .. s .. ']]'
 
 
else
 
else
s = '[[' .. name .. ']]' .. '{{?}}'
+
origArgs = frame
 
end
 
end
if not rs then rs = s end
 
return rs
 
end
 
 
function p.image(frame)
 
return p._image(frame:getParent())
 
end
 
 
function p._image(frame)
 
origArgs = frame.args
 
 
name = origArgs[1]
 
name = origArgs[1]
arg = origArgs[2]
+
if origArgs[2] then width = origArgs[2] end
if not arg then  
+
if origArgs[3] then height = origArgs[3] end
width = 20
 
else arg:match('%S')
 
width = arg
 
end
 
arg = origArgs[3]
 
if arg and arg:match('%S') then height = arg 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']
 
 
if not name then return '' end
 
 
return _image()
 
return _image()
 
end
 
end
 +
  
 
return p
 
return p

Please note that all contributions to Idlescape Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see IdleScape Wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: