词典表格:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
小无编辑摘要 |
||
| 第4行: | 第4行: | ||
function p.renderTable(frame) | function p.renderTable(frame) | ||
local result = {} | local result = {} | ||
local rows = {} | |||
-- | -- 收集所有数据到rows表中 | ||
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(rows, { | ||
local | 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, | |||
["角色专属词条"] = 3, | |||
["buff"] = 4, | |||
["debuff"] = 5 | |||
} | |||
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 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 | end | ||
2025年10月9日 (四) 14:13的版本
此模块的文档可以在模块:词典表格/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,
["角色专属词条"] = 3,
["buff"] = 4,
["debuff"] = 5
}
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