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
mNo edit summary
No edit summary
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
--[=[
  +
Get Update Name for version
  +
getVersion
  +
Parameters
  +
1. version number
  +
If blank or one of the options below,
  +
the current page name is used
  +
"P" = previous update
  +
"N" = next update
  +
"T" = infobox title (version number) text only
  +
"V" = infobox version (version + name) text only
  +
2. include event date after name
  +
3. text only (no link)
  +
]=]--
  +
 
local p = {}
 
local p = {}
 
 
 
local versionData = mw.loadData( 'Module:UpdateNumber/data' )
 
local versionData = mw.loadData( 'Module:UpdateNumber/data' )
   
function p.getVersion(frame)
+
local function prevUpdate(curVersion)
local versionNo = frame.args[1] or frame:getParent().args[1]
+
local curDate = nil
  +
local includeDate = frame.args[2] or frame:getParent().args[2]
 
  +
if versionData[curVersion] then
  +
curDate = versionData[curVersion][2]
  +
end
  +
  +
local prevDate = 0
  +
local prevVer = ""
  +
  +
if curDate then
  +
for k, v in pairs(versionData) do
  +
if v[2] and v[2] < curDate and v[2] > prevDate then
  +
prevDate = v[2]
  +
prevVer = k
  +
end
  +
end
  +
end
 
 
  +
return prevVer
  +
end
  +
  +
local function nextUpdate(curVersion)
  +
local curDate = nil
  +
  +
if versionData[curVersion] then
  +
curDate = versionData[curVersion][2]
  +
end
  +
  +
local nextDate = 99999999
  +
local nextVer = ""
  +
  +
if curDate then
  +
for k, v in pairs(versionData) do
  +
if v[2] and v[2] > curDate and v[2] < nextDate then
  +
nextDate = v[2]
  +
nextVer = k
  +
end
  +
end
  +
end
  +
  +
return nextVer
  +
end
  +
  +
local function strDate(numDate)
  +
local months = {"January ", "February ", "March ",
  +
"April ", "May ", "June ",
  +
"July ", "August ", "September ",
  +
"October ", "November ", "December "}
 
 
  +
local day = math.min(math.fmod(numDate, 100), 31)
return "[[" .. fooBarText .. "|" .. (versionData[fooBarText][1] or "Work In Progress") .. "]]"
 
  +
-- return "[[1.9.0|test]]"
 
  +
local idd = math.fmod(day, 10)
  +
  +
local nth = (idd==1 and day~=11 and "st ")
  +
or (idd==2 and day~=12 and "nd ")
  +
or (idd==3 and day~=13 and "rd ")
  +
or "th "
  +
  +
local year = math.floor(numDate / 100)
  +
  +
local mon = math.min(math.fmod(year, 100), 12)
  +
  +
year = math.floor(year/100)
  +
  +
return (day .. nth .. months[mon] .. year)
  +
end
  +
  +
function p.getVersion(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 versionNo = tArgs[1] or ""
  +
local inclDate = (tArgs[2] and tArgs[2] ~= "")
  +
local txtOnly = (tArgs[3] and tArgs[3] ~= "")
  +
  +
local outType = ""
  +
  +
if versionNo:match("^[NPTV]$") then
  +
outType = versionNo
  +
versionNo = ""
  +
end
  +
  +
if versionNo == "" then
  +
local pageName = mw.title.getCurrentTitle().text
  +
  +
if versionData[pageName] then
  +
versionNo = pageName
  +
else
  +
local updateNo = tonumber(pageName:match("^Update (%d+)"))
  +
  +
if updateNo then
  +
for k, v in pairs(versionData) do
  +
if v[3] and updateNo == v[3] then
  +
versionNo = k
  +
break
  +
end
  +
end
  +
end
  +
end
  +
end
  +
  +
if not versionData[versionNo] then
  +
return "[[Work In Progress|Unknown Version]]"
  +
end
  +
  +
if outType == "P" then
  +
-- output previous version
  +
versionNo = prevUpdate(versionNo)
  +
if versionNo == "" then return "Unknown" end
  +
elseif outType == "N" then
  +
-- output next version
  +
versionNo = nextUpdate(versionNo)
  +
if versionNo == "" then return "--" end
  +
end
  +
  +
local versionText = ""
  +
  +
if outType == "T" then
  +
versionText = versionNo
  +
txtOnly = true
  +
else
  +
local upNo = versionData[versionNo][3]
  +
  +
if upNo and upNo == 0 then
  +
versionText = versionData[versionNo][1]
  +
else
  +
versionText = versionData[versionNo][1] .. " Update"
  +
end
  +
  +
if outType == "V" then
  +
versionText = versionNo .. "<br />("
  +
.. versionText .. ")"
  +
txtOnly = true
  +
end
  +
end
  +
  +
if not txtOnly then
  +
versionText = "[[" .. versionNo .. "|" .. versionText .. "]]"
  +
end
  +
  +
if inclDate then
  +
versionText = versionText .. " on "
  +
.. strDate(versionData[versionNo][2])
  +
end
  +
  +
return versionText
 
end
 
end
 
 
 
return p
 
return p
  +
  +
-- </nowiki>
  +
-- [[Category:Lua Modules]]

Revision as of 09:31, 30 June 2020

Description

This module is the Lua back-end for {{UpdateNo}}, to display information about game Updates.


Usage

{{#invoke:UpdateNumber|getVersion|<parameter list>}}
For parameter details see Template:UpdateNo/doc

For direct invocation or from other modules

{{#invoke:UpdateNumber|getLastVer|<count>}}
{{#invoke:UpdateNumber|getVars|<item name>}}


--[=[
Get Update Name for version
getVersion
    Parameters
    1. version number
        If blank or one of the options below,
        the current page name is used
        "P" = previous update
        "N" = next update
        "T" = infobox title (version number) text only
        "V" = infobox version (version + name) text only
    2. include event date after name
    3. text only (no link)
]=]--

local p = {}
 
local versionData = mw.loadData( 'Module:UpdateNumber/data' )

local function prevUpdate(curVersion)
    local curDate = nil

    if versionData[curVersion] then
        curDate = versionData[curVersion][2]
    end

    local prevDate = 0
    local prevVer = ""

    if curDate then
        for k, v in pairs(versionData) do
            if v[2] and v[2] < curDate and v[2] > prevDate then
                prevDate = v[2]
                prevVer = k
            end
        end
    end
    
    return prevVer
end

local function nextUpdate(curVersion)
    local curDate = nil

    if versionData[curVersion] then
        curDate = versionData[curVersion][2]
    end

    local nextDate = 99999999
    local nextVer = ""

    if curDate then
        for k, v in pairs(versionData) do
            if v[2] and v[2] > curDate and v[2] < nextDate then
                nextDate = v[2]
                nextVer = k
            end
        end
    end
    
    return nextVer
end

local function strDate(numDate)
    local months = {"January ", "February ", "March ",
                    "April ", "May ", "June ",
                    "July ", "August ", "September ",
                    "October ", "November ", "December "}
 
    local day = math.min(math.fmod(numDate, 100), 31)

    local idd = math.fmod(day, 10)
 
    local nth = (idd==1 and day~=11 and "st ")
                or (idd==2 and day~=12 and "nd ")
                or (idd==3 and day~=13 and "rd ")
                or "th "

    local year = math.floor(numDate / 100)

    local mon = math.min(math.fmod(year, 100), 12)

    year = math.floor(year/100)

    return (day .. nth .. months[mon] .. year)
end

function p.getVersion(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 versionNo = tArgs[1] or ""
    local inclDate  = (tArgs[2] and tArgs[2] ~= "")
    local txtOnly   = (tArgs[3] and tArgs[3] ~= "")

    local outType = ""

    if versionNo:match("^[NPTV]$") then
        outType = versionNo
        versionNo = ""
    end

    if versionNo == "" then
        local pageName = mw.title.getCurrentTitle().text

        if versionData[pageName] then
            versionNo = pageName
        else
            local updateNo = tonumber(pageName:match("^Update (%d+)"))

            if updateNo then
                for k, v in pairs(versionData) do
                    if v[3] and updateNo == v[3] then
                        versionNo = k
                        break
                    end
                end
            end
        end
    end

    if not versionData[versionNo] then
         return "[[Work In Progress|Unknown Version]]"
    end

    if outType == "P" then
        -- output previous version
        versionNo = prevUpdate(versionNo)
        if versionNo == "" then return "Unknown" end
    elseif outType == "N" then
        -- output next version
        versionNo = nextUpdate(versionNo)
        if versionNo == "" then return "--" end
    end

    local versionText = ""

    if outType == "T" then
        versionText = versionNo
        txtOnly = true
    else
        local upNo = versionData[versionNo][3]
        
        if upNo and upNo == 0 then
            versionText = versionData[versionNo][1]
        else
            versionText = versionData[versionNo][1] .. " Update"
        end

        if outType == "V" then
            versionText = versionNo .. "<br />("
                            .. versionText .. ")"
            txtOnly = true
        end
    end

    if not txtOnly then
        versionText = "[[" .. versionNo .. "|" .. versionText .. "]]"
    end

    if inclDate then
        versionText = versionText .. " on "
                    .. strDate(versionData[versionNo][2])
    end

    return versionText
end
 
return p

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