无编辑摘要
无编辑摘要
第100行: 第100行:
end  
end  


-- 获取难度模式,如果不是难度字段则返回 nil。
-- 获取难度模式 (使用哈希表检查,使用 sub 提取模式)
local function getDifficultyMode(field)
local function getDifficultyMode(field)
     local checkField = field and string.lower(mw.text.trim(field)) or ''
     local checkField = field and string.lower(mw.text.trim(field)) or ''
     -- 匹配 Xb_(mode) 并捕获模式,排除 _notes 变体
   
     local mode = checkField:match("^[4568]b_(nm|hd|mx|sc)$")
     -- 哈希表包含所有需要套用 {{df|}} 模板的精准字段
     return mode -- returns nil or 'nm', 'hd', 'mx', or 'sc'
     local difficultyFields = {
        ['4b_nm'] = true, ['4b_hd'] = true, ['4b_mx'] = true, ['4b_sc'] = true,
        ['5b_nm'] = true, ['5b_hd'] = true, ['5b_mx'] = true, ['5b_sc'] = true,
        ['6b_nm'] = true, ['6b_hd'] = true, ['6b_mx'] = true, ['6b_sc'] = true,
        ['8b_nm'] = true, ['8b_hd'] = true, ['8b_mx'] = true, ['8b_sc'] = true,
    }
 
     if difficultyFields[checkField] == true then
        -- 匹配成功,安全提取模式 (最后两个字符: 'nm', 'hd', 'mx', or 'sc')
        return checkField:sub(-2)
    end
   
    return nil
end
end


第161行: 第173行:
         local formattedValue = formatSingleValue(value, argType)
         local formattedValue = formatSingleValue(value, argType)
          
          
         -- 在 p.value 中应用 {{df|}} 模板
         -- 应用 {{df|}} 模板和 SC 前缀逻辑
         local mode = getDifficultyMode(argType)
         local mode = getDifficultyMode(argType)
         if mode then
         if mode then
第281行: 第293行:
             local formattedValue = formatSingleValue(rawValue, field)
             local formattedValue = formatSingleValue(rawValue, field)
              
              
             -- 在 p.generateListTable 中应用 {{df|}} 模板
             -- 应用 {{df|}} 模板和 SC 前缀逻辑
             local mode = getDifficultyMode(field)
             local mode = getDifficultyMode(field)
             if mode then
             if mode then
第291行: 第303行:
             end
             end
              
              
             -- FIX: 移除表格单元格分隔符后的空格
             -- FIX: 移除表格单元格分隔符后的空格以避免解析错误
             table.insert(output, '|' .. formattedValue)
             table.insert(output, '|' .. formattedValue)
         end
         end