Module:ItemLevel

--[=[ -- --- --Lua script to display items with level/status --- -- --Parameters: --   1: Type = Item Type --             "I" = Character (Icon only, without background) --             	Instead of "I" : --						Event short name or "side" or "main" = Character with a background (background = instead of "I") --             "X" = Costume --             "A" = Attraction --             "F" = Float --   2: Collection = Collection Name (optional) --             For costumes : Character Name --   3: Items = list of items seperated by dollar sigh ($) --             item = "item name,level" --             if level = X, display blank/grey icon --             if level is missing, means level 0 --				if item name different from wiki item name : --				put a circumflex accent between the wiki item name and the name you want to put ("Wiki Item Name^New Name") --   4: item image size (default 40px) --   5: collection image size (default 1.25 * item size) --]=]

local p = {}

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

function p.dispItems(frame) local tArgs = util.getArgs(frame) local iType = tArgs[1] or "I" local collection = tArgs[2] or "" local itemList = tArgs[3] or "" local iSize = tonumber(tArgs[4]) or 40 local cSize = tonumber(tArgs[5]) or math.floor(iSize * 1.25) iType = iType:gsub("^%s*(.)%s*$", "%1")

local suffix = ""

if not mw.ustring.match(iType, "^[IXAF]$") then suffix = "-" .. mw.ustring.lower(iType) end

local outText = ""

collection = collection:gsub("^%s*(.-)%s*$", "%1")

if collection ~= "" then if iType == "X" then outText = "[[File:C-"                   .. mw.ustring.gsub(mw.ustring.lower(collection),                        "[':%,%.]", "")                    .. ".png|link="                    .. collection                    .. "|x"                    .. cSize                    .. "px|"                    .. collection                    .. "]] ― " else outText = getCollection({collection, cSize}) .. " ― "       end end

itemList = itemList:gsub("^%s*(.-)%s*$", "%1")

local space = "" local prefix = ""

if iType == "A" then prefix = "[[File:Ba-"   elseif iType == "F" then        prefix = "[[File:Pf-"    else        prefix = "[[File:C-"    end

for item in mw.text.gsplit(itemList, "%s*%$%s*") do       local iName, iLevel = mw.ustring.match(item,                             "^(.-)%s*#%s*(.-)$") local iNew, iText = mw.ustring.match((iName or item),                            "^(.-)%s*^%s*(.-)$")

if not iText then iText = (iName or item) end

local welcomed = true

if not iName then iName = item iLevel = 0 else iLevel = tonumber(iLevel) if not iLevel then welcomed = false iLevel = 0 end end

if iType == "X" then outText = outText .. space

if not welcomed then outText = outText .. "" end outText = outText .. ""                           .. iName                            .. "" if not welcomed then outText = outText .. " "           end space = " • " elseif iType == "F" then local filePart = string.gsub(string.lower((iNew or iName)),"[':%,%.]","") :gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")

if not welcomed then filePart = "?" end

outText = outText .. space .. prefix .. filePart .. ".png|link=" .. iName .. " Float|x" .. iSize .. "px|" .. iName .. " Float]]"

space = " " else local filePart = string.gsub(string.lower((iNew or iName)),"[':%,%.]","") :gsub("^([^%(]-)%/([^%(]-)$", "%1-%2") :gsub("^([^%(]-) *%(([^%(]-)%)$", "%1_%2") :gsub(" ", "_") :gsub("\"", "")           if not welcomed then                filePart = "?"            end

outText = outText .. space .. prefix .. filePart .. ((welcomed and suffix) or "") .. ".png|link=" .. (iNew or iName) .. "|x" .. iSize .. "px|" .. iText

if iLevel > 0 and not mw.ustring.match(iType, "[PX]") then outText = outText .. " (Level "                       .. iLevel                        .. ")" end

outText = outText .. "]]"           space = " " end end

return outText end

return p