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

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

全站通知:

模块:装备信息框

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

用于模板:Template:装备信息框。 视图模块:Module:信息框/装备。 数据模块:Module:Data/Equipments



local p = {}
local fstr = mw.ustring.format

local utils = require("Module:Utils")
local k0 = utils.K0
local po = require([[Module:Po]]).po
local i18neq = require([[Module:I18n]]).loadMessages([[Module:I18n/Equipment]])
local infobox = require([[Module:信息框/装备]])
local getArgs = require("Module:Dev/Arguments").getArgs
local fDataPath = [[Module:Data/Equipments]]
local fData = mw.loadData(fDataPath)
local exception = {
}


function p.getWornData(itemData, itemCode)
    for k, v in pairs(fData) do
        if k:upper() == itemData.wornId:upper() then
            local wornCode = itemCode:gsub(".NAME", ".WORN_NAME")
            return p._main(v, wornCode)
        end
    end
    return nil
end

function p._main(itemData, itemCode)
    local out = {}
    out["ID"] = fstr("<code>%s</code>", itemData.id)
    out["名称"] = po(itemCode)
    out["图片"] = fstr("%s.png", out["名称"])
    if itemData.isWorn == true then
        out["图片说明"] = po(itemCode:sub(1, -11) .. ".WORN_DESC")
    else
        out["图片说明"] = po(itemCode:sub(1, -6) .. ".DESC")
    end
    if itemData.slot ~= nil then
        out['装备分类'] = po("STRINGS.MISC.TAGS."..itemData.slot:upper())
    end
    if itemData.leadSuitTank ~= nil then
        out["电池续航时间"] = fstr("%s 秒", utils.float2str(itemData.leadSuitTank.batteryDuration))
    end
    if itemData.kBoxCollider2D ~= nil then
        out["宽度"] = itemData.kBoxCollider2D.x
        out["高度"] = itemData.kBoxCollider2D.y
    end
    if itemData.suitTank ~= nil then
        out['存储元素'] = fstr("{{物品|%s}}", utils.getEntry(itemData.suitTank.element))
        out["存储容量"] = fstr("%s 千克", itemData.suitTank.capacity)
        out["存储二氧化碳"] = itemData.suitTank.ShouldStoreCO2 == true and '✔' or '✖'
    end
    if itemData.onEquipEffect ~= nil then
        out['装饰加成'] = fstr("+%s", utils.float2str(itemData.onEquipEffect.decorMod))
        out["隔热厚度"] = fstr("%s cm", utils.float2str(itemData.onEquipEffect.conductivityMod * 100))
        out["体内平衡效率乘数"] = utils.float2str(itemData.onEquipEffect.homeostasisEfficiencyMultiplier)
    end
    if itemData.attribute ~= nil then
        out['效果'] = {}
        for _, attribute in ipairs(itemData.attribute) do
            local effectName = po("STRINGS.DUPLICANTS.ATTRIBUTES."..attribute.AttributeId:upper()..".NAME")
            local charPlus = attribute.IsMultiplier == true and "x" or "+"
            local effect = fstr("%s %s%s", effectName, (attribute.Value > 0 and charPlus or ""), utils.float2str(attribute.Value))
            table.insert(out['效果'], effect)
        end
        out["效果"] = #out["效果"] ~= 0 and table.concat(out["效果"], "<br/>") or nil
    end
    if itemData.effectImmunites ~= nil then
        out['免疫效果'] = {}
        for _, attribute in ipairs(itemData.effectImmunites) do
            local effectName = po("STRINGS.DUPLICANTS.MODIFIERS."..attribute.Id:upper()..".NAME")
            table.insert(out['免疫效果'], effectName)
        end
        out["免疫效果"] = #out["免疫效果"] ~= 0 and table.concat(out["免疫效果"], "<br/>") or nil
    end
    if itemData.primaryElement ~= nil then
        out["元素"] = fstr("{{物品|%s}}", utils.getEntry(itemData.primaryElement.Name))
        out["质量"] = utils.kg2str(itemData.primaryElement.Mass)
        out["初始温度"] = utils.float2str(itemData.primaryElement.InternalTemperature + k0) .. " °C"
    end
    return out
end

-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="太空服"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="冰爽背心"}))
-- test by: = p.main(require("Module:debug").frame({},{debug=1, pagename="睡衣"}))

function p.main(frame)
    local args = getArgs(frame)
    local infos = {}
    local equips = {}

    if args[1] ~= nil then
        for _, equipId in ipairs(args) do
            local _, _, equipCode = utils.getEntry(equipId)
            if equipCode == nil then
                return {
                    ["名称"] = fstr("找不到装备 '%s',请使用参数1或检查 [[%s]]。", equipId, fDataPath)
                }
            end
            table.insert(equips, {
                id = equipId,
                code = equipCode
            })
        end
    else
        local defalutCode = mw.text.nowiki('<' .. args.pagename .. '>')
        local equipCode = i18neq:msgRev({
            key = args.pagename,
            args = {
                prefix = "STRINGS.EQUIPMENT.PREFABS."
            }
        } or "")
        if equipCode == nil or equipCode == defalutCode then
            return {
                ["名称"] = fstr("找不到装备 '%s',请使用参数1或检查 [[%s]]。", args.pagename,
                    fDataPath)
            }
        end
        local equipId = equipCode:gsub("^STRINGS%.EQUIPMENT%.PREFABS%.", "")
        equipId = equipId:gsub(".NAME", "")
        equipId = equipId:gsub(".WORN_NAME", "")
        table.insert(equips, {
            id = equipId,
            code = equipCode
        })
    end

    for _, equip in ipairs(equips) do
        equip.id = exception[equip.id] ~= nil and exception[equip.id] or equip.id
        for k, v in pairs(fData) do
            if k:upper() == equip.id:upper() then
                local curr = p._main(v, equip.code)
                table.insert(infos, {
                    label = curr["名称"],
                    data = curr
                })
                if v.wornId ~= nil then
                    local wornCurr = p.getWornData(v, equip.code)
                    if wornCurr ~= nil then
                        table.insert(infos, {
                            label = wornCurr['名称'],
                            data = wornCurr
                        })
                    end
                end
            end
        end
    end

    if args.debug then
        mw.logObject(infos)
    end
    local infoboxTitle = #infos == 1 and infos[1].label or args.pagename
    return infobox.main(infoboxTitle, infos)
end

return p