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

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

全站通知:

模块:信息框/植物

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

用于模块:Module:植物信息框



local infobox = require([[Module:信息框]])
local fstr = mw.ustring.format
local utils = require("Module:Utils")
local p = {}

local innerNodes = {
    {
        tag = 'image',
        source = '图片',
        children = {
            {
                tag = 'caption',
                source = '图片说明'
            }
        }
    },
    {
        tag = 'data',
        source = 'ID',
        label = 'ID'
    },
    {
        tag = 'data',
        source = '尺寸',
        label = '尺寸'
    },
    {
        tag = 'data',
        source = '装饰',
        label = '[[装饰度|装饰]]'
    },
    {
        tag = 'data',
        source = '枯萎装饰',
        label = '<abbr title = "枯萎时不再提供装饰加成,且装饰度降低">枯萎惩罚</abbr>'
    },
    {
        tag = 'group',
        header = '生存',
        attr = {collapse = 'open'},
        children = {
            {
                tag = 'data',
                source = '气压',
                label = '<abbr title = "植物正常生长的气压区间">气压</abbr>'
            },
            {
                tag = 'data',
                source = '环境',
                label = '<abbr title = "植物正常生长所需环境">环境</abbr>'
            },
            {
                tag = 'data',
                source = '吸收元素需求',
                label = '<abbr title = "植物正常生长需要从环境吸收元素">吸收元素</abbr>'
            },
            {
                tag = 'data',
                source = '效果',
                label = '效果'
            },
            {
                tag = 'data',
                source = '存活温度',
                label = '<abbr title = "植物存活的温度区间">存活温度</abbr>'
            },
            {
                tag = 'data',
                source = '生长温度',
                label = '<abbr title = "植物正常生长的温度区间">生长温度</abbr>'
            },
            {
                tag = 'data',
                source = '光照',
                label = '[[照明|光照]]要求'
            },
            {
                tag = 'data',
                source = '辐射',
                label = '<abbr title = "眼冒金星 DLC 中该植物对辐射的耐受范围">[[辐射]]耐受范围</abbr>'
            },
            {
                tag = 'data',
                source = '淹没致死',
                label = '淹没致死'
            },
        }
    },
    {
        tag = 'group',
        header = '人工培育',
        attr = {collapse = 'open'},
        children = {
        	{
                tag = 'data',
                source = '灌溉',
                label = '灌溉'
            },
            {
                tag = 'data',
                source = '施肥',
                label = '施肥'
            },
            {
        		tag = 'data',
        		source = '种植容器',
        		label = nil
        	},
        },
    },
    {
        tag = 'group',
        header = '耕作',
        attr = {collapse = 'open'},
        children = {
            {
                tag = 'data',
                source = '生长周期',
                label = '<abbr title = "作物成熟所需时间">成熟时间</abbr>'
            },
            {
                tag = 'data',
                source = '收获',
                label = '收获产物'
            },
            {
                tag = 'data',
                source = '产出周期',
                label = '<abbr title = "产物产出所需时间">产出时间</abbr>'
            },
            {
                tag = 'data',
                source = '挂留时间',
                label = '<abbr title = "作物成熟后自行掉落收获物所需时间">挂留时间</abbr>'
            }
        }
    },
    {
        tag = 'group',
        header = '种子',
        attr = {collapse = 'open'},
        children = {
            {
                tag = 'data',
                source = '种子',
                label = '种子'
            },
            {
                tag = 'data',
                source = '种子说明',
                label = nil
            }
        }
    },
    {
        tag = 'group',
        header = '构成',
        attr = {collapse = 'closed'},
        children = {
            {
                tag = 'data',
                source = '元素',
                label = '主要元素'
            },
            {
                tag = 'data',
                source = '质量',
                label = '质量'
            },
            {
                tag = 'data',
                source = '初始温度',
                label = '初始温度'
            }
        }
    },
}

-- test: = p.infoboxContent{['装饰值'] = 5, ['装饰半径'] = 1}
function p.infoboxContent(args)
    if args['生长温度下限'] ~= nil and args['生长温度上限'] ~= nil then
        args['生长温度'] = fstr("%s°C ↔ %s°C ", tostring(args['生长温度下限']),
            tostring(args['生长温度上限']))
    end
    if args['存活温度下限'] ~= nil and args['存活温度上限'] ~= nil then
        args['存活温度'] = fstr("%s°C ↔ %s°C ", tostring(args['存活温度下限']),
            tostring(args['存活温度上限']))
    end

    args['生长周期'] = args['生长时间'] ~= nil and
                               fstr("<abbr title=\"培育生长 / 野外生长\">%s / %s 周期<abbr>",
            tostring(args['生长时间'] / 600), tostring(args['生长时间'] / 150)) or "无成长过程"
    args['产出周期'] = args['产出时间'] and fstr("<abbr title=\"培育/野外情况下物质产出所需时间\">%s / %s 周期<abbr>",
            tostring(args['产出时间'] / 600), tostring(args['产出时间'] / 150))
    args['挂留时间'] = args['挂留时间']~=nil and args['挂留时间']/600 .. " 周期" or nil

    args['环境'] = args['环境'] ~= nil and args['环境'] or "任意气体/液体环境"
    args['气压'] = args['气压下限'] ~= nil and args['气压上限'] ~= nil and
                         fstr("%s ↔ %s ", utils.kg2str(args['气压下限']), utils.kg2str(args['气压上限'])) or
                         "不限"

    args['辐射'] = args['辐射下限'] ~= nil and args['辐射上限'] ~= nil and args['辐射上限'] ~= 0 and
                         fstr("%s ↔ %s 拉德/周期", args['辐射下限'], args['辐射上限']) or
                         "不限"
    args['光照'] = args['光照'] or "不限"
    args['尺寸'] = fstr("宽 %s 高 %s(%s)", args['宽度'], args['高度'], args['方向'])
    if args['装饰值'] ~= nil and args['装饰半径'] ~= nil then
        args['装饰'] = fstr("%s(范围:%s 格)", tostring(args['装饰值']), tostring(args['装饰半径']))
    end
    if args['枯萎装饰值'] ~= nil and args['枯萎装饰半径'] ~= nil then
        args['枯萎装饰'] = fstr("%s(范围:%s 格)", tostring(args['枯萎装饰值']), tostring(args['枯萎装饰半径']))
    end

    local generated = {}
    for _, n in ipairs(innerNodes) do
        local child = infobox.genNode(n, args)
        if child ~= nil then
            table.insert(generated, child)
        end
    end
    return generated
end

-- test: = p.main('testTitle', {{data={['过冷'] = 5}}}, true)
--[[ test: = p.main('testTitle', {
    {label = 'testlabel1', data = {['过冷'] = 5}},
    {label = 'testlabel2', data = {['过冷'] = 5}}
}, true)
]]
function p.main(title, data, raw)
    local contentNodes = nil
    if #data == 1 then
        contentNodes = p.infoboxContent(data[1].data)
    else
        local panelData = {}
        for _, pData in ipairs(data) do
            table.insert(panelData, {
                label = pData.label,
                content = p.infoboxContent(pData.data)
            })
        end
        contentNodes = {
            infobox.panel(panelData)
        }
    end
    return infobox.infobox(title, contentNodes, raw, 'plant')
end

-- test: =p.demo{['装饰值'] = 5, ['装饰半径'] = 1, raw=true}
function p.demo(frame)
    local getArgs = require('Dev:Arguments').getArgs
    local args = getArgs(frame)
    return p.main(args['标题'], {
        {
            data = args
        }
    }, args.raw)
end

return p