模块

词典表格:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的6个中间版本)
第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 html = mw.html.create()
     local result = {}
    local rows = {}
      
      
     -- 创建表格
     -- 收集所有数据到rows表中
    local table = html:tag('table')
        :addClass('wikitable sortable')
        :css('width', '100%')
        :attr('id', 'CardSelectTr')
   
    -- 创建表头
    local thead = table:tag('thead'):tag('tr'):attr('id', 'CardSelectTabHeader')
    thead:tag('th'):css('width', '80px'):wikitext('图标'):addClass('dataHeader')
    thead:tag('th'):css('width', '150px'):wikitext('名称'):addClass('dataHeader headerSort')
    thead:tag('th'):css('width', '150px'):wikitext('类型'):addClass('dataHeader headerSort')
    thead:tag('th'):wikitext('描述'):addClass('dataHeader')
   
    -- 创建表格主体
    local tbody = table:tag('tbody')
   
    -- 遍历数据
     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
             local row = tbody:tag('tr')
             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
              
              
            -- 使用 cssText 方法添加 data 属性
             if orderA ~= orderB then
            local dataType = entry['类型'] or ''
                 return orderA < orderB
            local dataColor = entry['颜色'] or ''
            row:attr('data-paramType', dataType)  -- 改用英文属性名
            row:attr('data-paramColor', dataColor)
           
            -- 图标列
             if entry['icon'] and entry['icon'] ~= '' then
                 row:tag('td'):wikitext('[[File:' .. entry['icon'] .. '|50px]]')
            else
                row:tag('td'):wikitext('暂无图标')
             end
             end
              
             return a.type < b.type
            -- 名称列
            row:tag('td'):wikitext(name)
           
            -- 类型列(添加颜色)
            local typeCell = row:tag('td')
            local typeText = entry['类型'] or ''
            local color = entry['颜色'] or ''
           
            if color == '橙' then
                typeCell:css('color', '#ff8c00'):wikitext(typeText)
            elseif color == '蓝' then
                typeCell:css('color', '#4169E1'):wikitext(typeText)
            elseif color == '红' then
                typeCell:css('color', '#DC143C'):wikitext(typeText)
            else
                typeCell:wikitext(typeText)
            end
           
            -- 描述列
            row:tag('td'):wikitext(entry['描述'] or '')
         end
         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
     end
      
      
     return tostring(html)
     return 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