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
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
------
 
------
-- LUA script to get Currency for Enchanted Chests
+
-- LUA script to get Currency Icon
 
--
 
--
 
-- Parameters:
 
-- Parameters:
 
-- 1: Currency = (Currency,count)
 
-- 1: Currency = (Currency,count)
-- count is optional
+
-- count is optional
  +
-- count can include "," only first "," separates fields
-- 2: Size in pixels
 
  +
-- multiple separated by "!" (exclamation mark)
-- optional, defaults to 25
 
  +
-- 2: Include Name/Text Link (Optional)
 
-- N = Currency Name
 
-- E = "Event Currency"
 
-- e = "event currency"
  +
-- A = Alternate Text
  +
-- L = Currency Name link (without Icon)
  +
-- uses Alternate Text if present
  +
-- T = Currency Name text only (without Icon)
  +
-- 3: Alternate Text (Optional)
  +
-- 4: Icon or Image (Optional)
  +
-- Display Image file if present
 
-- 5: Size in pixels (Optional)
  +
-- for Icon default 22
  +
-- for Image default 50
  +
--
 
-- The list of available currency is kept in the module data
 
-- The list of available currency is kept in the module data
 
--
 
--
Line 14: Line 29:
 
local p = {}
 
local p = {}
   
local currencyData = mw.loadData( 'Module:Currency/data' )
+
local currencyData = mw.loadData( 'Module:EC/data' )
   
function p.getCurrency(frame)
+
function p.getEC(frame)
   
 
local tArgs
 
local tArgs
Line 34: Line 49:
   
 
local currency = tArgs[1] or ""
 
local currency = tArgs[1] or ""
local size = tArgs[2]
+
local inclName = tArgs[2] or ""
  +
local altText = tArgs[3] or ""
 
  +
local imgType = tArgs[4] or ""
  +
local size = tArgs[5]
  +
 
if not size or size == "" then
 
if not size or size == "" then
size = "25"
+
size = "22"
  +
if imgType ~= "" then size = "50" end
 
end
  +
  +
local imgSize = ".png|x" .. size .. "px|"
  +
  +
if imgType ~= "" then
 
imgType = "F"
 
else
 
imgType = "I"
 
end
 
end
   
Line 48: Line 75:
 
for cur in mw.text.gsplit(currency, "%s*!%s*") do
 
for cur in mw.text.gsplit(currency, "%s*!%s*") do
   
local currencyFile
 
local currencyLink
 
 
 
local cName, count = mw.ustring.match(cur,
 
local cName, count = mw.ustring.match(cur,
"^([^,]-)%s*,%s*(%d+)%s*,*%s*([\/%d]*)$")
+
"^([^,]-)%s*,%s*([%/%,%d%?%-]*)$")
   
if not cName then
+
if not cName then cName = cur end
  +
-- strip "EC-" from start of name
cName, count = mw.ustring.match(cur, "^([^,]-)%s*,%s*,*%s*([\/%d]*)$")
 
if not cName then cName = cur end
+
cName = mw.ustring.gsub(cName, "^ec%-", "")
  +
 
local imageFile = "[[File:work_in_progress"
 
local imageLink = cName .. "|link=Work In Progress]]"
  +
local nameText = "Work In Progress"
  +
 
if currencyData[cName] then
 
if currencyData[cName][imgType] then
 
imageFile = "[[File:"
 
.. mw.ustring.gsub(currencyData[cName][imgType], " ", "_")
 
end
  +
 
if currencyData[cName]["N"] then
  +
nameText = currencyData[cName]["N"]
  +
imageLink = nameText
  +
.. "|link="
  +
.. nameText
  +
.. "]]"
  +
end
 
end
 
end
   
 
local nameLink = ""
if currencyData[cName] and currencyData[cName][currencyType] then
 
 
local dispIcon = 1
if currencyData[cName]["F"] then
 
  +
local bracket = nil
currencyFile = "[[File:" .. currencyData[cName]["F"]
 
  +
else
 
  +
if mw.ustring.match(inclName, "^[NEeALT]$") then
currencyFile = "[[File:" .. currencyData[cName]
 
  +
if inclName == "N" then
  +
nameLink = "[[" .. nameText .. "]]"
  +
elseif inclName == "E" then
  +
nameLink = "[[" .. nameText .. "|Event Currency]]"
  +
elseif inclName == "e" then
  +
nameLink = "[[" .. nameText .. "|event currency]]"
  +
elseif inclName == "T" then
  +
nameLink = nameText
  +
elseif inclName == "A" or inclName == "L" then
  +
nameLink = "[[" .. nameText
  +
if altText ~= "" then
  +
nameLink = nameLink .. "|" .. altText
 
end
  +
nameLink = nameLink .. "]]"
 
end
 
end
  +
currencyFile = mw.ustring.gsub(currencyFile, " ", "_")
 
+
if inclName == "L" or inclName == "T" then
if currencyData[cName]["E"] then
+
dispIcon = nil
currencyLink = "|" .. currencyData[cName][E]
 
.. "|link="
 
.. currencyData[cName][E]
 
.. "]]"
 
 
else
 
else
currencyLink = "|Error|link=Work In Progress]]"
+
bracket = 1
 
end
 
end
 
else
 
currencyFile = "[[File:work_in_progress"
 
currencyLink = "|Error|link=Work In Progress]]"
 
 
end
 
end
  +
 
 
currencyFileAll = currencyFileAll .. space
 
currencyFileAll = currencyFileAll .. space
.. currencyFile .. ".png|x"
+
.. nameLink
.. size
 
.. "px"
 
.. currencyLink
 
   
if count and count ~= "" then
+
if dispIcon then
  +
if bracket then
currencyFileAll = currencyFileAll .. "'''" .. count .. "'''"
 
  +
currencyFileAll = currencyFileAll .. " ("
  +
end
  +
  +
currencyFileAll = currencyFileAll
  +
.. imageFile .. imgSize .. imageLink
  +
  +
if bracket then
  +
currencyFileAll = currencyFileAll .. ")"
  +
end
  +
  +
if count and count ~= "" then
 
currencyFileAll = currencyFileAll .. "'''" .. count .. "'''"
  +
end
 
end
 
end
  +
  +
-- if nameLink ~= "" then
  +
-- currencyFileAll = currencyFileAll .. ")"
 
-- end
   
 
space = " "
 
space = " "
Line 97: Line 159:
   
 
return p
 
return p
  +
  +
-- </nowiki>
  +
-- [[Category:Lua Modules]]

Revision as of 09:29, 30 June 2020

Description

This module is the Lua back-end for {{EC}}, to display information about in-game currencies.


Usage

{{#invoke:EC|getEC|<parameter list>}}

For parameter details see Template:EC/doc


------
-- LUA script to get Currency Icon
--
-- Parameters:
-- 1: Currency = (Currency,count)
--              count is optional
--              count can include "," only first "," separates fields
--              multiple separated by "!" (exclamation mark)
-- 2: Include Name/Text Link (Optional)
--              N = Currency Name
--              E = "Event Currency"
--              e = "event currency"
--              A = Alternate Text
--              L = Currency Name link (without Icon)
--                  uses Alternate Text if present
--              T = Currency Name text only (without Icon)
-- 3: Alternate Text (Optional)
-- 4: Icon or Image (Optional)
--              Display Image file if present
-- 5: Size in pixels (Optional)
--              for Icon default 22
--              for Image default 50
--
-- The list of available currency is kept in the module data
--
-- Unknown Currency is returned if Currency Type is not in data.
------

local p = {}

local currencyData = mw.loadData( 'Module:EC/data' )

function p.getEC(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 currency = tArgs[1] or ""
    local inclName = tArgs[2] or ""
    local altText  = tArgs[3] or ""
    local imgType  = tArgs[4] or ""
    local size     = tArgs[5]

    if not size or size == "" then
        size = "22"
        if imgType ~= "" then size = "50" end
    end

    local imgSize = ".png|x" .. size .. "px|"

    if imgType ~= "" then
        imgType = "F"
    else
        imgType = "I"
    end

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

    local currencyFileAll = ""
    local space = ""

    for cur in mw.text.gsplit(currency, "%s*!%s*") do

        local cName, count = mw.ustring.match(cur, 
                            "^([^,]-)%s*,%s*([%/%,%d%?%-]*)$")

        if not cName then cName = cur end
        -- strip "EC-" from start of name
        cName = mw.ustring.gsub(cName, "^ec%-", "")

        local imageFile = "[[File:work_in_progress"
        local imageLink = cName .. "|link=Work In Progress]]"
        local nameText = "Work In Progress"

        if currencyData[cName] then
            if currencyData[cName][imgType] then
                imageFile = "[[File:"
                            .. mw.ustring.gsub(currencyData[cName][imgType], " ", "_")
            end

            if currencyData[cName]["N"] then
                nameText = currencyData[cName]["N"]
                imageLink = nameText
                            .. "|link="
                            .. nameText
                            .. "]]"
            end
        end

        local nameLink = ""
        local dispIcon = 1
        local bracket  = nil

        if mw.ustring.match(inclName, "^[NEeALT]$") then
            if inclName == "N" then
                nameLink = "[[" .. nameText .. "]]"
            elseif inclName == "E" then
                nameLink = "[[" .. nameText .. "|Event Currency]]"
            elseif inclName == "e" then
                nameLink = "[[" .. nameText .. "|event currency]]"
            elseif inclName == "T" then
                nameLink = nameText
            elseif inclName == "A" or inclName == "L" then
                nameLink = "[[" .. nameText
                if altText ~= "" then
                    nameLink = nameLink .. "|" .. altText
                end
                nameLink = nameLink .. "]]"
            end

            if inclName == "L" or inclName == "T" then
                dispIcon = nil
            else
                bracket = 1
            end
        end

        currencyFileAll = currencyFileAll .. space
            .. nameLink

        if dispIcon then
            if bracket then
                currencyFileAll = currencyFileAll .. " ("
            end

            currencyFileAll = currencyFileAll
                .. imageFile .. imgSize .. imageLink

            if bracket then
                currencyFileAll = currencyFileAll .. ")"
            end

            if count and count ~= "" then
                currencyFileAll = currencyFileAll .. "'''" .. count .. "'''"
            end
        end

--        if nameLink ~= "" then
--            currencyFileAll = currencyFileAll .. ")"
--        end

        space = " "
    end
    return currencyFileAll
end

return p

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