-- 模块: llsifcardshow
-- 迁移自模板: {{llsifcardshow}}
-- 复刻主要行为(含 1 / 2 / 3 / 7 / 9 张卡的分支、idolized 判定、Hover 效果、自定义文件名 path 参数、underscore 插入、llsifitem 标签拼接、tabs/core 调用、末尾注释)。
-- 若原模板出现其它数量(>2 且非 3/7/9),此实现以通用 tabs 呈现所有卡。
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function splitList(raw)
if not raw or raw == '' then return {} end
raw = mw.ustring.gsub(raw, '[,、]', ',')
local out = {}
for part in mw.ustring.gmatch(raw, '([^,]+)') do
part = mw.text.trim(part)
if part ~= '' then table.insert(out, part) end
end
return out
end
local function buildFileNames(args, idx, id, idolized, underscore)
local names = {}
if idolized then
local custom = args['path' .. idx]
if custom and custom ~= '' then
names.single = custom
else
names.single = mw.ustring.format('Card%s%s.png', underscore and '_' or '', id)
end
else
local customA = args['path' .. idx .. 'a']
local customB = args['path' .. idx .. 'b']
if customA and customA ~= '' then
names.a = customA else names.a = mw.ustring.format('Card%s%s_a.png', underscore and '_' or '', id) end
if customB and customB ~= '' then
names.b = customB else names.b = mw.ustring.format('Card%s%s_b.png', underscore and '_' or '', id) end
end
return names
end
-- 生成 256px 卡图 (#img parser function + filepath)
local function img256(frame, fileName)
if not fileName or fileName == '' then return '' end
local path = frame:callParserFunction('filepath', fileName)
-- {{#img:|src=PATH|style=width:256px}}
return frame:callParserFunction('#img', { path, 'style=width:256px' })
end
local function buildHover(frame, beforeFile, afterFile)
return frame:expandTemplate{ title = 'Hover', args = {
width = '256px', height = '360px',
before = img256(frame, beforeFile),
after = img256(frame, afterFile)
}}
end
local function buildSingleTable(frame, idolized, typeUpper, label, fileNames)
local tbl = mw.html.create('table')
:addClass('wikitable')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:css('text-align', 'center')
local tr1 = tbl:tag('tr')
tr1:tag('th'):wikitext("'''活动奖励" .. typeUpper .. "卡面'''")
local tr2 = tbl:tag('tr')
if idolized then
tr2:tag('th'):wikitext(label)
local tr3 = tbl:tag('tr')
tr3:tag('td'):wikitext(img256(frame, fileNames.single))
else
tr2:tag('td'):wikitext('光标悬停或移动端点击显示觉醒状态')
local tr3 = tbl:tag('tr')
tr3:tag('th'):wikitext(label)
local tr4 = tbl:tag('tr')
tr4:tag('td'):wikitext(buildHover(frame, fileNames.a, fileNames.b))
end
return tostring(tbl)
end
local function buildDoubleTable(frame, typeUpper, label1, label2, files1, files2)
local tbl = mw.html.create('table')
:addClass('wikitable')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:css('text-align','center')
-- 标题行
local tr1 = tbl:tag('tr')
tr1:tag('th'):attr('colspan', 3):wikitext("'''活动奖励" .. typeUpper .. "卡面'''")
-- 悬停说明
local tr2 = tbl:tag('tr')
tr2:tag('td'):attr('colspan', 3):wikitext('光标悬停或移动端点击显示觉醒状态')
-- 名称行:左奖励 / 分隔空白 / 右奖励
local tr3 = tbl:tag('tr')
tr3:tag('th'):wikitext('活动pt达成奖励 ' .. label1)
tr3:tag('th'):attr('rowspan', 2):wikitext('')
tr3:tag('th'):wikitext('活动pt排名奖励 ' .. label2)
-- 图片行
local tr4 = tbl:tag('tr')
tr4:tag('td'):wikitext(buildHover(frame, files1.a, files1.b))
tr4:tag('td'):wikitext(buildHover(frame, files2.a, files2.b))
return tostring(tbl)
end
local function buildMiniTable(frame, idx, label, fileNames)
local center = mw.html.create('center')
local tbl = center:tag('table')
:addClass('wikitable')
:addClass('mw-collapsible')
:css('text-align','center')
local trh = tbl:tag('tr')
trh:tag('th'):wikitext("'''" .. label .. "'''")
local tri = tbl:tag('tr')
tri:tag('td'):wikitext(img256(frame, fileNames.single or fileNames.a or ''))
return tostring(center)
end
local function buildTabs(frame, count, labels, tables)
local args = {
TextBackgroundColor='transparent',
TextBorderColor='transparent',
LabelPadding='0.5em',
LabelColor='blue',
TextPadding=0,
AutoWidth='yes'
}
for i=1, count do
args['label'..i] = labels[i]
args['text'..i] = tables[i]
end
return frame:expandTemplate{ title='tabs/core', args = args }
end
function p.main(frame)
local args = getArgs(frame, { parentFirst = true })
local names = splitList(args.nm)
local ids = splitList(args.id)
local cls = splitList(args.cl)
local idolized = args.idolized and args.idolized ~= ''
local underscore = args.underscore and args.underscore ~= ''
local typeParam = args.type or 'sr'
local typeUpper = frame:callParserFunction('uc', typeParam)
local count = #names
if count == 0 then return '' end
-- 统一填充长度以避免索引错误
while #ids < count do table.insert(ids, ids[#ids] or '') end
while #cls < count do table.insert(cls, cls[#cls] or '') end
-- 生成标签(llsifitem 调用)
local labels = {}
for i=1,count do
labels[i] = frame:expandTemplate{ title='llsifitem', args={ cls[i], names[i] } }
end
-- 文件名集合
local files = {}
for i=1,count do
files[i] = buildFileNames(args, i, ids[i], idolized, underscore)
end
local out
if count == 1 then
out = buildSingleTable(frame, idolized, typeUpper, labels[1], files[1])
elseif count == 2 then
out = buildDoubleTable(frame, typeUpper, labels[1], labels[2], files[1], files[2])
elseif count == 3 or count == 7 or count == 9 then
-- 按原模板:3 / 7 / 9 特殊排布
local miniTables = {}
for i=1,count do
miniTables[i] = buildMiniTable(frame, i, labels[i], files[i])
end
if count == 7 then
-- 两组 tabs: 1-5 与 6-7
local first = buildTabs(frame,5,labels,miniTables)
local labels2, tables2 = {}, {}
for i=6,7 do labels2[i-5]=labels[i]; tables2[i-5]=miniTables[i] end
local second = buildTabs(frame,2,labels2,tables2)
local clear = frame:expandTemplate{ title = 'clear' }
out = first .. ' ' .. second .. ' ' .. clear
else
local clear = frame:expandTemplate{ title = 'clear' }
out = buildTabs(frame, count, labels, miniTables) .. ' ' .. clear
end
else
-- 通用 fallback: 所有卡做成一个 tabs
local miniTables = {}
for i=1,count do
miniTables[i] = buildMiniTable(frame, i, labels[i], files[i])
end
local clear = frame:expandTemplate{ title = 'clear' }
out = buildTabs(frame, count, labels, miniTables) .. ' ' .. clear
end
local note = "'''注:'''关于卡片的详细属性等信息,请在游戏中或利用其他工具进行查看。"
if idolized then
note = note .. "'''本组卡只有觉醒卡。'''"
end
return out .. note
end
return p