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
(6 intermediate revisions by 2 users not shown)
Line 43: Line 43:
 
 
 
local collections = {}
 
local collections = {}
local index = 1
 
   
 
for cName in mw.text.gsplit(character, "%s*!%s*") do
 
for cName in mw.text.gsplit(character, "%s*!%s*") do
   
 
if collectionData[cName] then
 
if collectionData[cName] then
collections[index] = collectionData[cName]
+
local coll = collectionData[cName]
 
local file = mw.ustring.gsub(coll, "[\,\.]", "")
  +
file = mw.ustring.gsub(file, " ", "_")
  +
file = mw.ustring.lower(file)
  +
 
if not collections[coll] then
 
collectionFile = collectionFile .. space
 
.. "[[File:cc-"
 
.. file
 
.. "-l.png|x"
 
.. size
 
.. "px|"
 
.. coll
 
.. "|link=Category:"
  +
.. coll
  +
.. "]]"
 
  +
space = " "
  +
 
collections[coll] = 1
 
end
 
end
 
end
end
 
 
for _, coll in ipairs(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
 
end
   
Line 71: Line 75:
   
 
return p
 
return p
  +
  +
-- </nowiki>
  +
-- [[Category:Lua Modules]]

Revision as of 09:37, 30 June 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
            local coll = collectionData[cName]
            local file = mw.ustring.gsub(coll, "[\,\.]", "")
            file = mw.ustring.gsub(file, " ", "_")
            file = mw.ustring.lower(file)

            if not collections[coll] then
                collectionFile = collectionFile .. space
                    .. "[[File:cc-"
                    .. file
                    .. "-l.png|x"
                    .. size
                    .. "px|"
                    .. coll
                    .. "|link=Category:"
                    .. coll
                    .. "]]"
            
                space = " "

            	collections[coll] = 1
            end
        end
    end

    return collectionFile
end

return p

-- </nowiki>
-- [[Category:Lua Modules]]