缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:版本信息框

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

用于模板:Template:版本信息框。 视图模块:Module:信息框/版本。 数据模块:Module:Data/版本



-- Module:版本信息框
local p = {}
local getArgs = require([[Module:Arguments]]).getArgs
local utils = require([[Module:Utils]])
local infobox = require([[Module:信息框/版本]])
local fstr = mw.ustring.format
local vData = mw.loadData("Module:Data/版本")
local versionVariants = {EX1 = "眼冒金星!", BASE = "本体游戏"}
local releaseVariants = {
    Test = "测试版",
    Release = "正式版",
    Hotfix = "热修复"
}

local function f_and(p1, p2) return function(x) return p1(x) and p2(x) end end

-- of a version code is for the extension 1 (Space Out!)
local function is_ex(is)
    return function(id) return is == (vData[id].prefix == 'EX1') end
end

-- Release / Hotfix
local function is_rh(id) return vData[id].type ~= "Test" end
local function is_t(id) return vData[id].type == "Test" end
local function is_r(id) return vData[id].type == "Release" end

local function has_name(id) return
    vData[id].name ~= nil and vData[id].name ~= "" end

-- Get the max key of a table
local function tbl_max(tbl, predicate)
    local mk = -math.huge
    for k, _ in pairs(tbl) do if predicate(k) and k > mk then mk = k end end
    return mk
end

local function get_first(tbl, predicate)
    for k, v in pairs(tbl) do if predicate(k) then return {k, v} end end
end

local function getVarient(prefix) return prefix == "EX1" and "EX1" or "BASE" end

-- test by: =p.getInfo{pagename='版本/206776'}
function p.getInfo(args)
    local out = {}
    local childPagename = mw.text.split(args.pagename, '/', true)
    childPagename = childPagename[#childPagename]
    local pagenameSegs = mw.text.split(childPagename, '-', true)
    local prefix = pagenameSegs[#pagenameSegs - 1]
    local build = tonumber(pagenameSegs[#pagenameSegs])
    local currBuild = vData[build]
    if currBuild == nil then
        return {
            ["名称"] = fstr("找不到版本 %s,请联系管理员。",
                              childPagename)
        }
    end
    local varient = getVarient(prefix)
    local versionBuilds = {}
    for k, v in pairs(vData) do
        if getVarient(v.prefix) == varient then
            table.insert(versionBuilds, k)
        end
    end
    table.sort(versionBuilds)

    local currIdx = nil
    for i, k in ipairs(versionBuilds) do
        if k == build then
            currIdx = i
            break
        end
    end
    if currIdx == nil then
        return {["名称"] = "模块错误,请联系管理员。"}
    end

    out["名称"] = childPagename
    out["发布日期"] = currBuild["release_date"]:gsub("(%d%d)/(%d%d)/(%d%d)", "20%3 年 %1 月 %2 日")
    out["版本"] = versionVariants[varient]
    out["类型"] = releaseVariants[currBuild.type]

    local prevVer = versionBuilds[currIdx - 1]
    local nextVer = versionBuilds[currIdx + 1]
    out["上一版本"] = prevVer and fstr("[[%s]]", vData[prevVer].page) or "-"
    out["下一版本"] = nextVer and fstr("[[%s]]", vData[nextVer].page) or "-"
    return out
end

-- test by: =p.main(require("Module:debug").frame({},{pagename='Version/EX1-465243'}))
function p.main(frame)
    local out = {}
	local data = {}
	data.data = p.getInfo(getArgs(frame))
	data.label = "版本信息框"
	table.insert(out,data)
	mw.logObject(out)
    return infobox.main("版本信息框",out)
end

-- test by: =p.intro(require("Module:debug").frame({},{pagename='版本/206776', relnotes=""}))
-- test by: =p.intro(require("Module:debug").frame({},{pagename='版本/EX1-465243', relnotes=""}))
-- test by: =p.intro(require("Module:debug").frame({},{pagename='版本/EX1-465243', relnotes="oni-alpha/252151-r363"}))
-- test by: =p.intro(require("Module:debug").frame({},{pagename='版本/EX1-465243', relnotes="https://forums.kleientertainment.com/game-updates/oni-alpha/252151-r363"}))
function p.intro(frame)
    local args = getArgs(frame)
    local childPagename = mw.text.split(args.pagename, '/', true)
    childPagename = childPagename[#childPagename]
    local pagenameSegs = mw.text.split(childPagename, '-', true)
    local prefix = pagenameSegs[#pagenameSegs - 1]
    local build = tonumber(pagenameSegs[#pagenameSegs])
    local ver = vData[build]
    local date = ver["release_date"]:gsub("(%d%d)/(%d%d)/(%d%d)", "20%3 年 %1 月 %2 日")
    local nameSuf = ""
    if prefix == "EX1" then nameSuf = ":" .. versionVariants[prefix] end

    local out = ("'''%s''' 是'''缺氧'''%s在 %s(太平洋时间)发布的更新。"):format(childPagename, nameSuf, date)

    local url = ver["url_or_suffix"] or args.relnotes or ""
    if not utils.startswith(url, "https://") then
        url = "https://forums.kleientertainment.com/game-updates/" .. url
    end

    out = ("%s<br/>[%s 官方更新日志]"):format(out, url)
    return out
end

-- test: =p.recent(require("Module:debug").frame({},{"3", "**"}))
function p.recent(frame)
    local args = getArgs(frame)
    local limit = tonumber(args[1]) or 3
    local prefix = args[2] or "*"

    local vs = {}
    for k, _ in pairs(vData) do table.insert(vs, k) end
    table.sort(vs, function(x, y) return x > y end)

    local out = {}
    for i = 1, limit do
        local currVer = vData[vs[i]]
        local date = currVer["release_date"]:gsub("(%d%d)/(%d%d)/(%d%d)", "20%3 年 %1 月 %2 日")
        table.insert(out,
                     fstr(
                         "%s<span style='white-space: nowrap;'>[[%s|%s-%s]](%s)</span>",
                         prefix, currVer.page, currVer.prefix, vs[i], date))
    end
    return mw.getCurrentFrame():preprocess(table.concat(out, "\n"))
end

return p