缺氧 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 worldsDataBASE = mw.loadData([[Module:Data/Worldgen/Worlds]])
local worldsDataDLC1 = mw.loadData([[Module:Data/Worldgen/Worlds/Expansion1]])
local worldsDataDLC2 = mw.loadData([[Module:Data/Worldgen/Worlds/Dlc2]])

local DLC_NAMES = {
    [""] = "游戏本体",
    ["EXPANSION1_ID"] = "[[眼冒金星!]]"
}

local worlds = {
    [""] = {},
    ["EXPANSION1_ID"] = {}
}
local usedWorlds = {}

function p.getCate(cData)
    if cData.forbiddenDlcIds ~= nil then
        for _, dlc in ipairs(cData.forbiddenDlcIds) do
            if dlc == "EXPANSION1_ID" then
                return ""
            end
        end
    end
    if cData.requiredDlcIds ~= nil then
        for _, dlc in ipairs(cData.requiredDlcIds) do
            if dlc == "EXPANSION1_ID" then
                return "EXPANSION1_ID"
            end
        end
    end
    return ""
end

function p.setWorld(cData)
    if cData.worldPlacements == nil then
        return
    end
    local dlc = p.getCate(cData)
    for _, world in ipairs(cData.worldPlacements) do
        local worldsData = nil
        if utils.startswith(world.world, "expansion1::") then
            worldsData = worldsDataDLC1
        elseif utils.startswith(world.world, "dlc2::") then
            worldsData = worldsDataDLC2
        else
            worldsData = worldsDataBASE
        end
        if worldsData ~= nil and dlc ~= nil then
            local worldId = mw.ustring.match(world.world, "worlds/(.+)$")
            local wData = worldsData[worldId .. ".yaml"]
            local nameCode = wData.name
            if usedWorlds[nameCode] == nil then
                usedWorlds[nameCode] = true
                table.insert(worlds[dlc], {
                    name = nameCode,
                    menuOrder = cData.menuOrder
                })
            end
        end
    end
end

function p._main(hideSkip)
    local out = {"<span>小行星</span>"}
    out.collapse = "no"
    for _, cData in pairs(clustersBASE) do
        if not hideSkip or cData.skip == nil then
            p.setWorld(cData)
        end
    end
    for _, cData in pairs(clustersDLC1) do
        if not hideSkip or cData.skip == nil then
            p.setWorld(cData)
        end
    end
    for _, cData in pairs(clustersDLC2) do
        if not hideSkip or cData.skip == nil then
            p.setWorld(cData)
        end
    end

    -- 装载项目
    for dlc, worldInfos in pairs(worlds) do
        table.sort(worldInfos, function(a, b)
            return a.menuOrder < b.menuOrder
        end)
        table.insert(out, DLC_NAMES[dlc])
        table.insert(out, table.concat(utils.map(worldInfos, function(info)
            local name = po(info.name)
            return fstr("{{物品|%s}}", name)
        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