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

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

全站通知:

模块:信息框/生态

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

用于模块:Module:生态信息框



-- Module:信息框/生态
local infobox = require([[Module:信息框]])
local fstr = mw.ustring.format
local p = {}

local innerNodes = {
	{
        tag = 'image',
        source = '图片',
        children = {{tag = 'caption', source = '图片说明'}}
    },
    {
        tag = 'data',
        source = '生态代码',
        label = '生态ID'
    },
    {
        tag = 'data',
        source = '生态类型代码',
        label = '生态类型ID'
    },
    {
        tag = 'data',
        source = '温度范围',
        label = '温度范围'
    },
    {
        tag = 'group',
        header = '资源',
        attr = {collapse = 'open'},
        children = {
            {
                tag = 'data',
                source = '固体',
                label = '固体'
            },
            {
                tag = 'data',
                source = '液体',
                label = '液体'
            },
            {
                tag = 'data',
                source = '气体',
                label = '气体'
            },
            {
                tag = 'data',
                source = '小动物',
                label = '小动物'
            },
            {
                tag = 'data',
                source = '植物',
                label = '植物'
            },
            {
                tag = 'data',
                source = '种子',
                label = '种子'
            },
            {
                tag = 'data',
                source = '食物',
                label = '食物'
            },
            {
                tag = 'data',
                source = '其他物品',
                label = '其他物品'
            }
        }
    },
    {
        tag = 'group',
        header = '世界生成',
        attr = {collapse = 'open'},
        children = {
            {
                tag = 'data',
                source = '间歇泉',
                label = '[[间歇泉]]'
            },
            {
                tag = 'data',
                source = '出现小行星',
                label = '出现小行星'
            }
        }
    }
}
local outerNodes = {
    {
        tag = 'image',
        source = '图片',
        children = {{tag = 'caption', source = '图片说明'}}
    }
}

-- test: = p.infoboxContent{['最大光照'] = 5}
function p.infoboxContent(args)
    if args['间歇泉'] ~= nil then
        local node = mw.html.create('div'):tag('small'):css{
            ['display'] = 'grid',
            ['grid-template-columns'] = 'repeat(2, auto)',
            ['grid-gap'] = '0.8em 0.5em',
            ['justify-content'] = 'start',
            ['white-space'] = 'nowrap',
            ['align-items'] = 'center'
        }:wikitext(args['间歇泉'])
        args['间歇泉'] = tostring(node)
    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: mw.logObject(p.infoboxSharedContent{['图片']= '233', ['图片说明']= '233'})
function p.infoboxSharedContent(args)
    local generated = {}
    for _, n in ipairs(outerNodes) 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', {data={['图片']= '233', ['图片说明']= '233'},{data={['天气'] = 5}}, {data={['天气'] = 6}}}, 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

    --local sharedNodes = p.infoboxSharedContent(data.data)
    local nodes = {}
    --for _, node in ipairs(sharedNodes) do table.insert(nodes, node) end
    for _, node in ipairs(contentNodes) do table.insert(nodes, node) end
    return infobox.infobox(title, nodes, raw, 'subworld')
end

-- test: =p.demo{['过冷'] = 5, 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