模块:SongInfoDetails:修订间差异
来自Rizline中文维基
更多操作
卡介菌(留言 | 贡献) (创建页面,内容为“local p = {} local getArgs = require('Module:Arguments').getArgs -- 获取带数字后缀的参数列表 local function getArgNums(args, prefix) local nums = {} for k, v in pairs(args) do local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') if num and v and v ~= '' then table.insert(nums, tonumber(num)) end end table.sort(nums) return nums end -- 渲染颜色块 local function renderColor(color)…”) |
(没有差异)
|
2025年10月24日 (五) 13:59的版本
此模块的文档可以在模块:SongInfoDetails/doc创建
local p = {}
local getArgs = require('Module:Arguments').getArgs
-- 获取带数字后缀的参数列表
local function getArgNums(args, prefix)
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num and v and v ~= '' then
table.insert(nums, tonumber(num))
end
end
table.sort(nums)
return nums
end
-- 渲染颜色块
local function renderColor(color)
if not color or color == '' then return '' end
return string.format(
'<span style="display: inline-block;width: 30px;height: 30px;background: %s; border: 1px solid #ccc;"></span><span style="position: relative; left: 10px; top: -8px;"><big>%s</big></span>',
color, color
)
end
-- 渲染Riztime时间段
local function renderRiztimes(args)
local nums = getArgNums(args, 'riztimestart')
if #nums == 0 then return nil end
local times = {}
for _, num in ipairs(nums) do
local startKey = 'riztimestart' .. num
local endKey = 'riztimeend' .. num
if args[startKey] and args[endKey] then
table.insert(times, args[startKey] .. '-' .. args[endKey])
end
end
return #times > 0 and table.concat(times, '<br>') or '未填写'
end
-- 渲染常规主题颜色
local function renderNormalColors(args)
local nums = getArgNums(args, 'normalcolor')
if #nums == 0 then return nil end
local colors = {}
for _, num in ipairs(nums) do
local color = args['normalcolor' .. num]
if color then
table.insert(colors, renderColor(color))
end
end
return #colors > 0 and table.concat(colors, '<br>') or '未填写'
end
-- 渲染Riztime主题颜色
local function renderRiztimeColors(args, themeNum)
local prefix = 'riztimecolor' .. themeNum .. '_'
local nums = getArgNums(args, prefix)
if #nums == 0 then return nil end
local colors = {}
for _, num in ipairs(nums) do
local color = args[prefix .. num]
if color then
table.insert(colors, renderColor(color))
end
end
return #colors > 0 and table.concat(colors, '<br>') or nil
end
-- 主函数
function p.details(frame)
local args = getArgs(frame)
-- 检查是否有任何详细信息
local hasDetails = args.previewtime
or getArgNums(args, 'riztimestart')[1]
or getArgNums(args, 'normalcolor')[1]
or getArgNums(args, 'riztimecolor1_')[1]
or args.eztap or args.hdtap or args.intap
or args.ezline or args.hdline or args.inline
if not hasDetails then
return ''
end
local html = {}
table.insert(html, '<div class="mw-collapsible mw-collapsed" style="border: 1px solid #a2a9b1; margin-top: 1em;">')
table.insert(html, string.format(
'<div style="background:%s; %s padding: 8px; font-weight: bold; text-align: center;">详细信息</div>',
args.color3 or '#B2E9FE',
args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
))
table.insert(html, '<table class="infobox" style="width:100%; border-collapse:separate; border-spacing:2px; margin:0;">')
local labelStyle = string.format(
'width:90px;background:%s; %s padding:4px 8px;',
args.color4 or '#D5F3FE',
args.textcolor4 and ('color:' .. args.textcolor4 .. ';') or 'color:#000000;'
)
-- 预览时间
if args.previewtime then
table.insert(html, string.format(
'<tr><th scope="row" style="%s">预览时间</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, args.previewtime
))
end
-- Riztime时间
local riztimes = renderRiztimes(args)
if riztimes then
table.insert(html, string.format(
'<tr><th scope="row" style="%s">Riztime时间</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, riztimes
))
end
-- 主题颜色标题
local normalColors = renderNormalColors(args)
local hasRiztimeColors = getArgNums(args, 'riztimecolor1_')[1]
if normalColors or hasRiztimeColors then
table.insert(html, string.format(
'<tr><th colspan="2" style="padding:8px;background:%s; %s">主题颜色</th></tr>',
args.color3 or '#B2E9FE',
args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
))
end
-- 常规主题
if normalColors then
table.insert(html, string.format(
'<tr><th scope="row" style="%s">常规主题</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, normalColors
))
end
-- Riztime主题
for i = 1, 20 do -- 最多支持20个Riztime主题
local colors = renderRiztimeColors(args, i)
if colors then
table.insert(html, string.format(
'<tr><th scope="row" style="%s">Riztime主题%d</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, i, colors
))
end
end
-- 谱面信息标题
if args.eztap or args.hdtap or args.intap or args.attap then
table.insert(html, string.format(
'<tr><th colspan="2" style="padding:8px;background:%s; %s">谱面信息</th></tr>',
args.color3 or '#B2E9FE',
args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
))
table.insert(html, string.format(
'<tr><th colspan="2" style="padding:8px;background:%s; %s">Tap/Drag/Hold</th></tr>',
args.color3 or '#B2E9FE',
args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
))
end
-- EZ谱面信息
if args.eztap then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'EZ', args.ez or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s/%s/%s</td></tr>',
labelStyle, diffTag, args.eztap or '?', args.ezdrag or '?', args.ezhold or '?'
))
end
-- HD谱面信息
if args.hdtap then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'HD', args.hd or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s/%s/%s</td></tr>',
labelStyle, diffTag, args.hdtap or '?', args.hddrag or '?', args.hdhold or '?'
))
end
-- IN谱面信息
if args.intap then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'IN', args.inlevel or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s/%s/%s</td></tr>',
labelStyle, diffTag, args.intap or '?', args.indrag or '?', args.inhold or '?'
))
end
-- AT谱面信息
if args.attap then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'AT', args.at or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s/%s/%s</td></tr>',
labelStyle, diffTag, args.attap or '?', args.atdrag or '?', args.athold or '?'
))
end
-- 线条数标题
if args.ezline or args.hdline or args.inline or args.atline then
table.insert(html, string.format(
'<tr><th colspan="2" style="padding:8px;background:%s; %s">线条数</th></tr>',
args.color3 or '#B2E9FE',
args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
))
end
-- EZ线条数
if args.ezline then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'EZ', args.ez or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, diffTag, args.ezline
))
end
-- HD线条数
if args.hdline then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'HD', args.hd or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, diffTag, args.hdline
))
end
-- IN线条数
if args.inline then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'IN', args.inlevel or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, diffTag, args.inline
))
end
-- AT线条数
if args.atline then
local diffTag = mw.getCurrentFrame():expandTemplate{
title = 'Diff',
args = {'AT', args.at or ''}
}
table.insert(html, string.format(
'<tr><th scope="row" style="%s">%s</th><td style="padding:4px 8px;">%s</td></tr>',
labelStyle, diffTag, args.atline
))
end
table.insert(html, '</table>')
table.insert(html, '</div>')
return table.concat(html)
end
return p