模块

模块:词典表格

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献2025年10月9日 (四) 14:14的版本

此模块的文档可以在模块:词典表格/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|' .. row.icon)
        
        -- 名称单元格
        table.insert(rowHtml, '\n|' .. row.name)
        
        -- 类型单元格
        table.insert(rowHtml, '\n|' .. row.type)
        
        -- 描述单元格
        table.insert(rowHtml, '\n|' .. row.description)
        
        table.insert(result, table.concat(rowHtml, ' '))
    end
    
    return table.concat(result, '\n')
end

return p