模块:LevelInfo
外观
local p = {}
-- 数据定义
local levelData = {
["1-1"] = {
name = "日光之塔",
challenge = "0",
rewards = "金矿",
gamemode = "经典模式",
gametime = "1",
startgold = "260",
startcrystal = "0",
sizex = "29",
sizey = "13",
goldore = "0",
crystalore = "0"
},
["1-1A"] = {
name = "(日光之塔)",
challenge = "1",
belongsto = "1-1",
gamemode = "固定选卡模式",
gametime = "1",
startgold = "300",
startcrystal = "15",
sizex = "29",
sizey = "13",
goldore = "0",
crystalore = "0"
},
}
-- wikitext
function p.render(frame)
-- 获取当前页面标题
local title = mw.title.getCurrentTitle()
if not title then
return "错误:无法获取当前页面标题。"
end
local pageKey = title.prefixedText
local data = levelData[pageKey]
if not data then
return "该关卡暂无信息(" .. pageKey .. " 未配置)。"
end
-- 构建wikitext
local lines = {}
-- table.insert(lines, "== " .. pageKey .. " " .. data.name .. " ==")
-- table.insert(lines, "{{}}")
-- table.insert(lines, "<div style=\"max-width: 100%; height: auto;\">[[文件:" .. pageKey .. ".png]]</div>")
table.insert(lines, "游戏模式: " .. (data.gamemode or "未知"))
table.insert(lines, "关卡时长: 共 " .. (data.gametime or "未知") .. "天")
table.insert(lines, "初始资源: {{gc|" .. (data.startgold or "未知") .. "|" .. (data.startcrystal or "未知") .. "}}")
table.insert(lines, "金矿矿地: {{c|g|" .. (data.goldore or "未知") .. "}}")
table.insert(lines, "水晶矿矿地: {{c|c|" .. (data.crystalore or "未知") .. "}}")
table.insert(lines, "关卡大小: " .. (data.sizex or "未知") .. " * " .. (data.sizey or "未知"))
-- 可选字段
if data.hpmultiplier then
table.insert(lines, "关内倍率: " .. data.hpmultiplier)
end
-- 用换行符连接
return frame:preprocess(table.concat(lines, "\n\n"))
end
return p