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 Enchanted Chest is not in data.

--]=]

local p = {}

local chestData = mw.loadData( 'Module:ECR/data' ) local cData = mw.loadData( 'Module:ItemCollection/data' ) local util = require('Module:Utility')

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

local allChest = tArgs[1] or "" local size = tArgs[2] local plural = tArgs[3] local outType = ""

if not tonumber(size) then outType = size if outType == "P" then size = 35 else size = 25 end end

local tAll = {} local space = ""

for chest in mw.text.gsplit(allChest, "%s*$%s*") do		local tChest = {space, "", "", "", "", "",	   				"", "", "", "", "", "", ""	    				}

local cName, count = mw.ustring.match(chest, "^(.-)%s*%#%s*([\/%d%?]*)$") local cVers = nil

cName = mw.ustring.gsub(cName or chest, " Chests", "")

if not chestData[cName] then cName, cVers = mw.ustring.match(cName, "(.-)%-([^%-]-)$") end local cFile = "work_in_progress" local cLink = "Work In Progress" local cDisp = cName .. " Chest" if chestData[cName] then tChest[ 7] = "ec-" local baseName, subName = mw.ustring.match(cName, "^([^,]-)%s*%/%s*([^,]-)$") cFile = mw.ustring.lower(mw.ustring.gsub(baseName or cName, " ", "_")) cLink = (baseName and (baseName .. " Chests/" .. subName .. " Chests") or (cName .. " Chests")) if cVers and chestData[cName][cVers] then cLink = cLink .. "#" .. cVers end cDisp = (subName or cName) .. " Chest"

if outType ~= "L" and outType ~= "N" and subName then tChest[ 6] = '[[File:'				tChest[15] = ']] ' tChest[16] = ' ' end

if plural or (count and count > "1") then cDisp = cDisp .. "s" end end if outType == "N" then tChest[ 2] = "" .. cDisp			tChest[ 5] = " ("			tChest[17] = ") " elseif outType == "L" or outType == "D" then tChest[ 6] = ""			tChest[11] = cDisp			tChest[13] = ""		elseif outType == "P" then			tChest[16] = (tChest[16]=="" and " " or tChest[16])			tChest[17] = " [["			tChest[18] = cLink			tChest[19] = "|"			tChest[20] = cDisp			tChest[21] = " "		end		if outType ~= "L" then			tChest[ 8] = cFile			tChest[12] = cDisp			tChest[14] = cLink			space = " "			if count then 				if outType == "N" then					tChest[ 5] = tChest[ 5] .. " x" .. count				else					tChest[15] = tChest[15] .. " " .. count 				end			end		end		table.insert(tAll, table.concat(tChest))	end	return table.concat(tAll) end

return p