公告:本站正处于条目建设期。编辑前请阅读 编辑原则;事务讨论请至 管理员告示板。

或许你可以看看这个致全体读者的一封信

Module:Infotable:修订间差异

来自2b2t.xin wiki
跳转到导航 跳转到搜索
Admin​(留言 | 贡献)
(新增 Lua 信息框引擎:已知字段按序渲染,未知参数自动成为自定义行)
 
Admin​(留言 | 贡献)
(group 信息框:结局/现状 合并为单一 状态 字段)
 
第24行: 第24行:
titleKey = '中文名称',
titleKey = '中文名称',
imageKey = '图标',
imageKey = '图标',
fields = { '缩写', '成立时间', '创始人', '现任首领', '成员规模', '主要活动', ' 结局', '现 状' },
fields = { '缩写', '成立时间', '创始人', '现任首领', '成员规模', '主要活动', '状 态' },
},
},
base = {
base = {

2026年10月2日 (五) 20:00的最新版本

此模块的文档可以在Module:Infotable/doc创建

local p = {}

-- 单行渲染:值非空才输出,否则整行隐藏(与旧 {{infotable-row}} 行为一致)
local function row( label, value )
	if value == nil or value == '' then
		return ''
	end
	return '<div class="infotable-row"><span class="infotable-key">'
		.. tostring( label )
		.. '</span><span class="infotable-val">'
		.. tostring( value )
		.. '</span></div>'
end

-- 各信息框的已知字段清单(顺序即显示顺序)
local schemas = {
	player = {
		titleKey = 'ID',
		imageKey = '头像',
		fields = { '别名', '身份', '所属组织', '活跃时期', '主要成就', '现状' },
		forum = true,  -- 启用 论坛(bbs/bbsid) 特殊处理
	},
	group = {
		titleKey = '中文名称',
		imageKey = '图标',
		fields = { '缩写', '成立时间', '创始人', '现任首领', '成员规模', '主要活动', '状态' },
	},
	base = {
		titleKey = '名称',
		imageKey = '图片',
		fields = { '类型', '维度', '坐标量级', '建造时间', '建造者', '结局', '现状' },
	},
	event = {
		titleKey = '名称',
		imageKey = '图片',
		fields = { '时间', '地点', '参与方', '起因', '结果', '影响' },
	},
	exploit = {
		titleKey = '名称',
		imageKey = '图片',
		fields = { '类型', '发现时间', '发现者', '原理', '影响范围', '修复情况' },
	},
}

local function render( frame, kind )
	local schema = schemas[kind]
	if not schema then
		return '<span class="error">未知的信息框类型:' .. tostring( kind ) .. '</span>[[分类:参数错误的页面]]'
	end
	local parent = frame:getParent()
	local args = ( parent and parent.args ) or frame.args

	local title = args[schema.titleKey] or ''
	local image = args[schema.imageKey] or ''
	local used = {}
	used[schema.titleKey] = true
	used[schema.imageKey] = true

	local rows = {}

	-- 已知字段(按清单顺序)
	for _, label in ipairs( schema.fields ) do
		used[label] = true
		rows[#rows + 1] = row( label, args[label] )
	end

	-- 论坛特殊处理(player):用 bbs + bbsid 拼论坛链接
	if schema.forum and ( args.bbs or args.bbsid ) then
		used.bbs = true
		used.bbsid = true
		local forumVal = frame:expandTemplate{
			title = 'bbsId',
			args = { id = args.bbsid or '', name = args.bbs or '' },
		}
		rows[#rows + 1] = row( '论坛', forumVal )
	end

	-- 未知参数字典序排列,作为自定义行(param 名即标签,值即内容)
	local custom = {}
	for k, v in pairs( args ) do
		if type( k ) == 'string' and not used[k] and v ~= '' and v ~= nil then
			custom[#custom + 1] = k
		end
	end
	table.sort( custom )
	for _, k in ipairs( custom ) do
		rows[#rows + 1] = row( k, args[k] )
	end

	local rowsHtml = table.concat( rows, '' )

	return '<div class="infotable">'
		.. '<div class="infotable-head"><div class="infotable-title">' .. title .. '</div></div>'
		.. '<div class="infotable-body">'
		.. '<div class="infotable-figure">' .. image .. '</div>'
		.. '<div class="infotable-rows">' .. rowsHtml .. '</div>'
		.. '</div></div>'
end

p.player  = function( frame ) return render( frame, 'player' ) end
p.group   = function( frame ) return render( frame, 'group' ) end
p.base    = function( frame ) return render( frame, 'base' ) end
p.event   = function( frame ) return render( frame, 'event' ) end
p.exploit = function( frame ) return render( frame, 'exploit' ) end

return p