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

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

全站通知:

模块:星群导航

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
-- Module:星群导航(眼冒金星)
local p = {}
local fstr = mw.ustring.format
local getArgs = require('Module:Dev/Arguments').getArgs
local navbox = require([[Module:导航栏]])
local utils = require([[Module:Utils]])
local po = require([[Module:Po]]).po
-- local clustersBASE = mw.loadData([[Module:Data/Worldgen/Clusters]])
local clustersDLC1 = mw.loadData([[Module:Data/Worldgen/Clusters/Expansion1]])
local clustersDLC2 = mw.loadData([[Module:Data/Worldgen/Clusters/Dlc2]])

local CATS_ORDER = {
    Vanilla = 0,
    SpacedOutVanillaStyle = 1,
    SpacedOutStyle = 2,
    Special = 3,
}
local CLUSTER_CATEGORY_NAME = {
    [0] = "STRINGS.UI.FRONTEND.CLUSTERCATEGORYSELECTSCREEN.VANILLA_TITLE",
    "STRINGS.UI.FRONTEND.CLUSTERCATEGORYSELECTSCREEN.CLASSIC_TITLE",
    "STRINGS.UI.FRONTEND.CLUSTERCATEGORYSELECTSCREEN.SPACEDOUT_TITLE",
    "STRINGS.UI.FRONTEND.CLUSTERCATEGORYSELECTSCREEN.EVENT_TITLE",
}
local CLUSTER_CATEGORY_NAME_2 = {
    [4] = "其他"
}

function p.isForbidden(mTable)
    if mTable == nil then
        return false
    end
    for _, tag in ipairs(mTable) do
        if "EXPANSION1_ID" == tag then
            return true
        end
    end
    return false
end

function p.setClusters(cDatas, clusters, hideSkip)
    for _, cData in pairs(cDatas) do
        if not p.isForbidden(cData.forbiddenDlcIds) then
            if not hideSkip or cData.skip == nil then
                local cate = cData.clusterCategory 
                cate = CATS_ORDER[cate] or cate or 4
                if clusters[cate] == nil then
                    clusters[cate] = {}
                end
                table.insert(clusters[cate], cData)
            end
        end
    end
end

function p._main(hideSkip, dlc)
    local out = {"<span>星群{{眼冒金星图标}}</span>"}
    out.collapse = "no"

    -- 星群
    local cateClusters = {}
    p.setClusters(clustersDLC1, cateClusters, hideSkip)
    p.setClusters(clustersDLC2, cateClusters, hideSkip)

    -- 装载项目    
    for cate, clustersDatas in ipairs(cateClusters) do
        if clustersDatas ~= nil then
            local cateName = cate
            if CLUSTER_CATEGORY_NAME[cate] ~= nil then
                cateName = po(CLUSTER_CATEGORY_NAME[cate])
            else
                cateName = CLUSTER_CATEGORY_NAME_2[cate] or cate
            end
            table.insert(out, cateName)
            table.sort(clustersDatas, function(a, b)
                return a.menuOrder < b.menuOrder
            end)
            table.insert(out, table.concat(utils.map(clustersDatas, function(cData)
                local name = po(cData.name)
                return fstr("{{物品|%s}}", name)
            end), " ! "))
        end
    end

    return out
end

-- test by: = p.main(require("Module:debug").frame({},{debug=1}))
-- test by: = p.main(require("Module:debug").frame({hideSkip=true},{debug=1}))
function p.main(frame)
    local args = getArgs(frame)
    local out = p._main(args.hideSkip)
    if args.debug then
        mw.logObject(args.hideSkip)
        mw.logObject(out)
    end
    return navbox.main(out)
end

return p