No edit summary |
No edit summary |
||
(69 intermediate revisions by 2 users not shown) | |||
Line 16: | Line 16: | ||
local p = {} |
local p = {} |
||
+ | |||
⚫ | |||
+ | ---[==[ For testing purposes |
||
local versionData = mw.loadData( 'Module:UpdateNumber/data' ) |
local versionData = mw.loadData( 'Module:UpdateNumber/data' ) |
||
+ | --[===[]==] |
||
+ | local versionData = { |
||
+ | ["8.5.0"] = {126, "The Black Cauldron Event", "2023/10/10", 36, 75, "8.5.0j"}, |
||
+ | ["8.5.1"] = {127, "The Black Cauldron Event Hotfix", "2023/10/31", nil, nil, "8.5.1a"}, |
||
+ | } |
||
+ | --]===] |
||
+ | local util = require('Module:Utility') |
||
+ | local date = require('Dev:Date') |
||
local function prevUpdate(curVersion) |
local function prevUpdate(curVersion) |
||
Line 26: | Line 35: | ||
end |
end |
||
− | local prevDate = |
+ | local prevDate = "" |
local prevVer = "" |
local prevVer = "" |
||
Line 48: | Line 57: | ||
end |
end |
||
− | local nextDate = |
+ | local nextDate = "9" |
local nextVer = "" |
local nextVer = "" |
||
Line 63: | Line 72: | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | local months = {"January ", "February ", "March ", |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | local day = math.min(math.fmod(numDate, 100), 31) |
||
− | |||
⚫ | |||
− | |||
− | local nth = (idd==1 and day~=11 and "st ") |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | 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) |
||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
local outType = "" |
local outType = "" |
||
− | if versionNo:match("^[ |
+ | if versionNo:match("^[NPTVR]$") then |
outType = versionNo |
outType = versionNo |
||
versionNo = "" |
versionNo = "" |
||
Line 106: | Line 91: | ||
if updateNo then |
if updateNo then |
||
for k, v in pairs(versionData) do |
for k, v in pairs(versionData) do |
||
− | if v[ |
+ | if v[5] and updateNo == v[5] then |
versionNo = k |
versionNo = k |
||
break |
break |
||
Line 116: | Line 101: | ||
if not versionData[versionNo] then |
if not versionData[versionNo] then |
||
− | return "[[ |
+ | return "[[?|Unknown Version]]" |
end |
end |
||
Line 132: | Line 117: | ||
if outType == "T" then |
if outType == "T" then |
||
− | + | if versionData[versionNo][6] and versionData[versionNo][6] ~= "" then |
|
+ | versionText = versionData[versionNo][6] |
||
⚫ | |||
+ | versionText = versionNo |
||
⚫ | |||
⚫ | |||
+ | elseif outType == "R" then |
||
+ | versionText = versionData[versionNo][1] |
||
txtOnly = true |
txtOnly = true |
||
else |
else |
||
− | local upNo = versionData[versionNo][ |
+ | local upNo = versionData[versionNo][5] |
if upNo and upNo == 0 then |
if upNo and upNo == 0 then |
||
Line 144: | Line 136: | ||
if outType == "V" then |
if outType == "V" then |
||
− | + | if versionData[versionNo][6] |
|
− | + | and versionData[versionNo][6] ~= "" then |
|
+ | versionText = versionData[versionNo][6] .. "<br />(" |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | .. versionText .. ")" |
||
+ | end |
||
txtOnly = true |
txtOnly = true |
||
end |
end |
||
⚫ | |||
+ | |||
+ | if inclDate == "S" and versionData[versionNo][5] then |
||
+ | versionText = "Update " .. versionData[versionNo][5] |
||
end |
end |
||
Line 154: | Line 156: | ||
end |
end |
||
− | if inclDate then |
+ | if inclDate == "U" then |
+ | versionText = "" |
||
+ | if versionData[versionNo][5] then versionText = " and the " .. util.wordinal(versionData[versionNo][5]) .. " major update" end |
||
+ | versionText = "On '''" |
||
+ | .. util.strDate(versionData[versionNo][3], 0) |
||
⚫ | |||
+ | .. util.wordinal(versionData[versionNo][1]) |
||
⚫ | |||
+ | .. versionText |
||
⚫ | |||
+ | .. versionNo |
||
+ | .. ")'' was released for the game." |
||
+ | elseif inclDate == "D" then |
||
versionText = versionText .. " on " |
versionText = versionText .. " on " |
||
− | .. strDate(versionData[versionNo][3]) |
+ | .. util.strDate(versionData[versionNo][3]) |
+ | elseif inclDate == "B" then |
||
+ | versionText = versionText .. " somewhere " |
||
+ | .. util.durDate(versionData[versionNo][3], versionData[versionNo][4], nil, nil, true) |
||
end |
end |
||
Line 163: | Line 180: | ||
-- return a list of versions for year |
-- return a list of versions for year |
||
− | function multiVersion( |
+ | local function multiVersion() |
+ | local navbox = require('Module:Navbox').main |
||
+ | local allVersions = {} |
||
+ | |||
⚫ | |||
+ | local year = string.sub(v[3], 1, 4) |
||
+ | if not allVersions[year] then allVersions[year] = {} end |
||
+ | table.insert(allVersions[year], {v[1], n, v[3], v[6]}) |
||
+ | end |
||
+ | |||
+ | local paramTable = {"child"} |
||
⚫ | |||
+ | local currYear = nil |
||
+ | local list = {} |
||
+ | |||
+ | table.sort(allVersions, function(a,b) return a[1] < b[1] end) |
||
+ | |||
⚫ | |||
+ | if key ~= currYear then |
||
+ | if currYear then |
||
+ | paramTable["group" .. key] = key |
||
+ | paramTable["list" .. key] = table.concat(list, " '''·''' ") |
||
+ | group = group + 1 |
||
+ | list = {} |
||
+ | end |
||
+ | currYear = key |
||
+ | end |
||
+ | |||
+ | table.sort(values, function(a,b) return a[3] < b[3] end) |
||
+ | |||
+ | for i, tData in pairs(values) do |
||
+ | table.insert(list, table.concat({"[[", tData[2], "|", (tData[4] or tData[2]), "]]"})) |
||
+ | end |
||
+ | |||
+ | paramTable["group" .. key] = key |
||
+ | paramTable["list" .. key] = table.concat(list, " '''·''' ") |
||
+ | end |
||
+ | |||
+ | return navbox(paramTable) |
||
⚫ | |||
+ | |||
+ | -- return last X versions formatted for Main Page |
||
+ | local function lastVersions(count) |
||
local tIndex = {} |
local tIndex = {} |
||
+ | local today = date():fmt("%Y/%m/%d") |
||
+ | for k, v in pairs(versionData) do |
||
⚫ | |||
⚫ | |||
− | table.insert(tIndex, "1.0.4") |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
table.insert(tIndex, k) |
table.insert(tIndex, k) |
||
end |
end |
||
end |
end |
||
− | table.sort(tIndex) |
+ | table.sort(tIndex, function(a,b) return a > b end) |
local outText = "" |
local outText = "" |
||
⚫ | |||
− | for |
+ | for i, ver in ipairs(tIndex) do |
− | + | local dateText = util.strDate(versionData[ver][3], nil, nil, true) |
|
− | + | local verText = mw.text.truncate(versionData[ver][2] .. " Update", |
|
− | .. |
+ | 43 - mw.ustring.len(dateText), nil, true) |
+ | |||
⚫ | |||
− | + | outText = outText |
|
− | + | .. "* [[" |
|
− | + | .. ver |
|
− | + | .. "|" |
|
− | + | .. verText |
|
− | + | .. "]] <small>" |
|
− | + | .. dateText |
|
− | + | .. "</small>\n" |
|
+ | |||
⚫ | |||
− | + | if i >= count then break end |
|
⚫ | |||
end |
end |
||
Line 207: | Line 258: | ||
-- function get Version Name |
-- function get Version Name |
||
function p.getVersion(frame) |
function p.getVersion(frame) |
||
− | local tArgs |
+ | local tArgs = util.getArgs(frame) |
⚫ | |||
− | if frame == mw.getCurrentFrame() then |
||
⚫ | |||
− | fParent = frame:getParent() |
||
− | tArgs = |
+ | local txtOnly = (tArgs[3] and tArgs[3] ~= "") |
− | + | if versionNo == "multi" then |
|
− | + | return multiVersion() |
|
⚫ | |||
⚫ | |||
⚫ | |||
+ | end |
||
+ | |||
+ | -- function get Last X Versions formatted for Main Page |
||
+ | function p.getLastVer(frame) |
||
⚫ | |||
+ | |||
⚫ | |||
+ | count = tonumber(count) or 5 |
||
+ | |||
+ | return lastVersions(count) |
||
+ | end |
||
+ | |||
+ | function p.getVars(frame) |
||
+ | local tArgs = util.getArgs(frame) |
||
+ | |||
+ | local curVer = tArgs[1] or "" |
||
+ | |||
+ | if curVer == "" then |
||
+ | local pageName = mw.title.getCurrentTitle().text |
||
+ | if versionData[pageName] then |
||
+ | curVer = pageName |
||
else |
else |
||
− | + | local updateNo = tonumber(pageName:match("^Update (%d+)")) |
|
⚫ | |||
+ | for k, v in pairs(versionData) do |
||
+ | if v[5] and updateNo == v[5] then |
||
⚫ | |||
+ | break |
||
⚫ | |||
⚫ | |||
+ | end |
||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
+ | local curData = versionData[curVer] |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | if not curData then |
||
− | local multi, year = versionNo:match("^(multi)(%d*)$") |
||
+ | curData = {0, "Unknown Version", nil, 0, 0} |
||
+ | curVer = "Unkown Version" |
||
+ | end |
||
+ | local prevVer = nil |
||
⚫ | |||
+ | local prevData = {} |
||
− | return multiVersion(tonumber(year)) |
||
+ | local nextVer = nil |
||
⚫ | |||
+ | local nextData = {} |
||
⚫ | |||
+ | |||
+ | if curData[3] then |
||
+ | for k, v in pairs(versionData) do |
||
+ | if v[3] then |
||
+ | if v[3] < curData[3] and v[3] > (prevData[3] or "") then |
||
+ | prevData = v |
||
⚫ | |||
+ | end |
||
+ | if v[3] > curData[3] and v[3] < (nextData[3] or "9") then |
||
+ | nextData = v |
||
+ | nextVer = k |
||
+ | end |
||
+ | end |
||
+ | end |
||
end |
end |
||
+ | |||
+ | if curData[6] and curData[6] ~= "" then |
||
+ | curVer = curData[6] |
||
+ | end |
||
+ | |||
+ | local VL = mw.ext.VariablesLua |
||
+ | |||
+ | VL.vardefine("pnTitle", curVer) |
||
+ | VL.vardefine("pnUpNo", curData[1]) |
||
+ | |||
+ | local tVer = {curVer, "<br />(", curData[2], "", ")"} |
||
+ | if not curData[5] or curData[5] ~= 0 then |
||
+ | tVer[4] = " Update" |
||
+ | end |
||
⚫ | |||
+ | VL.vardefine("pnVer", table.concat(tVer)) |
||
+ | if curData[3] then |
||
+ | VL.vardefine("pnDate", util.strDate(curData[3] ) .. " (iOS)<br/>" .. util.strDate(curData[3]) .. " (Android)<br/>" .. util.strDate(curData[3]) .. " (Windows)") |
||
+ | VL.vardefine("pnDur", (curData[4] and (curData[4] .. " Days") or nil)) |
||
+ | end |
||
+ | |||
⚫ | |||
+ | if ver then |
||
+ | local tLink = {"[[", ver, "|", data[2], " Update", "]]"} |
||
⚫ | |||
+ | tLink[5] = "" |
||
+ | end |
||
+ | return table.concat(tLink) |
||
+ | else |
||
+ | return "--" |
||
+ | end |
||
+ | end |
||
+ | |||
+ | VL.vardefine("pnPrev", prevnext(prevVer, prevData)) |
||
+ | VL.vardefine("pnNext", prevnext(nextVer, nextData)) |
||
end |
end |
||
return p |
return p |
||
− | |||
− | -- </nowiki> |
||
− | -- [[Category:Lua Modules]] |
Latest revision as of 11:01, 6 April 2024
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>}}
--[[<nowiki>
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
"R" = release number
2. include event date after name
3. text only (no link)
--]]
local p = {}
---[==[ For testing purposes
local versionData = mw.loadData( 'Module:UpdateNumber/data' )
--[===[]==]
local versionData = {
["8.5.0"] = {126, "The Black Cauldron Event", "2023/10/10", 36, 75, "8.5.0j"},
["8.5.1"] = {127, "The Black Cauldron Event Hotfix", "2023/10/31", nil, nil, "8.5.1a"},
}
--]===]
local util = require('Module:Utility')
local date = require('Dev:Date')
local function prevUpdate(curVersion)
local curDate = nil
if versionData[curVersion] then
curDate = versionData[curVersion][3]
end
local prevDate = ""
local prevVer = ""
if curDate then
for k, v in pairs(versionData) do
if v[3] and v[3] < curDate and v[3] > prevDate then
prevDate = v[3]
prevVer = k
end
end
end
return prevVer
end
local function nextUpdate(curVersion)
local curDate = nil
if versionData[curVersion] then
curDate = versionData[curVersion][3]
end
local nextDate = "9"
local nextVer = ""
if curDate then
for k, v in pairs(versionData) do
if v[3] and v[3] > curDate and v[3] < nextDate then
nextDate = v[3]
nextVer = k
end
end
end
return nextVer
end
-- return information for a single version/update
local function oneVersion(versionNo, inclDate, txtOnly)
local outType = ""
if versionNo:match("^[NPTVR]$") 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[5] and updateNo == v[5] then
versionNo = k
break
end
end
end
end
end
if not versionData[versionNo] then
return "[[?|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
if versionData[versionNo][6] and versionData[versionNo][6] ~= "" then
versionText = versionData[versionNo][6]
else
versionText = versionNo
end
txtOnly = true
elseif outType == "R" then
versionText = versionData[versionNo][1]
txtOnly = true
else
local upNo = versionData[versionNo][5]
if upNo and upNo == 0 then
versionText = versionData[versionNo][2]
else
versionText = versionData[versionNo][2] .. " Update"
end
if outType == "V" then
if versionData[versionNo][6]
and versionData[versionNo][6] ~= "" then
versionText = versionData[versionNo][6] .. "<br />("
.. versionText .. ")"
else
versionText = versionNo .. "<br />("
.. versionText .. ")"
end
txtOnly = true
end
end
if inclDate == "S" and versionData[versionNo][5] then
versionText = "Update " .. versionData[versionNo][5]
end
if not txtOnly then
versionText = "[[" .. versionNo .. "|" .. versionText .. "]]"
end
if inclDate == "U" then
versionText = ""
if versionData[versionNo][5] then versionText = " and the " .. util.wordinal(versionData[versionNo][5]) .. " major update" end
versionText = "On '''"
.. util.strDate(versionData[versionNo][3], 0)
.. "''', the "
.. util.wordinal(versionData[versionNo][1])
.. " update"
.. versionText
.. " ''("
.. versionNo
.. ")'' was released for the game."
elseif inclDate == "D" then
versionText = versionText .. " on "
.. util.strDate(versionData[versionNo][3])
elseif inclDate == "B" then
versionText = versionText .. " somewhere "
.. util.durDate(versionData[versionNo][3], versionData[versionNo][4], nil, nil, true)
end
return versionText
end
-- return a list of versions for year
local function multiVersion()
local navbox = require('Module:Navbox').main
local allVersions = {}
for n, v in pairs(versionData) do
local year = string.sub(v[3], 1, 4)
if not allVersions[year] then allVersions[year] = {} end
table.insert(allVersions[year], {v[1], n, v[3], v[6]})
end
local paramTable = {"child"}
local group = 1
local currYear = nil
local list = {}
table.sort(allVersions, function(a,b) return a[1] < b[1] end)
for key, values in pairs(allVersions) do
if key ~= currYear then
if currYear then
paramTable["group" .. key] = key
paramTable["list" .. key] = table.concat(list, " '''·''' ")
group = group + 1
list = {}
end
currYear = key
end
table.sort(values, function(a,b) return a[3] < b[3] end)
for i, tData in pairs(values) do
table.insert(list, table.concat({"[[", tData[2], "|", (tData[4] or tData[2]), "]]"}))
end
paramTable["group" .. key] = key
paramTable["list" .. key] = table.concat(list, " '''·''' ")
end
return navbox(paramTable)
end
-- return last X versions formatted for Main Page
local function lastVersions(count)
local tIndex = {}
local today = date():fmt("%Y/%m/%d")
for k, v in pairs(versionData) do
if today >= v[3] then
table.insert(tIndex, k)
end
end
table.sort(tIndex, function(a,b) return a > b end)
local outText = ""
for i, ver in ipairs(tIndex) do
local dateText = util.strDate(versionData[ver][3], nil, nil, true)
local verText = mw.text.truncate(versionData[ver][2] .. " Update",
43 - mw.ustring.len(dateText), nil, true)
outText = outText
.. "* [["
.. ver
.. "|"
.. verText
.. "]] <small>"
.. dateText
.. "</small>\n"
if i >= count then break end
end
return outText
end
-- function get Version Name
function p.getVersion(frame)
local tArgs = util.getArgs(frame)
local versionNo = tArgs[1] or ""
local inclDate = tArgs[2] or ""
local txtOnly = (tArgs[3] and tArgs[3] ~= "")
if versionNo == "multi" then
return multiVersion()
else
return oneVersion(versionNo, inclDate, txtOnly)
end
end
-- function get Last X Versions formatted for Main Page
function p.getLastVer(frame)
local tArgs = util.getArgs(frame)
local count = tArgs[1] or 5
count = tonumber(count) or 5
return lastVersions(count)
end
function p.getVars(frame)
local tArgs = util.getArgs(frame)
local curVer = tArgs[1] or ""
if curVer == "" then
local pageName = mw.title.getCurrentTitle().text
if versionData[pageName] then
curVer = pageName
else
local updateNo = tonumber(pageName:match("^Update (%d+)"))
if updateNo then
for k, v in pairs(versionData) do
if v[5] and updateNo == v[5] then
curVer = k
break
end
end
end
end
end
local curData = versionData[curVer]
if not curData then
curData = {0, "Unknown Version", nil, 0, 0}
curVer = "Unkown Version"
end
local prevVer = nil
local prevData = {}
local nextVer = nil
local nextData = {}
if curData[3] then
for k, v in pairs(versionData) do
if v[3] then
if v[3] < curData[3] and v[3] > (prevData[3] or "") then
prevData = v
prevVer = k
end
if v[3] > curData[3] and v[3] < (nextData[3] or "9") then
nextData = v
nextVer = k
end
end
end
end
if curData[6] and curData[6] ~= "" then
curVer = curData[6]
end
local VL = mw.ext.VariablesLua
VL.vardefine("pnTitle", curVer)
VL.vardefine("pnUpNo", curData[1])
local tVer = {curVer, "<br />(", curData[2], "", ")"}
if not curData[5] or curData[5] ~= 0 then
tVer[4] = " Update"
end
VL.vardefine("pnVer", table.concat(tVer))
if curData[3] then
VL.vardefine("pnDate", util.strDate(curData[3] ) .. " (iOS)<br/>" .. util.strDate(curData[3]) .. " (Android)<br/>" .. util.strDate(curData[3]) .. " (Windows)")
VL.vardefine("pnDur", (curData[4] and (curData[4] .. " Days") or nil))
end
local function prevnext(ver, data)
if ver then
local tLink = {"[[", ver, "|", data[2], " Update", "]]"}
if data[5] and data[5] ~= 0 then
tLink[5] = ""
end
return table.concat(tLink)
else
return "--"
end
end
VL.vardefine("pnPrev", prevnext(prevVer, prevData))
VL.vardefine("pnNext", prevnext(nextVer, nextData))
end
return p