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
No edit summary
No edit summary
Line 48: Line 48:
 
if collectionData[cName] then
 
if collectionData[cName] then
 
collections[collectionData[cName]] = 1
 
collections[collectionData[cName]] = 1
  +
collectionFile = collectionFile .. collectionData[cName]
 
end
 
end
 
end
 
end

Revision as of 19:05, 21 May 2020

Description

This module is the Lua back-end to display information about the collection the item is part of.

Usage

{{#invoke:ItemCollection|getCollection|<parameter list>}}

Directly Invoked

{{#invoke:ItemCollection|getGallery}}


------
-- LUA script to get Collection Icon for Character
----
-- Parameters:
-- 1: Character Name
-- 2: Icon Size
--
------

local p = {}

local collectionData = mw.loadData( 'Module:CharacterCollection/data' )

function p.getCollection(frame)

    local tArgs

    if frame == mw.getCurrentFrame() then
        fParent = frame:getParent()
        tArgs = fParent.args

        if (fParent.args[1]) then
            tArgs = fParent.args
        else
            tArgs = frame.args
        end
    else
        tArgs = frame
    end

    local character = tArgs[1] or ""
    local size = tArgs[2]
    
    if not size or size == "" then
        size = "50"
    end

    character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or ''
    character = mw.ustring.lower(character)

    local collectionFile = ""
    local space = ""
    
    local collections = {}

    for cName in mw.text.gsplit(character, "%s*!%s*") do

        if collectionData[cName] then
        	collections[collectionData[cName]] = 1
        	collectionFile = collectionFile .. collectionData[cName]
        end
    end

    for coll, _ in pairs(collections) do
        collectionFile = collectionFile .. space
            .. "[[File:cc-"
            .. mw.ustring.gsub(mw.ustring.lower(coll), " ", "_")
            .. "-l.png|x"
            .. size
            .. "px|"
            .. coll
            .. "|link=Category:"
            .. coll
            .. "]]"
    
        space = " "
    end

    return collectionFile
end

return p