打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:SongInfoDetails:修订间差异

来自Rizline中文维基
 
(未显示同一用户的5个中间版本)
第2行: 第2行:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


-- 获取带数字后缀的参数列表
local function getArgNums(args, prefix)
local function getArgNums(args, prefix)
     local nums = {}
     local nums = {}
第20行: 第19行:
end
end


-- 渲染Riztime时间段
local function renderRiztimes(args)
local function renderRiztimes(args)
     local nums = getArgNums(args, 'riztimestart')
     local nums = getArgNums(args, 'riztimestart')
第37行: 第35行:
end
end


-- 渲染常规主题颜色
local function renderNormalColors(args)
local function renderNormalColors(args)
     local nums = getArgNums(args, 'normalcolor')
     local nums = getArgNums(args, 'normalcolor')
第53行: 第50行:
end
end


-- 渲染Riztime主题颜色
local function renderRiztimeColors(args, themeNum)
local function renderRiztimeColors(args, themeNum)
     local prefix = 'riztimecolor' .. themeNum .. '_'
     local prefix = 'riztimecolor' .. themeNum .. '_'
第70行: 第66行:
end
end


-- 主函数
function p.details(frame)
function p.details(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)
第87行: 第82行:
     local html = {}
     local html = {}
      
      
     table.insert(html, '<div class="mw-collapsible mw-collapsed" style="width: 100%; text-align: left;">')
     local headerStyle = string.format(
    table.insert(html, string.format(
         'background:%s; color:%s; padding: 8px; font-weight: bold; text-align: center;',
         '<div style="background:%s; %s padding: 8px; font-weight: bold; text-align: center;">详细信息</div>',
         args.color3 or 'var(--color-surface-3)',
         args.color3 or '#AEE0F7', -- 匹配主infobox header颜色
         args.textcolor3 or 'var(--color-emphasized)'
         args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
     )
     ))
    table.insert(html, '<table class="infobox" style="width:100%; border:none; margin:0;">')
      
      
     local labelStyle = string.format(
     local labelStyle = string.format(
         'width:90px;background:%s; %s padding:4px 8px;',
         'width:90px; background:%s; color:%s; padding:4px 8px;',
         args.color4 or '#C5E8FB', -- 匹配主infobox label颜色
         args.color4 or 'var(--color-surface-2)',
         args.textcolor4 and ('color:' .. args.textcolor4 .. ';') or 'color:#000000;'
         args.textcolor4 or '#000000'
     )
     )
      
      
     local dataStyle = 'background:#FDFDFD; padding:4px 8px;'
     local dataStyle = 'background:var(--color-surface-1); color:var(--color-base); padding:4px 8px;'


     -- 预览时间
     table.insert(html, '<div class="mw-collapsible mw-collapsed" style="width: 100%;">')
    table.insert(html, string.format('<div style="%s">详细信息</div>', headerStyle))
    table.insert(html, '<table class="infobox mw-collapsible-content" style="width:100%; border:none; margin:0;">')
   
     if args.previewtime then
     if args.previewtime then
         table.insert(html, string.format(
         table.insert(html, string.format(
第111行: 第107行:
     end
     end
      
      
    -- Riztime时间
     local riztimes = renderRiztimes(args)
     local riztimes = renderRiztimes(args)
     if riztimes then
     if riztimes then
第120行: 第115行:
     end
     end
      
      
    -- 主题颜色标题
     local normalColors = renderNormalColors(args)
     local normalColors = renderNormalColors(args)
     local hasRiztimeColors = getArgNums(args, 'riztimecolor1_')[1]
     local hasRiztimeColors = getArgNums(args, 'riztimecolor1_')[1]
      
      
     if normalColors or hasRiztimeColors then
     if normalColors or hasRiztimeColors then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
         table.insert(html, string.format(
         table.insert(html, string.format(
             '<tr><th colspan="2" style="padding:8px;background:%s; %s">主题颜色</th></tr>',
             '<tr><th colspan="2" style="%s">主题颜色</th></tr>',
             args.color3 or '#AEE0F7',
             subHeaderStyle
            args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
         ))
         ))
     end
     end
      
      
    -- 常规主题
     if normalColors then
     if normalColors then
         table.insert(html, string.format(
         table.insert(html, string.format(
第140行: 第133行:
     end
     end
      
      
    -- Riztime主题
     for i = 1, 20 do
     for i = 1, 20 do
         local colors = renderRiztimeColors(args, i)
         local colors = renderRiztimeColors(args, i)
第151行: 第143行:
     end
     end
      
      
    -- 谱面信息标题
     if args.eztap or args.hdtap or args.intap or args.attap then
     if args.eztap or args.hdtap or args.intap or args.attap then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
         table.insert(html, string.format(
         table.insert(html, string.format(
             '<tr><th colspan="2" style="padding:8px;background:%s; %s">谱面信息</th></tr>',
             '<tr><th colspan="2" style="%s">谱面信息</th></tr>',
             args.color3 or '#AEE0F7',
             subHeaderStyle
            args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
         ))
         ))
         table.insert(html, string.format(
         table.insert(html, string.format(
             '<tr><th colspan="2" style="padding:8px;background:%s; %s">Tap/Drag/Hold</th></tr>',
             '<tr><th colspan="2" style="%s">Tap/Drag/Hold</th></tr>',
             args.color3 or '#AEE0F7',
             subHeaderStyle
            args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
         ))
         ))
     end
     end
      
      
    -- EZ谱面信息
     if args.eztap then
     if args.eztap then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'EZ', args.ez or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'EZ', args.ez or ''} }
第174行: 第163行:
     end
     end
      
      
    -- HD谱面信息
     if args.hdtap then
     if args.hdtap then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'HD', args.hd or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'HD', args.hd or ''} }
第183行: 第171行:
     end
     end
      
      
    -- IN谱面信息
     if args.intap then
     if args.intap then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'IN', args.inlevel or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'IN', args.inlevel or ''} }
第192行: 第179行:
     end
     end
      
      
    -- AT谱面信息
     if args.attap then
     if args.attap then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'AT', args.at or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'AT', args.at or ''} }
第201行: 第187行:
     end
     end
      
      
    -- 线条数标题
     if args.ezline or args.hdline or args.inline or args.atline then
     if args.ezline or args.hdline or args.inline or args.atline then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
         table.insert(html, string.format(
         table.insert(html, string.format(
             '<tr><th colspan="2" style="padding:8px;background:%s; %s">线条数</th></tr>',
             '<tr><th colspan="2" style="%s">线条数</th></tr>',
             args.color3 or '#AEE0F7',
             subHeaderStyle
            args.textcolor3 and ('color:' .. args.textcolor3 .. ';') or 'color:#000000;'
         ))
         ))
     end
     end
      
      
    -- EZ线条数
     if args.ezline then
     if args.ezline then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'EZ', args.ez or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'EZ', args.ez or ''} }
第219行: 第203行:
     end
     end
      
      
    -- HD线条数
     if args.hdline then
     if args.hdline then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'HD', args.hd or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'HD', args.hd or ''} }
第228行: 第211行:
     end
     end
      
      
    -- IN线条数
     if args.inline then
     if args.inline then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'IN', args.inlevel or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'IN', args.inlevel or ''} }
第237行: 第219行:
     end
     end
      
      
    -- AT线条数
     if args.atline then
     if args.atline then
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'AT', args.at or ''} }
         local diffTag = mw.getCurrentFrame():expandTemplate{ title = 'Diff', args = {'AT', args.at or ''} }

2025年11月29日 (六) 17:40的最新版本

此模块的文档可以在模块: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 color
end

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

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.attap
        or args.ezline or args.hdline or args.inline or args.atline
    
    if not hasDetails then
        return ''
    end
    
    local html = {}
    
    local headerStyle = string.format(
        'background:%s; color:%s; padding: 8px; font-weight: bold; text-align: center;',
        args.color3 or 'var(--color-surface-3)',
        args.textcolor3 or 'var(--color-emphasized)'
    )
    
    local labelStyle = string.format(
        'width:90px; background:%s; color:%s; padding:4px 8px;',
        args.color4 or 'var(--color-surface-2)',
        args.textcolor4 or '#000000'
    )
    
    local dataStyle = 'background:var(--color-surface-1); color:var(--color-base); padding:4px 8px;'

    table.insert(html, '<div class="mw-collapsible mw-collapsed" style="width: 100%;">')
    table.insert(html, string.format('<div style="%s">详细信息</div>', headerStyle))
    table.insert(html, '<table class="infobox mw-collapsible-content" style="width:100%; border:none; margin:0;">')
    
    if args.previewtime then
        table.insert(html, string.format(
            '<tr><th scope="row" style="%s">预览时间</th><td style="%s">%s</td></tr>',
            labelStyle, dataStyle, args.previewtime
        ))
    end
    
    local riztimes = renderRiztimes(args)
    if riztimes then
        table.insert(html, string.format(
            '<tr><th scope="row" style="%s">Riztime时间</th><td style="%s">%s</td></tr>',
            labelStyle, dataStyle, riztimes
        ))
    end
    
    local normalColors = renderNormalColors(args)
    local hasRiztimeColors = getArgNums(args, 'riztimecolor1_')[1]
    
    if normalColors or hasRiztimeColors then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
        table.insert(html, string.format(
            '<tr><th colspan="2" style="%s">主题颜色</th></tr>',
            subHeaderStyle
        ))
    end
    
    if normalColors then
        table.insert(html, string.format(
            '<tr><th scope="row" style="%s">常规主题</th><td style="%s">%s</td></tr>',
            labelStyle, dataStyle, normalColors
        ))
    end
    
    for i = 1, 20 do
        local colors = renderRiztimeColors(args, i)
        if colors then
            table.insert(html, string.format(
                '<tr><th scope="row" style="%s">Riztime主题%d</th><td style="%s">%s</td></tr>',
                labelStyle, i, dataStyle, colors
            ))
        end
    end
    
    if args.eztap or args.hdtap or args.intap or args.attap then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
        table.insert(html, string.format(
            '<tr><th colspan="2" style="%s">谱面信息</th></tr>',
            subHeaderStyle
        ))
        table.insert(html, string.format(
            '<tr><th colspan="2" style="%s">Tap/Drag/Hold</th></tr>',
            subHeaderStyle
        ))
    end
    
    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="%s">%s/%s/%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.eztap or '?', args.ezdrag or '?', args.ezhold or '?'
        ))
    end
    
    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="%s">%s/%s/%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.hdtap or '?', args.hddrag or '?', args.hdhold or '?'
        ))
    end
    
    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="%s">%s/%s/%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.intap or '?', args.indrag or '?', args.inhold or '?'
        ))
    end
    
    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="%s">%s/%s/%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.attap or '?', args.atdrag or '?', args.athold or '?'
        ))
    end
    
    if args.ezline or args.hdline or args.inline or args.atline then
        local subHeaderStyle = headerStyle:gsub('font%-weight:%s*bold;%s*','') .. ' text-align: center;'
        table.insert(html, string.format(
            '<tr><th colspan="2" style="%s">线条数</th></tr>',
            subHeaderStyle
        ))
    end
    
    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="%s">%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.ezline
        ))
    end
    
    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="%s">%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.hdline
        ))
    end
    
    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="%s">%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.inline
        ))
    end
    
    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="%s">%s</td></tr>',
            labelStyle, diffTag, dataStyle, args.atline
        ))
    end
    
    table.insert(html, '</table>')
    table.insert(html, '</div>')
    
    return table.concat(html)
end

return p