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

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

全站通知:

模块:图库/星群

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

此模块的文档可以在模块:图库/星群/doc创建

-- Module:图库/星群
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local gallerybox = require([[Module:图库]])
local utils = require([[Module:Utils]])
local po = require([[Module:Po]]).po
local yesno = require([[Module:Dev/Yesno]])
local getArgs = require('Module:Dev/Arguments').getArgs
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 function contains(t, e)
    if t == nil then
        return false
    end
    for _, i in ipairs(t) do
        if i == e then
            return true
        end
    end
    return false
end

-- test by: = p.main(require("Module:debug").frame({},{debug=1, cat="Vanilla", base=1}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, cat="Special", base=1}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, cat="SpacedOutVanillaStyle"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, cat="SpacedOutStyle"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, cat="Special"}))
function p.main(frame)
    local sections = {}
    local args = getArgs(frame)
    local csList = {clustersBASE, clustersDLC1, clustersDLC2}

    local infos = {}
    for _, cs in ipairs(csList) do
        for _, cData in pairs(cs) do
            if cData.skip ~= nil then
                -- do nothing
            elseif (args.cat == nil or cData.clusterCategory == args.cat) then
                if yesno(args.base) == true then
                    if cData.requiredDlcIds == nil or not contains(cData.requiredDlcIds, "EXPANSION1_ID") then
                        -- 不需要DLC1
                        table.insert(infos, cData)
                    end
                else
                    local useDLC1 = true
                    if cData.forbiddenDlcIds ~= nil and contains(cData.forbiddenDlcIds, "EXPANSION1_ID") then
                        -- 被禁止
                        useDLC1 = false                        
                    end
                    if cData.requiredDlcIds ~= nil and contains(cData.requiredDlcIds, "EXPANSION1_ID") then
                        -- 被需要
                        useDLC1 = true
                    end
                    if useDLC1 then
                        table.insert(infos, cData)
                    end
                end
            end
        end
    end
    table.sort(infos, function(a, b)
        return a.menuOrder < b.menuOrder
    end)

    local gallerys = utils.map(infos, function(cData)
        local name = po(cData.name)
        local desc = po(cData.description)
        return {
            name = name,
            desc = fstr("[[%s]]是%s", name, desc)
        }
    end)

    local out = gallerybox.gallery(gallerys, args.params and "" or "widths=200px")

    if args.debug then
        mw.logObject(out, "out")
    end

    return mw.getCurrentFrame():preprocess(out)
end

return p