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

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

全站通知:

模块:表格/太空地点

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

此模块的文档可以在模块:表格/太空地点/doc创建

-- Module:表格/太空地点
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local getArgs = require('Module:Dev/Arguments').getArgs
local tb = require([[Module:表格]])
local po = require([[Module:Po]]).po
local utils = require([[Module:Utils]])
local poiData = mw.loadData([[Module:Data/SpaceDestinationTypes]])

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

    -- 名称
    local name = po(itemData.Name)
    table.insert(out, fstr("[[File:%s.png|80px]]", name))
    table.insert(out, fstr("%s", name))
    -- 描述
    local descCode = itemData.Name:sub(1, -6) .. ".DESCRIPTION"
    local desc = po(descCode)
    if not utils.isDefaultT(descCode, desc) then
        table.insert(out, desc)
    else
        table.insert(out, "")
    end
    -- 大小
    table.insert(out, tostring(itemData.iconSize))
    -- 恢复速率
    table.insert(out, fstr('<abbr title = "%s">%s</abbr>',
        fstr("完全补充:%s 周期", utils.float2str((itemData.maxiumMass - itemData.minimumMass)/itemData.replishmentPerCycle)),
        utils.float2str(itemData.replishmentPerCycle, 2)
    ))
    -- 矿物资源
    if itemData.elementTable ~= nil then
        -- 计算总的最小值和最大值
        local totalMin = 0
        local totalMax = 0
        for eId, element in pairs(itemData.elementTable) do
            totalMin = totalMin + element.min
            totalMax = totalMax + element.max
        end

        -- 计算每个项的最小占比和最大占比
        local proportions = {}
        for eId, element in pairs(itemData.elementTable) do
            local elementName = utils.getEntry(eId)
            local avgProportion = element.min / totalMin
            local minProportion = element.min / (totalMax - element.max + element.min)
            local maxProportion = element.max / (totalMin - element.min + element.max)
            table.insert(proportions,fstr('{{*}} <abbr title = "%s%%~%s%%">≈%s%%</abbr> {{物品|%s}}',
                utils.float2str(minProportion * 100, 2),
                utils.float2str(maxProportion * 100, 2),
                utils.float2str(avgProportion * 100, 2),
                elementName
            ))
        end
        table.insert(out, table.concat(proportions, "<br/>"))
    else
        table.insert(out, "")
    end
    -- 生物资源
    if itemData.recoverableEntities ~= nil then
        local critters = {}
        for critterId, num in pairs(itemData.recoverableEntities) do
            local critterName = utils.getEntry(critterId)
            table.insert(critters, fstr("%s {{物品|%s}}", tostring(num), critterName))
        end
        table.insert(out, table.concat(critters, "<br/>"))
    else
        table.insert(out, "")
    end
    -- 艺术品
    local artifactDropTable = itemData.artifactDropTable
    if artifactDropTable ~= nil and artifactDropTable.Disabled ~= true then
        local artifacts = {}
        for i, rate in ipairs(artifactDropTable.rates) do
            local nameCode = rate.first.name_key.String
            if nameCode ~= nil then
                table.insert(artifacts, fstr("%s:%s%%",
                    po(nameCode),
                    utils.float2str(rate.second/artifactDropTable.totalWeight*100, 2)
                ))
            end
        end
        table.insert(out, table.concat(artifacts, "<br/>"))
    else
        table.insert(out, "")
    end

    return out
end

-- test by: = p.main(require("Module:debug").frame({},{debug=1}))
function p.main(frame)
    local args = getArgs(frame)
    local infos = {}
    for k, v in pairs(poiData) do
        local info = p._main(v)
        table.insert(infos, info)
    end

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

    return tb.table(infos, args)
end

return p