词典表格:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
小无编辑摘要 |
||
| (未显示同一用户的5个中间版本) | |||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local data = | local data = require('Module:词典/data') | ||
function p. | 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( | 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( | table.sort(rows, function(a, b) | ||
local | -- 首先按类型排序 | ||
if a.type ~= b.type then | |||
-- 定义类型排序优先级 | |||
return a. | 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 | -- 如果类型相同,按名称排序 | ||
return a.name < b.name | |||
end) | end) | ||
-- | -- 生成表格行 | ||
for _, | for _, row in ipairs(rows) do | ||
local | local rowHtml = {} | ||
table.insert(rowHtml, '|-') | |||
table.insert( | |||
-- | -- 添加数据属性用于筛选 | ||
table.insert( | 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( | -- 类型单元格 | ||
table.insert(rowHtml, '\n|style="text-align:center;"|' .. row.type) | |||
-- | -- 描述单元格 | ||
table.insert( | table.insert(rowHtml, '\n|' .. row.description) | ||
table.insert(result, ' | table.insert(result, table.concat(rowHtml, ' ')) | ||
end | end | ||
return table.concat(result, '\n') | |||
return | |||
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