Module:IS

local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

-- Original IS template: -- ]]

function p._main(args) local pages = mw.loadData('Module:IS/pages') --Returns a table containing a table for each item page's name and the items on them

local item = args[1] or "" --Passed argument is the name of the item who's sprite we want local link = args[2] or "" --Page the sprite should link to. Can be removed or added manually

--Find the item name throughout the table of item pages to link a page if link == "" then --If statement to skip the link finding part if argument 2 isn't empty for _,page in pairs(pages) do --Iterate each item page table in "pages" for _, i in pairs (page.items) do --Iterate its table of items if i == item then --If "item" matches link = "|link=" ..page.pagename.."#"..item --"link" becomes the name of the page the item is listed on				end end end end --Manual link if link ~= "" and link ~= "nolink" then --If argument 2 isn't empty and also isn't "nolink" link = "|link="..link --Passed arg becomes the linked page end

--Mystery Eggs page isn't an actual item page, but eggs are still items, so it needs its own statement to link automatically if link == "" and item == "Mystery Egg" then link = "|link=Mystery Eggs" end

--Remove ` in item name if string.match(item, "`") then item = string.gsub(item, "`", "") end

if mw.getCurrentFrame:callParserFunction( "filepath", "" .. item .. ".png" ) ~= "" and link == "nolink" then --Omit the automatic link if argument 2 is "nolink" return mw.getCurrentFrame:preprocess( "" ) elseif mw.getCurrentFrame:callParserFunction( "filepath", "" .. item .. ".png" ) ~= "" then return mw.getCurrentFrame:preprocess( "" ) else return mw.getCurrentFrame:preprocess("") end end

return p

-- print(p.main)