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 chest Name Link also If equal to "L", includes the chest Name Link only 3: Enchanted Chest link if diffrent from name -- Unknown is returned if EC is not in data.

--]=]

local p = {}

local coll = require("Module:ItemCollection").getCollection local util = require('Module:Utility') local chestData = {["Bronze"] = {}, ["Silver"] = {}, ["Gold"] = {}, ["Platinum"] = {}, ["Decoration"] = {}, ["Resource"] = {}, ["Concession"] = {}, ["Attraction Enchantment"] = {}, ["Legendary"] = {}, ["Magical"] = {}, ["Radiant"] = {}, ["Ruby"] = {}, ["Sapphire"] = {}, ["Amber"] = {}, ["Cobalt"] = {}, ["Red Ribbon"] = {}, ["Halloween"] = {"Sapphire"}, ["Christmas"] = {"Red Ribbon"}}

local function ChestIcon(Chests, size, variable) local outType = ""

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

local tAll = {} local space = ""

for chest in mw.text.gsplit(Chests, "%s*[!%$]%s*") do		local tChest = {space, "", "", "", "", "", ""	   				}		local cName, version = mw.ustring.match(chest, "^([^,]-)%s*-%s*(.-)$") if not cName then cName = chest end cName = mw.ustring.gsub(cName, " Chests", "") if outType == "S" then version = mw.title.getCurrentTitle.text end local cFile = "work_in_progress" local cLink = "Work In Progress" local cDisp = cName .. " Chest" if chestData[cName] then tChest[ 7] = "ec-" cFile = mw.ustring.lower(mw.ustring.gsub(cName, " ", "_")) cLink = cName .. " Chests" cDisp = cName .. " Chest" if variable then if mw.ustring.lower(variable) == "s" then cDisp = cDisp .. "s" elseif chestData[variable] then cLink = variable .. " Chests" cDisp = cDisp .. "s (" .. cLink .. ")" end elseif chestData[cName][1] then cFile = mw.ustring.lower(mw.ustring.gsub(chestData[cName][1], " ", "_")) cDisp = chestData[cName][1] .. " Chests (" .. cDisp .. ")" end if cName == "Legendary" and version then if outType ~= "S" then cDisp = coll({version, "N"}) .. " " .. cDisp end cLink = cLink .. "#" .. coll({version, "N"}) end end if outType == "N" then tChest[ 2] = ""			tChest[ 5] = cDisp			tChest[ 6] = " ([[File:"			tChest[16] = ")"		elseif outType == "L" then			tChest[ 6] = ""			tChest[10] = cDisp			tChest[11] = ""			tChest[13] = ""			tChest[15] = ""		elseif outType == "S" then			tChest[ 6] = "FREE ([["			tChest[ 7] = cLink			tChest[ 9] = "|"			tChest[10] = cDisp			tChest[11] = "]]) "			tChest[13] = ""			tChest[15] = ""		end		if outType ~= "L" and outType ~= "S" 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 variable = tArgs[3]

return ChestIcon(chest, size, variable) end

return p