模块:Db:修订间差异
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
||
| 第18行: | 第18行: | ||
-- [[------------------------------------------------------------------]] | -- [[------------------------------------------------------------------]] | ||
local displayNames = { | local displayNames = { | ||
['title'] = '歌曲标题', ['composer'] = '艺术家', ['bpm'] = 'BPM', ['singer'] = '歌手', ['genre'] = '流派', | |||
['title'] = '歌曲标题', | ['id'] = '歌曲ID', ['key'] = 'KEY音', ['bga'] = 'BGA作者', ['duration'] = '时长', | ||
['id'] = '歌曲ID', | |||
['4b_nm'] = '4B NM', ['4b_nm_notes'] = '4B NM按键数', ['4b_hd'] = '4B HD', ['4b_hd_notes'] = '4B HD按键数', | ['4b_nm'] = '4B NM', ['4b_nm_notes'] = '4B NM按键数', ['4b_hd'] = '4B HD', ['4b_hd_notes'] = '4B HD按键数', | ||
['4b_mx'] = '4B MX', ['4b_mx_notes'] = '4B MX按键数', ['4b_sc'] = '4B SC', ['4b_sc_notes'] = '4B SC按键数', | ['4b_mx'] = '4B MX', ['4b_mx_notes'] = '4B MX按键数', ['4b_sc'] = '4B SC', ['4b_sc_notes'] = '4B SC按键数', | ||
| 第56行: | 第44行: | ||
end | end | ||
-- 格式化单个值的私有函数 ( | -- 格式化单个值的私有函数 (基础格式化,确保 ' - ' 被视为字符串) | ||
local function formatSingleValue(value, fieldType) | local function formatSingleValue(value, fieldType) | ||
if value == nil then | if value == nil then | ||
| 第65行: | 第53行: | ||
return p.valueMappingMethod[fieldType](value) | return p.valueMappingMethod[fieldType](value) | ||
else | else | ||
-- 核心:将所有值转换为字符串,包括 '-' | |||
return tostring(value) | return tostring(value) | ||
end | end | ||
| 第77行: | 第66行: | ||
end | end | ||
-- 获取难度模式 | |||
-- 获取难度模式 | |||
local function getDifficultyDetails(field) | local function getDifficultyDetails(field) | ||
local checkField = field and string.lower(mw.text.trim(field)) or '' | local checkField = field and string.lower(mw.text.trim(field)) or '' | ||
| 第90行: | 第78行: | ||
if difficultyFields[checkField] == true then | if difficultyFields[checkField] == true then | ||
local mode = checkField:sub(-2) | local mode = checkField:sub(-2) | ||
return checkField:match("^(%d+)b"), mode | return checkField:match("^(%d+)b"), mode | ||
end | end | ||
return nil, nil | return nil, nil | ||
end | end | ||
-- **核心:难度样式应用 ( | -- **核心:难度样式应用 (仅用于表格,并处理可能存在的 'sc' 前缀)** | ||
local function formatDifficultyStyles(valueString, mode) | local function formatDifficultyStyles(valueString, mode) | ||
-- valueString 预期是经过 formatSingleValue 处理的字符串 (例如 '15', ' - ', 或 '无') | -- valueString 预期是经过 formatSingleValue 处理的字符串 (例如 '15', ' - ', 或 '无') | ||
-- 1. 特殊值检查:如果是 '-' 或 '无',直接返回 | |||
if valueString == '-' or valueString == i18n['none'] then | |||
return valueString | |||
end | |||
local displayString = valueString -- 用于最终输出的字符串 (默认为原始字符串) | |||
local numValue = tonumber(valueString) | local numValue = tonumber(valueString) | ||
-- | if mode == 'sc' and numValue == nil then | ||
-- 核心修复:如果是 SC 字段且不是纯数字,则尝试剥离 'sc'/'SC' 前缀进行转换 | |||
local stripped = valueString:match("^[Ss][Cc](%d+)$") | |||
if stripped then | |||
numValue = tonumber(stripped) -- 使用剥离后的数字进行样式判断 | |||
displayString = stripped -- 使用剥离后的数字字符串进行显示 | |||
end | |||
end | |||
-- 如果仍不是数字,则返回原始字符串 | |||
if numValue == nil then | if numValue == nil then | ||
return valueString | return valueString | ||
| 第139行: | 第140行: | ||
if style ~= '' then | if style ~= '' then | ||
-- 返回带样式的纯数字字符串 ( | -- 返回带样式的纯数字字符串 (例如 <span...>15</span>) | ||
return '<span style="' .. style .. '">' .. | return '<span style="' .. style .. '">' .. displayString .. '</span>' | ||
end | end | ||
return | return displayString -- 返回原始数字字符串(例如 8) | ||
end | end | ||
| 第150行: | 第151行: | ||
local isSC = string.match(fieldType, '_sc$') | local isSC = string.match(fieldType, '_sc$') | ||
-- 仅当是 SC | -- 仅当是 SC 字段,且值存在且不为 '-' 或 '无' 时,添加 "sc" 前缀 | ||
if isSC and valueString ~= i18n['none'] and valueString ~= '-' then | if isSC and valueString ~= i18n['none'] and valueString ~= '-' then | ||
return 'sc' .. valueString | if not valueString:lower():find('sc') then | ||
return 'sc' .. valueString | |||
end | |||
end | end | ||
| 第214行: | 第217行: | ||
local formattedValue = formatSingleValue(value, argType) | local formattedValue = formatSingleValue(value, argType) | ||
-- 步骤 2: 应用 SC 前缀 | -- 步骤 2: 应用 SC 前缀 | ||
formattedValue = applySCPrefix(formattedValue, argType) | formattedValue = applySCPrefix(formattedValue, argType) | ||
| 第221行: | 第224行: | ||
return table.concat(resultTable, ' / ') | return table.concat(resultTable, ' / ') | ||
end | end | ||
| 第307行: | 第276行: | ||
local output = {} | local output = {} | ||
-- 表格样式 | -- 表格样式 | ||
table.insert(output, '{| class="wikitable sortable" style="width: 100%; margin: 0 auto; text-align: center;"') | table.insert(output, '{| class="wikitable sortable" style="width: 100%; margin: 0 auto; text-align: center;"') | ||
-- 构造表格头部 | -- 构造表格头部 | ||
table.insert(output, '|-') | table.insert(output, '|-') | ||
for _, field in ipairs(displayFields) do | for _, field in ipairs(displayFields) do | ||
| 第320行: | 第289行: | ||
for _, songId in ipairs(matchingKeys) do | for _, songId in ipairs(matchingKeys) do | ||
local songEntry = songData[songId] | local songEntry = songData[songId] | ||
table.insert(output, '|-') | table.insert(output, '|-') | ||
for _, field in ipairs(displayFields) do | for _, field in ipairs(displayFields) do | ||
field = mw.text.trim(field) | field = mw.text.trim(field) | ||
| 第333行: | 第301行: | ||
-- 步骤 2: **仅在表格中**应用特殊样式 | -- 步骤 2: **仅在表格中**应用特殊样式 | ||
if field == 'bpm' then | if field == 'bpm' then | ||
formattedValue = formatBPMValue(formattedValue) | formattedValue = formatBPMValue(formattedValue) | ||
end | end | ||
local _, mode = getDifficultyDetails(field) | local _, mode = getDifficultyDetails(field) | ||
if mode then | if mode then | ||
-- | -- 核心:formatDifficultyStyles 现在能正确处理 '-' 值 | ||
formattedValue = formatDifficultyStyles(formattedValue, mode) | formattedValue = formatDifficultyStyles(formattedValue, mode) | ||
end | end | ||
-- | -- MediaWiki 表格单元格开始符 ' | ' | ||
table.insert(output, '|' .. formattedValue) | table.insert(output, '|' .. formattedValue) | ||
end | end | ||
| 第352行: | 第318行: | ||
table.insert(output, '|}') | table.insert(output, '|}') | ||
return table.concat(output, '\n') | return table.concat(output, '\n') | ||
end | end | ||
return p | return p | ||