Description[]
This module is the Lua back-end for {{Enchanted Chest}}, to display information about Enchanted Chests.
Usage[]
{{#invoke:EnchantedChest|getChest|<parameter list>}}
For parameter details see Template:Enchanted Chest/doc
--[=[
Lua script replacement for wikitext template
[[File:ec-{{lc:{{{1}}}}}.png|25x25px|{{{1}}} Chest|link={{{1}}} Chests]]
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, "", "", "", "",
"[[File:", "", "", ".png|x", size,
"px|", "", "|link=", "", "]]",
"", "", "", "", "", "", ""
}
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 or chest) .. " 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 outType == "T" then
return cLink
end
if cVers and chestData[cName][cVers] then
if outType == "CARD" then
return {cLink, (cName .. "-" .. cVers), chestData[cName][cVers]}
end
cLink = cLink .. "/Content History#" .. cVers
end
cDisp = (subName or cName) .. " Chest"
if outType ~= "L" and outType ~= "N" then
tChest[ 6] = '<div style="position: relative; margin: auto; width: ' .. (count and size+25 or size) .. 'px; height: ' .. size .. 'px;">[[File:'
if subName then tChest[15] = ']]<span class="hidden" style="position: absolute; top: -' .. math.floor(size / 7) .. 'px; left: -' .. math.floor(size / 7) .. 'px;">[[File:cc-' .. mw.ustring.lower(mw.ustring.gsub(subName, "[':\"%,%.*!]", "")) .. '-l.png|x' .. math.floor(size / 2) .. 'px|' .. subName .. '|link=' .. cLink .. ']]</span>' end
tChest[16] = '</div>'
end
if plural or (count and count > "1") then
cDisp = cDisp .. "s"
end
end
if outType == "CARD" then
return {cLink}
elseif outType == "N" then
tChest[ 2] = "[["
tChest[ 3] = cLink
tChest[ 4] = "|" .. cDisp
tChest[ 5] = "]] <span style=\"white-space: nowrap;\">("
tChest[17] = ")</span>"
elseif outType == "L" or outType == "D" then
tChest[ 6] = "[["
tChest[ 7] = ""
tChest[ 9] = cLink
tChest[10] = "|"
tChest[11] = cDisp
tChest[13] = ""
elseif outType == "P" then
tChest[16] = (tChest[16]=="" and "<br />" or tChest[16])
tChest[17] = "<small>[["
tChest[18] = cLink
tChest[19] = "|"
tChest[20] = cDisp
tChest[21] = "]]</small>"
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=="0" and "?" or count)
else
tChest[15] = tChest[15] .. " " .. (count=="0" and "?" or count)
end
end
end
table.insert(tAll, table.concat(tChest))
end
return table.concat(tAll)
end
function p.getCycle(frame)
local tArgs = util.getArgs(frame)
local icon = require("Module:ItemDisplay").getOneItem
local tChests = mw.text.split(tArgs[1], "%s*%$%s*")
local tTotal = {}
local tOut = {'{| class="article-table dmk-calendar" style="text-align: center;line-height: 1.0;width: 100%;"\n!#\n! style="width: 90%;" colspan="6"|Hidden Chests'}
for k, v in ipairs(tChests) do
table.insert(tOut, '\n|-\n! id="Chest ')
table.insert(tOut, k)
table.insert(tOut, '"|')
table.insert(tOut, k)
table.insert(tOut, '\n| colspan="6"|')
table.insert(tOut, icon(v .. " Chests", "X"))
if not tTotal[v] then tTotal[v] = 0 end
tTotal[v] = tTotal[v] + 1
end
table.insert(tOut, '\n|-\n!Total')
for chest, nb in pairs(tTotal) do
table.insert(tOut, '\n! style="width:15%;"|')
table.insert(tOut, icon(chest .. " Chests", nb, true))
end
return table.concat(tOut) .. "\n|}"
end
return p