本WIKI于2021年03月04日通过了时雨音的接管申请,编辑权限开放。
欢迎收藏本WIKI防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
建议使用PC版页面访问本WIKI以获得更佳体验!
编辑帮助 • WIKI建议 • 加入我们 • 使用哔哩哔哩APP打开WIKI
全站通知:
模块:评分表格
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:评分表格/doc创建
-- 模块:评分表格 —— {{评分表格}} 的 Lua 版本
local p = {}
local RATING_KEYS = { '综合', 'PVE', '角斗场', '竞技赛', '公会战', '首领连战', '团队远征', '死斗' }
-- 取参数:本 wiki 的 #invoke 不会自动继承模板参数,故显式回退到父级(模板)帧
local function getArgs(frame)
local args = frame.args
if mw.text.trim(tostring(args['页面名称'] or '')) ~= '' then
return args
end
local ok, parent = pcall(frame.getParent, frame)
if ok and parent and mw.text.trim(tostring(parent.args['页面名称'] or '')) ~= '' then
return parent.args
end
return args
end
-- {{{1|}}} 取值并 trim
local function val(x)
return mw.text.trim(tostring(x or ''))
end
-- 对应 {{#show:页面|?属性}}
local function showProp(frame, page, prop)
if val(page) == '' then return '' end
return val(frame:preprocess('{{#show:' .. page .. '|?' .. prop .. '}}'))
end
-- 对应 {{Ifexist|1=页面|2=有|3=无}}
-- 注意:不能用 mw.title.exists,那是昂贵函数,234 行会撞上限(Lua错误: too many expensive function calls);
-- {{Ifexist}} 在本 wiki 不计入昂贵函数,与原模板写法保持一致。
local function ifexist(frame, name)
if val(name) == '' then return '' end
return val(frame:preprocess('{{Ifexist|1=' .. name .. '|2=1|3=}}'))
end
-- 对应 {{评分表格/光环|{{#explode:@|+|0}}}}:取 "+" 之前的部分
local function auraItem(frame, item)
local head = mw.text.trim(mw.text.split(item, '+', true)[1] or '')
return frame:expandTemplate{ title = '评分表格/光环', args = { head } }
end
-- 对应 {{评分表格/光环}} 的 arraymap 整列
local function auraParam(frame, aura)
local s = val(aura)
if s == '' then return '' end
local out = {}
for item in mw.text.gsplit(s, ',', true) do
out[#out + 1] = auraItem(frame, item)
end
return table.concat(out, ',')
end
-- 队伍增益效果列的输出策略
-- AURA_ALL_PAGES = false:仅在 AURA_PAGES 列出的页面输出
-- (= 原模板 {{#ifeq:{{PAGENAME}}|英雄筛选表}} 的行为,12 列页与 13 列页各自对齐)
-- AURA_ALL_PAGES = true :每行都输出第 5 格。此时【必须】同时给 英雄图鉴 的 4 个表头
-- 补上「队伍增益效果」<th>,否则那 4 个页面会列错位;多出的第 5 列再用 CSS 隐藏:
-- body:not(.page-英雄筛选表) #CardSelectTr th:nth-child(5),
-- body:not(.page-英雄筛选表) #CardSelectTr td:nth-child(5) { display: none; }
local AURA_ALL_PAGES = false
local AURA_PAGES = {
['英雄筛选表'] = true,
}
local function needAuraColumn()
if AURA_ALL_PAGES then return true end
local title = mw.title.getCurrentTitle()
return AURA_PAGES[title.text] == true or AURA_PAGES[title.prefixedText] == true
end
-- 对应 模板:评分表格/行:13 个位置参数
-- 1 页面名称 2 简称 3 名字 4 角色外号 5 稀有度 6 属性 7 职业
-- 8 可携带武器 9 专武名称 10 连锁发起状态 11 连锁效果 12 组队光环 13 评分串
local function renderRow(frame, a)
-- 英雄图标:{{#switch:{{{5}}}|5|6=Icon2|Icon}}
local heroIcon = showProp(frame, a[1], (a[5] == '5' or a[5] == '6') and 'Icon2' or 'Icon')
-- 专武:{{Ifexist}} + {{#switch:{{{5}}}|6=Icon2|Icon}}
local wcell
if ifexist(frame, a[9]) ~= '' then
local wIcon = showProp(frame, a[9], a[5] == '6' and 'Icon2' or 'Icon')
wcell = '[[文件:' .. wIcon .. '|class=img-item|link=' .. a[9] .. '|50px]]'
else
wcell = '[[文件:未实装.png|class=img-kk|link=|50px]]'
end
-- 连锁效果:{{#if:{{{10|}}}|skill_chain_10_11.png|/}}
local chainCell = '/'
if val(a[10]) ~= '' then
chainCell = '[[文件:skill_chain_' .. a[10] .. a[11] .. '.png|32px|link=]]'
end
-- 队伍增益列:仅指定页面显示(与原 {{#ifeq:{{PAGENAME}}|英雄筛选表}} 一致)
local auraCell = ''
if needAuraColumn() then
auraCell = '<td>' .. (val(a[12]):gsub(',', '<br>')) .. '</td>'
end
-- 8 个评分列:{{#arraymap:评分串|,|@|<td>{{评星|@|1}}</td>}}
local starCells = {}
for i = 1, 8 do
starCells[#starCells + 1] = '<td>'
.. frame:expandTemplate{ title = '评星', args = { a[13][i], '1' } }
.. '</td>'
end
return table.concat({
'<tr class="divsort" data-param1="' .. (val(a[8]):gsub(',', ','))
.. '" data-param2="' .. val(a[5])
.. '" data-param3="' .. val(a[6])
.. '" data-param4="' .. (val(a[10]) ~= '' and val(a[10]) or '/')
.. '" data-param5="' .. (val(a[11]) ~= '' and val(a[11]) or '/')
.. '" data-param6="' .. val(a[7])
.. '" data-param7="' .. auraParam(frame, a[12]) .. '">',
'<th class="hero-th">[[文件:' .. heroIcon .. '|' .. (val(a[3]) ~= '' and val(a[3]) or val(a[2]))
.. '|class=img-item|60px|link=' .. a[1] .. ']]'
.. ' <span class="mwiki-hide">'
.. frame:expandTemplate{ title = '稀有度', args = { '角色', val(a[5]), '60px' } }
.. '</span> <span class="hero-mname">[[' .. a[1] .. '|' .. val(a[2]) .. ']]</span></th>',
'<td class="hero-td">' .. (val(a[4]):gsub(',', '<br>')) .. '</td>',
'<th>' .. wcell .. '</th>',
'<td>' .. chainCell .. '</td>',
auraCell,
table.concat(starCells),
'</tr>',
}, '\n')
end
-- 对应 模板:评分表格:4 段条件调用
function p.main(frame)
local args = getArgs(frame)
-- {{#arraymap:综合,...,死斗|,|@|{{#ifeq:{{{@评价|}}}||n|{{{@评价|n}}}}}|,}}
local function ratingList(suffix)
local t = {}
for i, key in ipairs(RATING_KEYS) do
local v = val(args[key .. '评价' .. suffix])
t[i] = (v ~= '') and v or 'n'
end
return t
end
local function build(suffix, abbr, rarity)
return renderRow(frame, {
val(args['页面名称']), -- 1 页面名称
abbr, -- 2 简称(二专行加 ²)
val(args['名字']), -- 3 名字
val(args['角色外号' .. suffix]), -- 4 角色外号
rarity, -- 5 稀有度(升阶 5 / 开花 6)
val(args['属性']), -- 6 属性
val(args['职业']), -- 7 职业
val(args['可携带武器']), -- 8 可携带武器
val(args['专武名称' .. (suffix == '2' and '2' or '')]), -- 9 专武名称(仅二专为 2)
val(args['连锁发起状态' .. suffix]), -- 10 连锁发起状态
val(args['连锁效果' .. suffix]), -- 11 连锁效果
val(args['组队光环' .. suffix]), -- 12 组队光环
ratingList(suffix), -- 13 评分串
})
end
local rows = {}
-- 第 1 行:普通形态
rows[#rows + 1] = build('', val(args['简称']), val(args['稀有度']))
-- 第 2 行:二专
if val(args['二专']) == '是' then
rows[#rows + 1] = build('2', val(args['简称']) .. '²', val(args['稀有度']))
end
-- 第 3 行:升阶(稀有度固定 5,专武仍取 专武名称)
if val(args['升阶']) == '是' then
rows[#rows + 1] = build('3', val(args['简称']), '5')
end
-- 第 4 行:开花(稀有度固定 6,专武仍取 专武名称)
if val(args['开花']) == '是' then
rows[#rows + 1] = build('4', val(args['简称']), '6')
end
return table.concat(rows, '\n')
end
-- 诊断:临时把模板改成 {{#invoke:评分表格|debug}} 可查看实际收到的参数
function p.debug(frame)
local out = { 'frame.args:' }
local function dump(t, prefix)
local keys = {}
for k in pairs(t) do keys[#keys + 1] = tostring(k) end
table.sort(keys)
for _, k in ipairs(keys) do
out[#out + 1] = prefix .. k .. ' = [' .. tostring(t[k]) .. ']'
end
end
dump(frame.args, ' args.')
local ok, parent = pcall(frame.getParent, frame)
out[#out + 1] = ok and parent and '-- parent.args --' or '(无父级帧)'
if ok and parent then dump(parent.args, ' parent.') end
return '<pre style="white-space:pre-wrap;font-size:12px">'
.. table.concat(out, '\n') .. '</pre>'
end
return p

沪公网安备 31011002002714 号