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

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

全站通知:

模块:病菌信息框

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

用于模板:Template:病菌信息框。 视图模块:Module:信息框/病菌。 数据模块:Module:Data/Diseases



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

local utils = require("Module:Utils")
local k0 = utils.K0
local po = require([[Module:Po]]).po
local i18ncr = require([[Module:I18n]]).loadMessages([[Module:I18n/Duplicants]])
local infobox = require([[Module:信息框/病菌]])
local getArgs = require("Module:Dev/Arguments").getArgs
local fDataPath = [[Module:Data/Diseases]]
local fData = mw.loadData(fDataPath)
local exception = {
}


function p.getTempetureStr(value)
    if value == nil then
        return nil
    elseif value == "Infinity"then
        return value
    else
        return utils.float2str(value + k0) .. " °C"
    end
end

function p.getHalfLives(value)
    if value == nil then
        return nil
    elseif value == "Infinity" then
        return value
    else
        return utils.float2str(value)
    end
end

function p.getRuleElement(rules)
    local elems = {}
    for _, rule in ipairs(rules) do
        if rule.element ~= nil then
            table.insert(elems, fstr("{{物品|%s}}", utils.getEntry(rule.element)));
        elseif rule.tag ~= nil then
            table.insert(elems, fstr("[[%s]]", po("STRINGS.MISC.TAGS."..rule.tag:upper())))
        elseif rule.state ~= nil then
            table.insert(elems, fstr("[[%s]]", po("STRINGS.MISC.TAGS."..rule.state:upper())))
        end
    end
    elems = #elems ~= 0 and table.concat(elems, "<br/>") or nil
    return elems
end

function p._main(diesData, diesCode, args)
    local out = {}
    out["ID"] = fstr("<code>%s</code>", diesData.Id)
    out["名称"] = po(diesCode)
    out["图片"] = args.img or fstr("%s.png", out["名称"])
    out["图片说明"] = po(diesCode:sub(1, -6) .. ".DESC")
    if diesData.radiationKillRate ~= nil then
    	out["辐射杀菌系数"] = utils.float2str(diesData.radiationKillRate)
    end
    if diesData.temperatureRange ~= nil then
        local range = diesData.temperatureRange
    	out["存活温度下限"] = p.getTempetureStr(range.minViable)
    	out["存活温度上限"] = p.getTempetureStr(range.maxViable)
    	out["繁殖温度下限"] = p.getTempetureStr(range.minGrowth)
    	out["繁殖温度上限"] = p.getTempetureStr(range.maxGrowth)
    end
    if diesData.temperatureHalfLives ~= nil then
        local range = diesData.temperatureHalfLives
    	out["存活温度半衰期下限"] = p.getHalfLives(range.minViable)
    	out["存活温度半衰期上限"] = p.getHalfLives(range.maxViable)
    	out["繁殖温度半衰期下限"] = p.getHalfLives(range.minGrowth)
    	out["繁殖温度半衰期上限"] = p.getHalfLives(range.maxGrowth)
    end
    if diesData.exposureType ~= nil then
        local eType = diesData.exposureType
        if eType.sickness_id ~= nil then
            out['感染疾病'] = fstr("[[%s]]", po('STRINGS.DUPLICANTS.DISEASES.'..eType.sickness_id:upper()..".NAME"))
        end
        if eType.infect_immediately ~= nil then
            out['立刻染病'] = eType.infect_immediately == true and "✔" or "✖"
        end
        if eType.exposure_threshold ~= nil then
            out['暴露阈值'] = fstr("%s", utils.float2str(eType.exposure_threshold))
        end
        out['抗菌特质'] = {}
        if eType.excluded_traits ~= nil then
            for _, trait in ipairs(eType.excluded_traits) do
                table.insert(out['抗菌特质'], fstr(
                    "[[%s|%s]]",
                    "复制人/特质",
                    po("STRINGS.DUPLICANTS.TRAITS."..trait:upper()..".NAME"))
                )
            end
        end
        out['抗菌特质'] = #out["抗菌特质"] ~= 0 and table.concat(out["抗菌特质"], "<br/>") or nil
        out['抗菌效果'] = {}
        if eType.excluded_effects ~= nil then
            for _, effect in ipairs(eType.excluded_effects) do
                table.insert(out['抗菌效果'], fstr(
                    "[[%s|%s]]",
                    "复制人/特质",
                    po("STRINGS.DUPLICANTS.MODIFIERS."..effect:upper()..".NAME"))
                )
            end
        end
        out['抗菌效果'] = #out["抗菌效果"] ~= 0 and table.concat(out["抗菌效果"], "<br/>") or nil
    end
    if diesData.ruleGrowsOn ~= nil then
        local elems = p.getRuleElement(diesData.ruleGrowsOn)
        if elems ~= nil then
            out['繁殖于'] = elems
        end
    end
    if diesData.ruleNeutralOn ~= nil then
        local elems = p.getRuleElement(diesData.ruleNeutralOn)
        if elems ~= nil then
            out['存活于'] = elems
        end
    end
    if diesData.ruleDiesSlowlyOn ~= nil then
        local elems = p.getRuleElement(diesData.ruleDiesSlowlyOn)
        if elems ~= nil then
            out['抑菌物'] = elems
        end
    end
    if diesData.ruleDiesOn ~= nil then
        local elems = p.getRuleElement(diesData.ruleDiesOn)
        if elems ~= nil then
            out['抗菌物'] = elems
        end
    end
    if diesData.ruleDiesQuicklyOn ~= nil then
        local elems = p.getRuleElement(diesData.ruleDiesQuicklyOn)
        if elems ~= nil then
            out['灭菌物'] = elems
        end
    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="放射性污染物"}))
function p.main(frame)
    local args = getArgs(frame)
    local infos = {}
    local diseases = {}

    if args[1] ~= nil then
        for _, diseaseId in ipairs(args) do
            local _, _, diesCode = utils.getEntry(diseaseId)
            if diesCode == nil then
                return {
                    ["名称"] = fstr("找不到病菌 '%s',请使用参数1或检查 [[%s]]。", diseaseId, fDataPath)
                }
            end
            table.insert(diseases, {
                id = diseaseId,
                code = diesCode
            })
        end
    else
        local diesCode = i18ncr:msgRev({
            key = args.pagename,
            args = {
                prefix = "STRINGS.DUPLICANTS.DISEASES."
            }
        } or "")
        if diesCode == nil then
            return {
                ["名称"] = fstr("找不到病菌 '%s',请使用参数1或检查 [[%s]]。", args.pagename,
                    fDataPath)
            }
        end
        local diseaseId = diesCode:match("([%u_]+).NAME$")
        table.insert(diseases, {
            id = diseaseId,
            code = diesCode
        })
    end

    for _, disease in pairs(diseases) do
        disease.id = exception[disease.id] ~= nil and exception[disease.id] or disease.id
        for k, v in pairs(fData) do
            if k:upper() == disease.id:upper() then
                local curr = p._main(v, disease.code, args)
                table.insert(infos, {
                    label = curr["名称"],
                    data = curr
                })
            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