Module:EnchantedChest

--[=[ Lua script replacement for wikitext template



Parameters: 1: Enchanted Chest name 2: Size in pixels optional, defaults to 25 If equal to "N", includes the token Name Link also If equal to "L", includes the token Name Link only 3: IP Collection (Optional) -- Unknown is returned if EC is not in data.

--]=]

local p = {}

local coll = require("Module:ItemCollection").getCollection local util = require('Module:Utility')

local function ChestIcon(chest, size, version) local outType = ""

if not tonumber(size) then outType = size size = 25 end

local tAll = {} local space = "" local chest = mw.ustring.gsub(chest, " Chests", "")

for cName in mw.text.gsplit(chest, "%s*[!%$]%s*") do		local tChest = {space, "", "", "", "", "", ""	   				}    	cFile = mw.ustring.lower(mw.ustring.gsub(cName, " ", "_")) cLink = cName .. " Chests" cDisp = cName .. " Chest" if cName == "Halloween" then cFile = "sapphire" cDisp = "Sapphire Chests (Halloween Chests)" elseif cName == "Christmas" then cFile = "red_ribbon" cDisp = "Red Ribbon Chests (Christmas Chests)" elseif cName == "Legendary" and version then cDisp = coll({version, "N"}) .. " " .. cName .. " Chest" end if outType == "N" then tChest[ 2] = ""			tChest[ 5] = cDisp			tChest[ 6] = " ([[File:"			tChest[16] = ")"		elseif outType == "L" then			tChest[ 6] = "[["			tChest[ 7] = cLink			tChest[ 9] = "|"			tChest[10] = cDisp			tChest[11] = "]]"			tChest[13] = ""			tChest[15] = ""		end		if outType ~= "L" then			tChest[ 8] = cFile			tChest[12] = cDisp			tChest[14] = cLink   	end    	table.insert(tAll, table.concat(tChest))    end    return table.concat(tAll) end

function p.getChest(frame) local tArgs = util.getArgs(frame)

local chest = tArgs[1] or "" local size = tArgs[2] local version = tArgs[3]

return ChestIcon(chest, size, version) end

return p