模块:中立&怪物卡牌灵光一闪:修订间差异
来自卡厄思梦境WIKI
创建页面,内容为“local p = {} local data = mw.loadData("模块:中立&怪物卡牌灵光一闪/data") -- 分割字符串函数 local function split(str, delimiter) if not str or str == "" then return {} end local result = {} for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match) end return result end -- 检查是否包含某个值 local function contains(str, value) if not str or str == "" then…” |
小无编辑摘要 |
||
| 第93行: | 第93行: | ||
end | end | ||
-- | -- 生成唯一ID | ||
local function | local function generateId() | ||
return tostring(os.time()) .. math.random(1000, 9999) | |||
return tostring( | |||
end | end | ||
| 第256行: | 第103行: | ||
local request = mw.getCurrentFrame():getParent() or frame | local request = mw.getCurrentFrame():getParent() or frame | ||
local args = request.args | local args = request.args | ||
-- 获取筛选参数 | -- 获取筛选参数 | ||
local filters = { | local filters = { | ||
type = args | type = args.type or "", | ||
dict_include = args | dict_include = args.dict_include or "", | ||
dict_exclude = args | dict_exclude = args.dict_exclude or "", | ||
class = args.class | class = args.class or "", | ||
cost_min = args | cost_min = args.cost_min or "", | ||
cost_max = args | cost_max = args.cost_max or "" | ||
} | } | ||
| 第282行: | 第120行: | ||
local output = "" | local output = "" | ||
-- | -- 添加筛选表单Widget | ||
output = output .. "== 筛选条件 ==\n" | output = output .. "== 筛选条件 ==\n" | ||
local widgetId = generateId() | |||
output = output .. | output = output .. frame:extensionTag{ | ||
name = 'widget', | |||
args = { id = widgetId }, | |||
content = 'CardFilter' | |||
} | |||
-- 显示当前筛选信息 | -- 显示当前筛选信息 | ||
2025年11月3日 (一) 13:30的版本
此模块的文档可以在模块:中立&怪物卡牌灵光一闪/doc创建
local p = {}
local data = mw.loadData("模块:中立&怪物卡牌灵光一闪/data")
-- 分割字符串函数
local function split(str, delimiter)
if not str or str == "" then
return {}
end
local result = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end
-- 检查是否包含某个值
local function contains(str, value)
if not str or str == "" then
return false
end
local items = split(str, "、")
for _, item in ipairs(items) do
if item == value then
return true
end
end
return false
end
-- 检查费用范围
local function checkCost(item, minCost, maxCost)
if minCost and tonumber(minCost) then
if item.cost_min < tonumber(minCost) then
return false
end
end
if maxCost and tonumber(maxCost) then
if item.cost_max > tonumber(maxCost) then
return false
end
end
return true
end
-- 筛选函数
local function filterData(filters)
local result = {}
for _, item in ipairs(data) do
local match = true
-- 筛选类型
if filters.type and filters.type ~= "" and filters.type ~= "全部" then
if not item.type or not contains(item.type, filters.type) then
match = false
end
end
-- 筛选包含机制
if match and filters.dict_include and filters.dict_include ~= "" and filters.dict_include ~= "全部" then
if not item.dict_include or not contains(item.dict_include, filters.dict_include) then
match = false
end
end
-- 筛选排除机制
if match and filters.dict_exclude and filters.dict_exclude ~= "" and filters.dict_exclude ~= "全部" then
if not item.dict_exclude or not contains(item.dict_exclude, filters.dict_exclude) then
match = false
end
end
-- 筛选职业
if match and filters.class and filters.class ~= "" and filters.class ~= "全部" then
if not item.class or not contains(item.class, filters.class) then
match = false
end
end
-- 筛选费用
if match then
if not checkCost(item, filters.cost_min, filters.cost_max) then
match = false
end
end
if match then
table.insert(result, item)
end
end
return result
end
-- 生成唯一ID
local function generateId()
return tostring(os.time()) .. math.random(1000, 9999)
end
-- 主函数
function p.show(frame)
-- 获取URL参数
local request = mw.getCurrentFrame():getParent() or frame
local args = request.args
-- 获取筛选参数
local filters = {
type = args.type or "",
dict_include = args.dict_include or "",
dict_exclude = args.dict_exclude or "",
class = args.class or "",
cost_min = args.cost_min or "",
cost_max = args.cost_max or ""
}
-- 筛选数据
local filteredData = filterData(filters)
-- 构建输出
local output = ""
-- 添加筛选表单Widget
output = output .. "== 筛选条件 ==\n"
local widgetId = generateId()
output = output .. frame:extensionTag{
name = 'widget',
args = { id = widgetId },
content = 'CardFilter'
}
-- 显示当前筛选信息
local hasFilter = false
local filterInfo = ""
if filters.type and filters.type ~= "" then
filterInfo = filterInfo .. "* 类型: " .. filters.type .. "\n"
hasFilter = true
end
if filters.dict_include and filters.dict_include ~= "" then
filterInfo = filterInfo .. "* 包含机制: " .. filters.dict_include .. "\n"
hasFilter = true
end
if filters.dict_exclude and filters.dict_exclude ~= "" then
filterInfo = filterInfo .. "* 排除机制: " .. filters.dict_exclude .. "\n"
hasFilter = true
end
if filters.class and filters.class ~= "" then
filterInfo = filterInfo .. "* 职业: " .. filters.class .. "\n"
hasFilter = true
end
if filters.cost_min and filters.cost_min ~= "" then
filterInfo = filterInfo .. "* 最低费用: " .. filters.cost_min .. "\n"
hasFilter = true
end
if filters.cost_max and filters.cost_max ~= "" then
filterInfo = filterInfo .. "* 最高费用: " .. filters.cost_max .. "\n"
hasFilter = true
end
if hasFilter then
output = output .. "\n=== 当前筛选 ===\n" .. filterInfo
end
-- 构建表格
output = output .. "\n== 结果 ==\n"
local html = mw.html.create('table')
html:addClass('wikitable sortable')
-- 表头
local headerRow = html:tag('tr')
headerRow:tag('th'):wikitext('描述')
headerRow:tag('th'):wikitext('最低费用')
headerRow:tag('th'):wikitext('最高费用')
headerRow:tag('th'):wikitext('类型')
headerRow:tag('th'):wikitext('包含机制')
headerRow:tag('th'):wikitext('排除机制')
headerRow:tag('th'):wikitext('职业')
-- 数据行
for _, item in ipairs(filteredData) do
local row = html:tag('tr')
row:tag('td'):wikitext(item.desc_global or "")
row:tag('td'):wikitext(tostring(item.cost_min))
row:tag('td'):wikitext(tostring(item.cost_max))
row:tag('td'):wikitext(item.type or "")
row:tag('td'):wikitext(item.dict_include or "")
row:tag('td'):wikitext(item.dict_exclude or "")
row:tag('td'):wikitext(item.class or "")
end
output = output .. tostring(html)
output = output .. "\n\n''共 " .. #filteredData .. " 条结果''"
return output
end
return p