全站通知:
模块:提取深网代码数据
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:提取深网代码数据/doc创建
local p = {}
function p.getData()
local jsonText = mw.title.new("data:AbyssalChaos/Codes.json"):getContent()
if not jsonText then
return "找不到json文件内容"
end
-- 解析 json 内容
local data = mw.text.jsonDecode(jsonText)
if not data then
return "无法解析json内容"
end
-- 整理 json 数据
local qualityOrder = {
["蓝"] = 1,
["紫"] = 2,
["金"] = 3,
["红"] = 4,
}
table.sort(data, function(a,b)
if a["代码大类"] ~= b["代码大类"] then
return a["代码大类"] < b["代码大类"]
end
if a["代码小类"] ~= b["代码小类"] then
return a["代码小类"] < b["代码小类"]
end
return (qualityOrder[b["代码品质"]] or 0) < (qualityOrder[a["代码品质"]] or 0)
end)
return data
end
-- 用于在模板中调用
function p.show(frame)
local data = p.getData()
if type(data) ~= "table" then
return data
end
local root = mw.html.create()
local qualityClass = {
["紫"] = "purple-icon",
["红"] = "red-icon",
["蓝"] = "blue-icon",
["金"] = "gold-icon",
}
for _, code in ipairs(data) do
local iconClass = qualityClass[code["代码品质"]] or ""
local desc = "<b>初始效果:</b>"..code["初始效果"]
if code["升级效果"] and code["升级效果"] ~= "" then
desc = desc .. "<br>" .. "<br>" .. "<b>升级效果:</b>"..code["升级效果"]
end
-- 拼模板参数
local args = {
["名称"] = code["代码名称"],
["显示名称"] = code["代码名称"],
["显示图片"] = (code["代码大类"] == "专属") and code["代码大类"] or code["代码小类"],
["品质"] = code["代码品质"],
["描述"] = desc,
["获取途径"] = "混沌深网",
["角色"] = code["男主"],
["初始效果"] = code["初始效果"],
["效果备注"] = code["效果备注"],
["升级效果"] = code["升级效果"],
["代码大类"] = code["代码大类"],
["代码小类"] = code["代码小类"],
["背景色"] = iconClass
}
local html = frame:expandTemplate{ title = "深网代码/个", args = args }
root:wikitext(html)
end
return tostring(root)
end
return p