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

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

全站通知:

模块:元素导航

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string

local i18ndt = require([[Module:I18n]]).loadMessages([[Module:I18n/Misc]])
local i18nde = require([[Module:I18n]]).loadMessages([[Module:I18n/Elements]])
local _t = function(...) return i18ndt:msg(...) end
local _e = function(...) return i18nde:msg(...) end
local getArgs = require("Module:Dev/Arguments").getArgs
local json = require("Module:Dev/Json")
local nav = require("Module:导航栏")
local buData = mw.loadData([[Module:Data/Buildings]])
local elData = mw.loadData([[Module:Data/Elements]])

-- those are pages that can not be mapped correctly
local pageMatch = {
	StableSnow = "紧压雪",
}

function tagCode(t) return "STRINGS.MISC.TAGS." .. t:upper() end

function cateLink(s) return fstr("[[:category:%s|%s]]", s, s) end

function isDefaultMsg(s, t) return ("<" .. s .. ">") == t end

function p._main(args)
    local out = {}

    out.title = "[[元素]]"
    out.template = args.pagename
    template = args.pagename

    local stateData = {
        Solid = {},
        Liquid = {},
        Gas = {},
        Vacuum = {}
    }
    for k, v in pairs(elData) do
        table.insert(stateData[v.state], v)
    end

    local cateCount = 1
    for _, state in ipairs({"Solid", "Liquid", "Gas", "Vacuum"}) do
        local stateCode = state == "Vacuum" and "Special" or state
        out[fstr("header%d", cateCount)] = fstr("[[%s]]", _t(tagCode(stateCode)))
        local cates = {}
        for _, e in ipairs(stateData[state]) do
            repeat -- simulate continue inside for loop
                local currCate = e.materialCategory
                if e.isDisabled then
                    if not args.showDisabled then
                        do break end -- continue for loop
                    end
                    currCate = "~~"
                elseif currCate == nil then
                    currCate = "~"
                end
                local eleName = _e(e.localizationID)
                if pageMatch[e.elementId] then
                    eleName = pageMatch[e.elementId]
                end
                if isDefaultMsg(e.localizationID, eleName) then
                    eleName = e.elementId
                end
                if cates[currCate] then
                    table.insert(cates[currCate], eleName)
                else
                    cates[currCate] = {eleName}
                end
            until true
        end

        cateIds = {}
        for k, _ in pairs(cates) do table.insert(cateIds, k) end
        table.sort(cateIds)
        for _, cate in ipairs(cateIds) do
            if cate == "~" then
                if state == "Liquid" then
                    out[fstr("group%d", cateCount)] = "液体"
                else
                    out[fstr("group%d", cateCount)] = "无分类"
                end
            elseif cate == "~~" then
                out[fstr("group%d", cateCount)] = "未实装"
            else
                out[fstr("group%d", cateCount)] = cateLink(_t(tagCode(cate)))
            end
            local es = cates[cate]
            table.sort(es)
            local listContent = {}
            for _, e in ipairs(es) do
                if e == "复合物" then --复合物无图标,不必显示
                    table.insert(listContent, fstr("[[%s]]", e))
                else
                    table.insert(listContent, mw.getCurrentFrame():expandTemplate{
                        title = "物品",
                        args = {e}
                    })
                end
            end
            out[fstr("list%d", cateCount)] =
                table.concat(listContent, " • ")
            cateCount = cateCount + 1
        end
    end
    return nav.main(out)
end
-- test by: = p._main({pagename = "testPageName"})
-- test by: = p._main({pagename = "testPageName", showDisabled=true})
function p.main(frame) return p._main(getArgs(frame)) end
return p