模块

词典表格:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local data = mw.loadData("模块:词典/data")
local data = require('Module:词典/data')


function p.makeTable(frame)
function p.renderTable(frame)
     local result = {}
     local result = {}
    local rows = {}
      
      
     -- 表格开始
     -- 收集所有数据到rows表中
    table.insert(result, '<table class="wikitable sortable" style="width:100%" id="CardSelectTr">')
   
    -- 表头
    table.insert(result, '<thead>')
    table.insert(result, '<tr id="CardSelectTabHeader">')
    table.insert(result, '<th style="width:80px" class="dataHeader">图标</th>')
    table.insert(result, '<th style="width:150px" class="dataHeader headerSort">名称</th>')
    table.insert(result, '<th style="width:150px" class="dataHeader headerSort">类型</th>')
    table.insert(result, '<th class="dataHeader">描述</th>')
    table.insert(result, '</tr>')
    table.insert(result, '</thead>')
   
    -- 表格主体
    table.insert(result, '<tbody>')
   
    -- 先收集所有数据并排序
    local allEntries = {}
     for name, entries in pairs(data.dictionary) do
     for name, entries in pairs(data.dictionary) do
         for _, entry in ipairs(entries) do
         for _, entry in ipairs(entries) do
             table.insert(allEntries, {
             table.insert(rows, {
                 name = name,
                 name = name,
                 entry = entry
                 icon = entry["icon"] or "",
                type = entry["类型"] or "",
                color = entry["颜色"] or "",
                description = entry["描述"] or ""
             })
             })
         end
         end
第33行: 第20行:
      
      
     -- 按类型排序
     -- 按类型排序
     table.sort(allEntries, function(a, b)
     table.sort(rows, function(a, b)
         local typeA = a.entry['类型'] or ''
         -- 首先按类型排序
        local typeB = b.entry['类型'] or ''
        if a.type ~= b.type then
        if typeA == typeB then
            -- 定义类型排序优先级
             return a.name < b.name
            local typeOrder = {
                ["卡牌机制"] = 1,
                ["战斗员专属机制"] = 2,
                ["buff"] = 3,
                ["debuff"] = 4
            }
            local orderA = typeOrder[a.type] or 999
            local orderB = typeOrder[b.type] or 999
           
            if orderA ~= orderB then
                return orderA < orderB
            end
             return a.type < b.type
         end
         end
         return typeA < typeB
        -- 如果类型相同,按名称排序
         return a.name < b.name
     end)
     end)
      
      
     -- 遍历排序后的数据
     -- 生成表格行
     for _, item in ipairs(allEntries) do
     for _, row in ipairs(rows) do
         local name = item.name
         local rowHtml = {}
        local entry = item.entry
         table.insert(rowHtml, '|-')
        local dataType = entry['类型'] or ''
        local dataColor = entry['颜色'] or ''
       
         table.insert(result, string.format('<tr data-param类型="%s" data-param颜色="%s">',
            mw.text.encode(dataType), mw.text.encode(dataColor)))
       
        -- 图标列
        if entry['icon'] and entry['icon'] ~= '' then
            table.insert(result, '<td>[[File:' .. entry['icon'] .. '|50px]]</td>')
        else
            table.insert(result, '<td>暂无图标</td>')
        end
          
          
         -- 名称列
         -- 添加数据属性用于筛选
         table.insert(result, '<td>' .. mw.text.encode(name) .. '</td>')
         table.insert(rowHtml, string.format('data-param1="%s"', row.type))
          
          
         -- 类型列(添加颜色)
         -- 图标单元格
         local typeText = entry['类型'] or ''
         table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.icon)
        local color = entry['颜色'] or ''
        local colorStyle = ''
          
          
         if color == '橙' then
         -- 名称单元格
            colorStyle = ' style="color:#ff8c00"'
         table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.name)
        elseif color == '蓝' then
            colorStyle = ' style="color:#4169E1"'
         elseif color == '红' then
            colorStyle = ' style="color:#DC143C"'
        end
          
          
         table.insert(result, '<td' .. colorStyle .. '>' .. mw.text.encode(typeText) .. '</td>')
        -- 类型单元格
         table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.type)
          
          
         -- 描述列
         -- 描述单元格
         table.insert(result, '<td>' .. (entry['描述'] or '') .. '</td>')
         table.insert(rowHtml, '\n|' .. row.description)
          
          
         table.insert(result, '</tr>')
         table.insert(result, table.concat(rowHtml, ' '))
     end
     end
      
      
    table.insert(result, '</tbody>')
     return table.concat(result, '\n')
    table.insert(result, '</table>')
   
     return frame:preprocess(table.concat(result, '\n'))
end
end


return p
return p

2025年10月9日 (四) 14:17的最新版本

此模块的文档可以在模块:词典表格/doc创建

local p = {}
local data = require('Module:词典/data')

function p.renderTable(frame)
    local result = {}
    local rows = {}
    
    -- 收集所有数据到rows表中
    for name, entries in pairs(data.dictionary) do
        for _, entry in ipairs(entries) do
            table.insert(rows, {
                name = name,
                icon = entry["icon"] or "",
                type = entry["类型"] or "",
                color = entry["颜色"] or "",
                description = entry["描述"] or ""
            })
        end
    end
    
    -- 按类型排序
    table.sort(rows, function(a, b)
        -- 首先按类型排序
        if a.type ~= b.type then
            -- 定义类型排序优先级
            local typeOrder = {
                ["卡牌机制"] = 1,
                ["战斗员专属机制"] = 2,
                ["buff"] = 3,
                ["debuff"] = 4
            }
            local orderA = typeOrder[a.type] or 999
            local orderB = typeOrder[b.type] or 999
            
            if orderA ~= orderB then
                return orderA < orderB
            end
            return a.type < b.type
        end
        -- 如果类型相同,按名称排序
        return a.name < b.name
    end)
    
    -- 生成表格行
    for _, row in ipairs(rows) do
        local rowHtml = {}
        table.insert(rowHtml, '|-')
        
        -- 添加数据属性用于筛选
        table.insert(rowHtml, string.format('data-param1="%s"', row.type))
        
        -- 图标单元格
        table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.icon)
        
        -- 名称单元格
        table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.name)
        
        -- 类型单元格
        table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.type)
        
        -- 描述单元格
        table.insert(rowHtml, '\n|' .. row.description)
        
        table.insert(result, table.concat(rowHtml, ' '))
    end
    
    return table.concat(result, '\n')
end

return p