Disney Magic Kingdoms Wiki

The Sword in the Stone Part 3 Update has arrived! ✨
Visit this page to learn all about what's coming up in Disney Magic Kingdoms!

READ MORE

Disney Magic Kingdoms Wiki
Advertisement

Description[]

This module is the Lua back-end for {{ItemsLevel}}.

Usage[]

{{#invoke:ItemLevel|dispItems|<parameter list>}}

For parameter details see Template:ItemsLevel/doc


--[=[
-- <nowiki/>[[Category:Lua Modules]]
-----------------------------------------------
--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 = mw.ustring.lower(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 mw.ustring.match(iType, "^(.-)%s*-%s*(.-)$") then
    	iType, suffix = mw.ustring.match(iType, "^(.-)%s*-%s*(.-)$")
    	suffix = "-" .. suffix
    end

    local outText = ""

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

    if collection ~= "" then
        if iType == "cos" 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 conv = {
		["ch"] = "c",
		["cos"] = "cp",
	}
    local prefix = "[[File:" .. string.gsub(iType, ".+", conv) .. "-"
    local space = ""

	if suffix == "-x" and iSize < 12 then
		outText = outText .. "<small>"
	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 suffix == "-x" then
            outText = outText .. space

            if not welcomed then
                outText = outText .. "<span style=\"background: #6568cd\">"
            end

            outText = outText .. "[["
            
            if iType == "cos" then
                outText = outText .. collection .. "/"
            end

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

            if not welcomed then
                outText = outText .. space .. '<span id="qst-bg-grey">'
            else
                outText = outText .. space
            end

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

            if not welcomed then
                outText = outText .. '</span>'
            end

            space = " "
        else
            if iType == "cos" then
                iNew = collection .. "/" .. (iNew or iName)
            end

            local filePart = string.gsub(string.lower((iNew or iName)),"[':%,%.*]","")
                                    :gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")
        		                    :gsub("^([^%(]-) *%(([^%(]-)%)$", "%1_%2")
                		            :gsub(" ", "_")
                        		    :gsub("\"", "")

            if not welcomed then
                outText = outText .. space .. '<span id="qst-bg-grey">'
            else
                outText = outText .. space
            end

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

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

            outText = outText .. "]]"

            if not welcomed then
                outText = outText .. '</span>'
            end
            
            space = " "
        end
    end
	if suffix == "-x" and iSize < 12 then
		outText = outText .. "</small>"
	end

    return outText
end

return p
Advertisement