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

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

全站通知:

模块:疾病信息框

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

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



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

local utils = require("Module:Utils")
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/Sicknesses]]
local fData = mw.loadData(fDataPath)
local exception = {
}
local INFECTION_VECTORS = {
    Contact = "STRINGS.DUPLICANTS.DISEASES.DESCRIPTORS.INFO.SKINBORNE",
    Digestion = "STRINGS.DUPLICANTS.DISEASES.DESCRIPTORS.INFO.FOODBORNE",
    Inhalation = "STRINGS.DUPLICANTS.DISEASES.DESCRIPTORS.INFO.AIRBORNE",
    Exposure = "STRINGS.DUPLICANTS.DISEASES.DESCRIPTORS.INFO.SUNBORNE"
}


function p._main(sickData, sickCode, args)
    local out = {}
    out["ID"] = fstr("<code>%s</code>", sickData.Id)
    out["名称"] = po(sickCode)
    out["图片"] = args.img or fstr("%s.png", out["名称"])
    out["图片说明"] = po(sickData.descSymptoms)

    if sickData.sicknessType ~= nil then
    	out["疾病类型"] = po("STRINGS.DUPLICANTS.DISEASES.TYPE."..sickData.sicknessType:upper())
    end
    if sickData.SicknessDuration ~= nil then
    	out["持续时间"] = fstr("%s [[周期]]", utils.float2str(sickData.SicknessDuration/600))
    end
    if sickData.severity ~= nil then
    	out["严重性"] = po("STRINGS.DUPLICANTS.DISEASES.SEVERITY."..sickData.severity:upper())
    end
    if sickData.recoveryEffect ~= nil then
    	out["恢复效果"] = po("STRINGS.DUPLICANTS.MODIFIERS."..sickData.recoveryEffect:upper()..".NAME")
    end
    if sickData.germId ~= nil then
    	out["致病病菌"] = po("STRINGS.DUPLICANTS.DISEASES."..sickData.germId:upper()..".NAME")
    end
    if sickData.infectionVectors ~= nil then
        out["感染媒介"] = {}
        for _, vector in ipairs(sickData.infectionVectors) do
            local vectorCode = INFECTION_VECTORS[vector]
            if vectorCode ~= nil then
                local vectorName = po(vectorCode):gsub("\n------------------", "")
                table.insert(out["感染媒介"], vectorName)
            end
        end
        out['感染媒介'] = #out["感染媒介"] ~= 0 and table.concat(out["感染媒介"], "<br/>") or nil
    end
    if sickData.symptoms ~= nil then
        out["病症"] = {}
        for _, symptom in ipairs(sickData.symptoms) do
            table.insert(out["病症"], symptom)
        end
        out['病症'] = #out["病症"] ~= 0 and table.concat(out["病症"], "<br/>") or nil
    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 Sicknesses = {}

    if args[1] ~= nil or args.multipage ~= nil then
        local pagename_array = {}
        pagename_array = args[1] ~= nil and {args[1]} or nil
        if pagename_array == nil then
            pagename_array = args.multipage ~= nil and mw.text.split(args.multipage, ",") or {}
        end
        for _, sicknessId in ipairs(pagename_array) do
            local _, _, sickCode = utils.getEntry(sicknessId)
            if sickCode == nil then
                error(fstr("找不到疾病 '%s',请使用参数1或检查 [[%s]]。", args.pagename,fDataPath))
            end
            table.insert(Sicknesses, {
                id = sicknessId,
                code = sickCode
            })
        end
    else
        local sickCode = i18ncr:msgRev({
            key = args.pagename,
            args = {
                prefix = "STRINGS.DUPLICANTS.DISEASES."
            }
        } or "")
        if sickCode == nil then
            error(fstr("找不到疾病 '%s',请使用参数1或检查 [[%s]]。", args.pagename,fDataPath))
        end
        local sicknessId = sickCode:gsub("^STRINGS%.DUPLICANTS%.DISEASES%.", "")
        sicknessId = sicknessId:gsub(".NAME", "")
        table.insert(Sicknesses, {
            id = sicknessId,
            code = sickCode
        })
    end

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

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

return p