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

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

全站通知:

模块:物品信息框

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

用于模板:Template:物品信息框。 视图模块:Module:信息框/物品。 数据模块:Module:Data/Items



local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string

local utils = require("Module:Utils")
local po = require([[Module:Po]]).po
local i18ncr = require([[Module:I18n]]).loadMessages([[Module:I18n/Creatures]])
local i18nitem = require([[Module:I18n]]).loadMessages([[Module:I18n/Items]])
local infobox = require([[Module:信息框/物品]])
local getArgs = require('Module:Dev/Arguments').getArgs
local iDataPath = [[Module:Data/Items]]
local iData = mw.loadData(iDataPath)
local k0 = utils.K0
local arrow = '➤'
local exception = {}


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

    out["名称"] = args.pagename
    out["图片"] = args.img or fstr("%s.png", args.pagename)
    if args.desc ~= nil then
        out["图片说明"] = po(args.desc)
    end
    if args.sources ~= nil then
    	out["获取来源"] = fstr("{{物品|%s}}", args.sources)
    end
    out["效果"] = args.effects or nil

    return out
end

function p._main(itemData, itemCode, args)
    local out = {}
    out["ID"] = fstr("<code>%s</code>", itemData.id)
    out["名称"] = po(itemCode)
    out["图片"] = args.img or fstr("%s.png", out["名称"])
    if args.desc ~= nil then
        out["图片说明"] = po(args.desc)
    elseif itemData.tagFilter == "Egg" then
        out["图片说明"] = po("STRINGS.ITEMS.FOOD."..itemData.id:upper()..".DESC")
    else
        out["图片说明"] = po(itemCode:sub(1, -6) .. ".DESC")
    end
    if itemData.tagFilter ~= nil then
        out['物品分类'] = po("STRINGS.MISC.TAGS."..itemData.tagFilter:upper())
    end
    if itemData.kBoxCollider2D ~= nil then
        out["宽度"] = itemData.kBoxCollider2D.x
        out["高度"] = itemData.kBoxCollider2D.y
    end
    if itemData.recipes ~= nil then
        local function reprRecipe(recipe)
            -- 消耗
            local consumes = {}
            if recipe.ingredients ~= nil then
                for _, ingredient in ipairs(recipe.ingredients) do
                    local name = utils.getEntry(ingredient)
                    if name then
                        table.insert(consumes, fstr("{{物品|%s|notext=1}}", name))
                    end
                end
            end
            local consume = '无'
            if #consumes > 0 then
                consume = table.concat(consumes, " ")
            end
            -- 生产
            local produces = {}
            if recipe.results ~= nil then
                for _, result in ipairs(recipe.results) do
                    local name = utils.getEntry(result)
                    if name then
                        table.insert(produces, fstr("{{物品|%s|notext=1}}", name))
                    end
                end
            end
            local produce = '无'
            if #produces > 0 then
                produce = table.concat(produces, " ")
            end
            -- 制作台
            local fabricator = nil
            if recipe.fabricator ~= nil then
                local fabricatorName = utils.getEntry(recipe.fabricator)
                if fabricatorName then
                    fabricator = fstr("{{物品|%s|notext=1}}", fabricatorName)
                end
            end
            fabricator = fabricator or '无'
            return fstr('<div>%s</div>' ..
                '<div style="text-align: left">%s</div>' ..
                '<div>%s</div>'..
                '<div style="text-align: left">%s</div>' ..
                '<div>%s</div>',
                consume, arrow, fabricator , arrow, produce)
        end
        out['配方'] = table.concat(utils.map(itemData.recipes, reprRecipe), "\n")
    end
    out["获取来源"] = {}
    if args.sources ~= nil then
        for _, source in ipairs(args.sources) do
            local fabricator = fstr("{{物品|%s}}", utils.getEntry(source))
            table.insert(out["获取来源"], fabricator)
        end
    end
    if itemData.sources ~= nil then
        for _, source in ipairs(itemData.sources) do
            local sourceName = utils.getEntry(source)
            if sourceName ~= nil then
                local fabricator = fstr("{{物品|%s}}", sourceName)
                table.insert(out["获取来源"], fabricator)
            end
        end
    end
    out["获取来源"] = #out["获取来源"] ~= 0 and table.concat(out["获取来源"], "<br/>") or nil
    if itemData.medicineInfo ~= nil then
        out['药物类型'] = tostring(itemData.medicineInfo.medicineType)
        out["治愈疾病"] = {}
        local curedSicknesses = itemData.medicineInfo.curedSicknesses
        if curedSicknesses ~= nil then
            for _, curedSickness in ipairs(curedSicknesses) do
                local cured = po("STRINGS.DUPLICANTS.DISEASES."..curedSickness:upper()..".NAME")
                table.insert(out["治愈疾病"], cured)
            end
        end
        out["治愈疾病"] = #out["治愈疾病"] ~= 0 and table.concat(out["治愈疾病"], "<br/>") or nil
        out['效果'] = itemData.medicineInfo.effect ~= nil and po("STRINGS.DUPLICANTS.MODIFIERS."..itemData.medicineInfo.effect:upper()..".TOOLTIP") 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

function p.getItemCode(pagename)
    local defalutCode = mw.text.nowiki('<' .. pagename .. '>')
    local itemCode = i18ncr:msgRev({
        key = pagename,
        args = {
            prefix = "STRINGS.CREATURES.SPECIES.SEEDS."
        }
    } or "")
    if itemCode == nil or itemCode == defalutCode then
        itemCode = i18ncr:msgRev({
            key = pagename,
            args = {
                prefix = "STRINGS.CREATURES.SPECIES."
            }
        } or "")
    end
    if itemCode == nil or itemCode == defalutCode then
        itemCode = i18nitem:msgRev({
            key = pagename,
            args = {
                prefix = "STRINGS.ITEMS.INDUSTRIAL_PRODUCTS."
            }
        } or "")
    end
    if itemCode == nil or itemCode == defalutCode then
        itemCode = i18nitem:msgRev({
            key = pagename,
            args = {
                prefix = "STRINGS.ITEMS."
            }
        } or "")
    end
    if itemCode == nil or itemCode == defalutCode then
        local _, _, mItemCode = utils.getEntry(pagename)
        itemCode = mItemCode
    end
    if itemCode == nil or itemCode == defalutCode then
        return nil
    end
    return itemCode
end

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

    if args.multipage then
        local pagename_array = mw.text.split(args.multipage, ",")
        for _, pagename in ipairs(pagename_array) do
            local itemCode = p.getItemCode(pagename)
            if itemCode ~= nil then
                table.insert(itemCodes, itemCode)
            end
        end
    else
        local itemCode = p.getItemCode(args)
        table.insert(itemCodes, itemCode)
    end

    for _, itemCode in pairs(itemCodes) do
        for k, v in pairs(iData) do
            if v.msgctxt == itemCode then
                local curr = p._main(v, itemCode, args)
                table.insert(infos, {
                    label = curr["名称"],
                    data = curr
                })
            end
        end
    end
    if #infos == 0 then
        local curr = p.getInfo(args)
        table.insert(infos, {
            label = curr["名称"],
            data = curr
        })
    end

    local infoboxTitle = #infos > 1 and args.pagename or infos[1].label
    return infobox.main(infoboxTitle, infos)
end
return p