模块:Db:修订间差异
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
||
| (未显示同一用户的10个中间版本) | |||
| 第20行: | 第20行: | ||
['title'] = '歌曲标题', ['composer'] = '艺术家', ['bpm'] = 'BPM', ['singer'] = '歌手', ['genre'] = '流派', | ['title'] = '歌曲标题', ['composer'] = '艺术家', ['bpm'] = 'BPM', ['singer'] = '歌手', ['genre'] = '流派', | ||
['id'] = '歌曲ID', ['key'] = 'KEY音', ['bga'] = 'BGA作者', ['duration'] = '时长', | ['id'] = '歌曲ID', ['key'] = 'KEY音', ['bga'] = 'BGA作者', ['duration'] = '时长', | ||
['pack'] = '曲包', | ['pack'] = '曲包', | ||
['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', | ||
| 第29行: | 第29行: | ||
['8b_nm'] = '8B NM', ['8b_nm_notes'] = '8B NM', ['8b_hd'] = '8B HD', ['8b_hd_notes'] = '8B HD', | ['8b_nm'] = '8B NM', ['8b_nm_notes'] = '8B NM', ['8b_hd'] = '8B HD', ['8b_hd_notes'] = '8B HD', | ||
['8b_mx'] = '8B MX', ['8b_mx_notes'] = '8B MX', ['8b_sc'] = '8B SC', ['8b_sc_notes'] = '8B SC', | ['8b_mx'] = '8B MX', ['8b_mx_notes'] = '8B MX', ['8b_sc'] = '8B SC', ['8b_sc_notes'] = '8B SC', | ||
} | |||
-- **Pack 缩写映射表(用户输入缩写 -> 完整包名,键使用大写以便不区分大小写查询)** | |||
local packAbbreviations = { | |||
['VL'] = 'V LIBERTY', | |||
['VL2'] = 'V LIBERTY 2', | |||
['VL3'] = 'V LIBERTY 3', | |||
['VE'] = 'V EXTENSION', | |||
['VE2'] = 'V EXTENSION 2', | |||
['VE3'] = 'V EXTENSION 3', | |||
['VE4'] = 'V EXTENSION 4', | |||
['VE5'] = 'V EXTENSION 5', | |||
['P1'] = 'PORTABLE 1', | |||
['P2'] = 'PORTABLE 2', | |||
['P3'] = 'PORTABLE 3', | |||
['CE'] = 'CLAZZIQUAI', | |||
['BS'] = 'BLACK SQUARE', | |||
['TR'] = 'TRILOGY', | |||
['T1'] = 'TECHNIKA', | |||
['T2'] = 'TECHNIKA 2', | |||
['T3'] = 'TECHNIKA 3', | |||
['R'] = 'RESPECT', | |||
['RV'] = 'RESPECT V', | |||
['ARC'] = 'ARCAEA', | |||
['BA'] = 'BLUE ARCHIVE', | |||
['CY'] = 'CYTUS', | |||
['CHU'] = 'CHUNITHM', | |||
['DE'] = 'DEEMO', | |||
['EZ'] = 'EZ2ON', | |||
['GC'] = 'GROOVE COASTER', | |||
['MD'] = 'MUSE DASH', | |||
['ESTI'] = 'ESTIMATE', | |||
['FC'] = 'FALCOM', | |||
['GF'] = 'GIRL\'S FRONTLINE', | |||
['GG'] = 'GUILTY GEAR', | |||
['MAP'] = 'MAPLESTORY', | |||
['NXN'] = 'NEXON', | |||
['TK'] = 'TEKKEN', | |||
['TB1'] = 'PLI: TRIBUTE VOL.1', | |||
['645141'] = 'PLI: 64514 VOL.1', | |||
} | } | ||
| 第44行: | 第84行: | ||
return nil | return nil | ||
end | end | ||
-- **Pack 缩写解析** | |||
local function resolvePackValue(input) | |||
if type(input) ~= 'string' then | |||
return input | |||
end | |||
-- 尝试查找缩写(不区分大小写,因为 packAbbreviations 的键是大写) | |||
local upperInput = string.upper(input) | |||
if packAbbreviations[upperInput] then | |||
return packAbbreviations[upperInput] | |||
end | |||
-- 找不到缩写,返回原始输入 | |||
return input | |||
end | |||
local function formatSingleValue(value, fieldType) | local function formatSingleValue(value, fieldType) | ||
| 第62行: | 第116行: | ||
end | end | ||
return valueString | return valueString | ||
end | |||
-- **格式化 key 值 (仅在表格中使用)** | |||
local function formatKeyValue(value) | |||
if type(value) == 'boolean' then | |||
local color = value and 'green' or 'red' | |||
local text = value and i18n['true'] or i18n['false'] | |||
return '<span style="color:' .. color .. ';">' .. text .. '</span>' | |||
end | |||
return tostring(value) | |||
end | end | ||
| 第141行: | 第205行: | ||
local numValue = tonumber(valueString) | local numValue = tonumber(valueString) | ||
if numValue and numValue >= 2000 then | if numValue and numValue >= 2000 then | ||
local content = valueString | local content = valueString | ||
if context == 'table' then | if context == 'table' then | ||
-- | -- --- 表格环境 (高优先级颜色 + 加粗) --- | ||
return '<span style="font-weight: bold; color: red;">' .. content .. '</span>' | if numValue >= 3000 then | ||
-- Table, >= 3000: 紫色加粗 | |||
return '<span style="font-weight: bold; color: purple;">' .. content .. '</span>' | |||
elseif numValue >= 2000 then | |||
-- Table, 2000 <= X < 3000: 红色加粗 | |||
return '<span style="font-weight: bold; color: red;">' .. content .. '</span>' | |||
end | |||
else | else | ||
-- | -- --- 非表格环境 (仅加粗) --- | ||
return '<b>' .. content .. '</b>' | return '<b>' .. content .. '</b>' | ||
end | end | ||
end | end | ||
-- 如果小于 2000,返回原始字符串 | |||
return valueString | return valueString | ||
end | end | ||
| 第182行: | 第252行: | ||
return value | return value | ||
end), | end), | ||
-- key 字段在非表格环境中的默认处理 (例如 p.value 调用) | |||
['key'] = (function(value) | |||
if type(value) == 'boolean' then | |||
return value and i18n['true'] or i18n['false'] | |||
end | |||
return tostring(value) | |||
end) | |||
} | } | ||
| 第224行: | 第301行: | ||
local value = ValueFromValuesByKey(songEntry, argType) | local value = ValueFromValuesByKey(songEntry, argType) | ||
-- 使用 formatSingleValue 处理 BPM/Duration/Key(boolean->text) 等映射 | |||
local formattedValue = formatSingleValue(value, argType) | local formattedValue = formatSingleValue(value, argType) | ||
formattedValue = applySCPrefix(formattedValue, argType) | formattedValue = applySCPrefix(formattedValue, argType) | ||
| 第246行: | 第325行: | ||
local displayFieldsString = mw.text.trim(args.columns or '') | local displayFieldsString = mw.text.trim(args.columns or '') | ||
local isPackFilter = (conditionField == 'pack') -- 定义 pack 筛选标记 | |||
-- ** 预处理 conditionValue ** | |||
if type(conditionValue) == 'string' then | if type(conditionValue) == 'string' then | ||
local trimmedValue = mw.text.trim(conditionValue) | local trimmedValue = mw.text.trim(conditionValue) | ||
local lowerValue = string.lower(trimmedValue) | local lowerValue = string.lower(trimmedValue) | ||
if lowerValue == 'true' or trimmedValue == '是' then | if lowerValue == 'true' or trimmedValue == '是' then | ||
conditionValue = true | conditionValue = true | ||
| 第256行: | 第339行: | ||
else | else | ||
local num = tonumber(trimmedValue) | local num = tonumber(trimmedValue) | ||
if num ~= nil then | -- 核心修复:如果是 Pack 筛选,即使能转为数字也不转,保持字符串以便后续缩写解析和不区分大小写比较 | ||
if num ~= nil and not isPackFilter then | |||
conditionValue = num | conditionValue = num | ||
else | else | ||
| 第273行: | 第357行: | ||
local shouldFilter = conditionValue ~= nil | local shouldFilter = conditionValue ~= nil | ||
-- 如果是 pack 筛选,提前解析 conditionValue 以支持缩写 | |||
local resolvedConditionValue = nil | |||
if isPackFilter and type(conditionValue) == 'string' then | |||
resolvedConditionValue = resolvePackValue(conditionValue) | |||
end | |||
for songId, songEntry in pairs(songData) do | for songId, songEntry in pairs(songData) do | ||
| 第279行: | 第370行: | ||
else | else | ||
local currentValue = ValueFromValuesByKey(songEntry, conditionField) | local currentValue = ValueFromValuesByKey(songEntry, conditionField) | ||
local match = false | |||
-- 1. 数字和布尔值的精确匹配 | |||
if currentValue == conditionValue then | if currentValue == conditionValue then | ||
match = true | |||
-- 2. 字符串匹配 | |||
elseif type(currentValue) == 'string' and type(conditionValue) == 'string' then | |||
-- 2a. Pack 字段: 缩写解析后的精确匹配 (Case-insensitive Exact Match) | |||
if isPackFilter then | |||
local targetValue = resolvedConditionValue -- 这会是完整的包名或原始输入 | |||
if string.upper(currentValue) == string.upper(targetValue) then | |||
match = true | |||
end | |||
-- 2b. 其他字符串字段: 模糊匹配 (Case-insensitive Fuzzy Match) | |||
else | |||
local searchString = conditionValue | |||
-- 模糊匹配:只要 currentValue 包含 searchString(不区分大小写) | |||
if string.find(string.upper(currentValue), string.upper(searchString), 1, true) then | |||
match = true | |||
end | |||
end | |||
end | |||
if match then | |||
table.insert(matchingKeys, songId) | table.insert(matchingKeys, songId) | ||
end | end | ||
| 第292行: | 第411行: | ||
local output = {} | local output = {} | ||
-- 检查是否需要禁用宽度设置 | |||
local disableWidths = (#displayFields <= 8) | |||
-- 表格样式 | -- 表格样式 | ||
| 第306行: | 第428行: | ||
local separator = ' ' -- 默认分隔符是空格 | local separator = ' ' -- 默认分隔符是空格 | ||
if | if not disableWidths then -- 宽度要求失效检查 | ||
headerStyle = ' style="width: | -- BPM/Key/Duration 字段,固定宽度 6% | ||
if field == 'bpm' or field == 'key' or field == 'duration' then | |||
headerStyle = ' style="width: 6%;"' | |||
separator = ' | ' | |||
-- Pack 字段,固定宽度 10% | |||
elseif field == 'pack' then | |||
headerStyle = ' style="width: 10%;"' | |||
separator = ' | ' | |||
elseif mode then -- 谱面难度字段 (3.2% 固定宽度) | |||
headerStyle = ' style="width: 3.2%;"' | |||
separator = ' | ' | |||
elseif string.match(field, '_notes$') then -- NOTES 字段 (4% 固定宽度) | |||
headerStyle = ' style="width: 4%;"' | |||
separator = ' | ' | |||
end | |||
end | end | ||
| 第330行: | 第459行: | ||
local rawValue = ValueFromValuesByKey(songEntry, field) | local rawValue = ValueFromValuesByKey(songEntry, field) | ||
-- 获取格式化的值 | |||
local formattedValue = formatSingleValue(rawValue, field) | local formattedValue = formatSingleValue(rawValue, field) | ||
-- 应用内容样式 | -- 应用内容样式 (BPM/Key) | ||
if field == 'bpm' then | if field == 'bpm' then | ||
formattedValue = formatBPMValue(formattedValue) | formattedValue = formatBPMValue(formattedValue) | ||
elseif field == 'key' then | |||
formattedValue = formatKeyValue(rawValue) -- 对 key 字段应用颜色逻辑,使用原始值 (rawValue) | |||
end | end | ||
| 第342行: | 第475行: | ||
end | end | ||
-- *** NOTES 字段样式逻辑 (包含 _sc_notes 默认颜色) *** | |||
if string.match(field, '_notes$') then | if string.match(field, '_notes$') then | ||
-- | local numValue = tonumber(rawValue) | ||
formattedValue = formatNotesValue(formattedValue, 'table') | |||
-- 1. 检查是否为高优先级(>= 2000/3000) | |||
if numValue and numValue >= 2000 then | |||
-- 高优先级:应用红/紫色的 formatNotesValue | |||
formattedValue = formatNotesValue(formattedValue, 'table') | |||
-- 2. 检查是否为所有 _sc_notes 字段且为低优先级(< 2000) | |||
elseif string.match(field, '_sc_notes$') then | |||
-- sc_notes 默认颜色:3d66ff (如果值不是高优先级) | |||
formattedValue = '<span style="color: #3d66ff;">' .. formattedValue .. '</span>' | |||
end | |||
end | end | ||