跳转到内容

模块:LevelInfo:修订间差异

来自Minimalist Tower Defense Wiki
无编辑摘要
不再需要
 
(未显示3个用户的15个中间版本)
第1行: 第1行:
local p = {}
local p = {}


-- 数据定义
-- 加载数据子模块
 
-- 从 [[Module:LevelInfo/data]] 获取数据
local names = {
    ["1-1"]  = "日光之塔",
    ["1-1A"]  = "(日光之塔)",
}
 
local challenges = {
    ["1-1"]  = "0",
    ["1-1A"] = "1",
}
 
local belongstos = {
    ["1-1A"]  = "1-1",
   
}
 
local rewards = {
    ["1-1"]   = "金矿",
   
}
 
local gamemodes = {
    ["1-1"]  = "经典模式",
    ["1-1A"]  = "固定选卡模式",
}
 
local gametimes = {
    ["1-1"]  = "1",
    ["1-1A"]  = "1",
}
 
local startgolds = {
    ["1-1"]  = "260",
    ["1-1A"]  = "300",
}


local startcrystals = {
local dataTables = require('Module:LevelInfo/data')
    ["1-1"]  = "0",
    ["1-1A"]  = "15",
}
 
local sizexs = {
    ["1-1"]  = "29",
    ["1-1A"]  = "29",
}
 
local sizeys = {
    ["1-1"]  = "13",
    ["1-1A"]  = "13",
}
 
local goldores = {
    ["1-1"]  = "0",
    ["1-1A"]  = "0",
}
 
local crystalores = {
    ["1-1"]  = "0",
    ["1-1A"]  = "0",
}
 
-- 可选属性
local hpmultipliers = {
    -- ["1-1"] = "1.0",
}
 
-- 图片数据
local imgs = {
    ["1-1"]  = "1-1",
    ["1-1A"]  = "1-1",
}
 
local imgd2s = {
    -- ["1-1"] = "1-1d2",
}
 
local imgd3s = {
    -- ["1-1"] = "1-1d3",
}
 
local imgd4s = {
    -- ["1-1"] = "1-1d4",
}
 
local imgd5s = {
    -- ["1-1"] = "1-1d5",
}
 
local imgd6s = {
    -- ["1-1"] = "1-1d6",
}
 
-- 消息框相关
local stamps = {
    -- ["1-A"] = "6",
}
 
local nopauses = {
    -- ["1-8"] = true,
}
 
-- ===========================================


local function getValue(tbl, key, default)
local function getValue(tbl, key, default)
第125行: 第27行:


     -- 检查是否存在
     -- 检查是否存在
     if names[pageKey] == nil then
     if dataTables.names[pageKey] == nil then
         return "该关卡暂无信息(" .. pageKey .. " 未配置)。"
         return "该关卡暂无信息(" .. pageKey .. " 未配置)。"
     end
     end
第131行: 第33行:
     -- 组装属性
     -- 组装属性
     local data = {
     local data = {
         name = getValue(names, pageKey, "未知"),
         name = getValue(dataTables.names, pageKey, "未知"),
         challenge = getValue(challenges, pageKey, "未知"),
         challenge = getValue(dataTables.challenges, pageKey, "未知"),
         belongsto = getValue(belongstos, pageKey, nil),
         belongsto = getValue(dataTables.belongstos, pageKey, nil),
         reward = getValue(rewards, pageKey, nil),
         reward = getValue(dataTables.rewards, pageKey, nil),
         gamemode = getValue(gamemodes, pageKey, "未知"),
         gamemode = getValue(dataTables.gamemodes, pageKey, "未知"),
         gametime = getValue(gametimes, pageKey, "未知"),
         gametime = getValue(dataTables.gametimes, pageKey, "未知"),
         startgold = getValue(startgolds, pageKey, "未知"),
         startgold = getValue(dataTables.startgolds, pageKey, "未知"),
         startcrystal = getValue(startcrystals, pageKey, "未知"),
         startcrystal = getValue(dataTables.startcrystals, pageKey, "未知"),
         sizex = getValue(sizexs, pageKey, "未知"),
         goldore = getValue(dataTables.goldores, pageKey, "未知"),
         sizey = getValue(sizeys, pageKey, "未知"),
         crystalore = getValue(dataTables.crystalores, pageKey, "未知"),
         goldore = getValue(goldores, pageKey, "未知"),
         sizex = getValue(dataTables.sizexs, pageKey, "未知"),
         crystalore = getValue(crystalores, pageKey, "未知"),
         sizey = getValue(dataTables.sizeys, pageKey, "未知"),
       
 
         hpmultiplier = getValue(hpmultipliers, pageKey, nil),
         hpmultiplier = getValue(dataTables.hpmultipliers, pageKey, nil),
       
 
         stamp = getValue(stamps, pageKey, nil),
         stamp = getValue(dataTables.stamps, pageKey, nil),
         nopause = getValue(nopauses, pageKey, false),
         nopause = getValue(dataTables.nopauses, pageKey, false),
 
        challengename = getValue(dataTables.challengenames, pageKey, nil),
        challengerank = getValue(dataTables.challengeranks, pageKey, nil),
        challengestar = getValue(dataTables.challengestars, pageKey, nil),
     }
     }


     -- 图片处理
     -- 图片处理
     local mainImg = getValue(imgs, pageKey, nil)
     local mainImg = getValue(dataTables.imgs, pageKey, nil)
     local d2 = getValue(imgd2s, pageKey, nil)
     local d2 = getValue(dataTables.imgd2s, pageKey, nil)
     local d3 = getValue(imgd3s, pageKey, nil)
     local d3 = getValue(dataTables.imgd3s, pageKey, nil)
     local d4 = getValue(imgd4s, pageKey, nil)
     local d4 = getValue(dataTables.imgd4s, pageKey, nil)
     local d5 = getValue(imgd5s, pageKey, nil)
    local d4night = getValue(dataTables.imgd4nights, pageKey, nil)
     local d6 = getValue(imgd6s, pageKey, nil)
     local d5 = getValue(dataTables.imgd5s, pageKey, nil)
     local d6 = getValue(dataTables.imgd6s, pageKey, nil)


     local imageWikitext = ""
     local imageWikitext = ""
     if mainImg then
     if mainImg then
         local hasExtra = d2 or d3 or d4 or d5 or d6
         local hasExtra = d2 or d3 or d4 or d4night or d5 or d6
         if not hasExtra then
         if not hasExtra then
             -- 直接插入第一张图
             -- 直接插入第一张图
             imageWikitext = "[[File:" .. mainImg .. ".png]]"
             imageWikitext = "[[File:" .. mainImg .. ".png|1000px]]"
         else
         else
             -- 有多张图,构建表格
             -- 有多张图,构建表格
            -- 收集所有图片(按显示顺序),用于确定最后一张
            local allImages = {mainImg}
            if d2 then table.insert(allImages, d2) end
            if d3 then table.insert(allImages, d3) end
            if d4 then table.insert(allImages, d4) end
            if d4night then table.insert(allImages, d4night) end
            if d5 then table.insert(allImages, d5) end
            if d6 then table.insert(allImages, d6) end
            local lastImg = allImages[#allImages]  -- 最后一张图片名
             local tbl = {}
             local tbl = {}
             table.insert(tbl, '{| class="wikitable mw-collapsible" style="text-align:center;"')
             table.insert(tbl, '{| class="wikitable mw-collapsible mw-collapsed" style="text-align:center; width:100%;"')
            -- 第一行:所有地图,展示最后一张图片
            table.insert(tbl, "|-\n| 所有地图\n[[File:" .. lastImg ..  ".png]]")
             -- Day 1
             -- Day 1
             table.insert(tbl, "|-\n| Day 1")
             table.insert(tbl, "|-\n| Day 1")
             table.insert(tbl, "|-\n| [[File:" .. mainImg .. ".png]]")
             table.insert(tbl, "|-\n| [[File:" .. mainImg .. ".png]]")
             local extras = {
 
                {2, d2},
            -- 构建带标签的图片列表
                {3, d3},
             local extras = {}
                {4, d4},
            if d2 then table.insert(extras, {label = "Day 2", img = d2}) end
                {5, d5},
            if d3 then table.insert(extras, {label = "Day 3", img = d3}) end
                {6, d6},
            if d4 then table.insert(extras, {label = "Day 4", img = d4}) end
            }
            if d4night then table.insert(extras, {label = "Day 4 Night", img = d4night}) end
            if d5 then table.insert(extras, {label = "Day 5", img = d5}) end
            if d6 then table.insert(extras, {label = "Day 6", img = d6}) end
 
             for _, item in ipairs(extras) do
             for _, item in ipairs(extras) do
                 local dayNum = item[1]
                 table.insert(tbl, "|-\n| " .. item.label)
                local img = item[2]
                table.insert(tbl, "|-\n| [[File:" .. item.img .. ".png]]")
                if img then
                    table.insert(tbl, "|-\n| Day " .. dayNum)
                    table.insert(tbl, "|-\n| [[File:" .. img .. ".png]]")
                end
             end
             end
             table.insert(tbl, "|}")
             table.insert(tbl, "|}")
第195行: 第113行:


     -- 关卡关系消息框
     -- 关卡关系消息框
     if data.challenge == "0" then
     if data.challenge == 0 then
         local titleText = "本关卡为战役关卡"
         local titleText = "本关卡为战役关卡"
         local textParts = {}
         local textParts = {}
         -- 检查是否存在A关卡
         -- 检查是否存在A关卡
         local aKey = pageKey .. "A"
         local aKey = pageKey .. "A"
         if names[aKey] then
         if dataTables.names[aKey] then
             table.insert(textParts, "挑战:[[" .. aKey .. "]]")
             table.insert(textParts, "挑战:[[" .. aKey .. "]]")
         end
         end
第217行: 第135行:
             table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "}}")
             table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "}}")
         end
         end
     elseif data.challenge == "1" then
     elseif data.challenge == 1 then
         if data.belongsto then
         if data.belongsto then
             local titleText = "本关卡为挑战关卡"
             local titleText = "本关卡为挑战关卡"
第233行: 第151行:
     if data.nopause then
     if data.nopause then
         table.insert(msgboxLines, "{{Message box|text=关卡最后一夜禁用暂停与倍速}}")
         table.insert(msgboxLines, "{{Message box|text=关卡最后一夜禁用暂停与倍速}}")
    end
    -- 成就消息框
    if data.challengename then
        local titleText = "成就:" .. data.challengename
        local text
        if data.challengerank == 2 then
            text = "在极难难度下,通关关卡" .. pageKey
        else
            text = "通关关卡" .. pageKey
        end
        local star = data.challengestar or 1
        local image = "challengestar" .. star .. ".png"
        table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "|image=" .. image .. "|image-size=60px}}")
     end
     end
      
      
第254行: 第186行:
      
      
     -- 其他信息
     -- 其他信息
     table.insert(lines, "游戏模式: " .. data.gamemode)
     table.insert(lines, "游戏模式:" .. data.gamemode)
     table.insert(lines, "关卡时长: 共 " .. data.gametime .. "天")
     table.insert(lines, "关卡时长:共 " .. data.gametime .. " 天")
     table.insert(lines, "初始资源: {{gc|" .. data.startgold .. "|" .. data.startcrystal .. "}}")
     table.insert(lines, "初始资源:{{gc|" .. data.startgold .. "|" .. data.startcrystal .. "}}")
     table.insert(lines, "金矿矿地: {{c|g|" .. data.goldore .. "}}")
     table.insert(lines, "金矿矿地:{{c|g|" .. data.goldore .. "}}")
     table.insert(lines, "水晶矿矿地: {{c|c|" .. data.crystalore .. "}}")
     table.insert(lines, "水晶矿矿地:{{c|c|" .. data.crystalore .. "}}")
     table.insert(lines, "关卡大小: " .. data.sizex .. " * " .. data.sizey)
     table.insert(lines, "关卡大小:" .. data.sizex .. " * " .. data.sizey)
    table.insert(lines, "关内倍率:" .. data.hpmultiplier)
      
      
     -- 可选信息
     -- 可选信息
     if data.hpmultiplier then
     -- if data.hpmultiplier then
        table.insert(lines, "关内倍率: " .. data.hpmultiplier)
    --    table.insert(lines, "关内倍率:" .. data.hpmultiplier)
     end
     -- end
     -- 用换行符连接
     -- 用换行符连接

2026年10月9日 (五) 13:43的最新版本

见Template:LevelInfo。



local p = {}

-- 加载数据子模块
-- 从 [[Module:LevelInfo/data]] 获取数据

local dataTables = require('Module:LevelInfo/data')

local function getValue(tbl, key, default)
    local v = tbl[key]
    if v == nil then
        return default
    end
    return v
end

-- wikitext

function p.render(frame)
    -- 获取当前页面标题
    local title = mw.title.getCurrentTitle()
    if not title then
        return "错误:无法获取当前页面标题。"
    end

    local pageKey = title.prefixedText

    -- 检查是否存在
    if dataTables.names[pageKey] == nil then
        return "该关卡暂无信息(" .. pageKey .. " 未配置)。"
    end

    -- 组装属性
    local data = {
        name = getValue(dataTables.names, pageKey, "未知"),
        challenge = getValue(dataTables.challenges, pageKey, "未知"),
        belongsto = getValue(dataTables.belongstos, pageKey, nil),
        reward = getValue(dataTables.rewards, pageKey, nil),
        gamemode = getValue(dataTables.gamemodes, pageKey, "未知"),
        gametime = getValue(dataTables.gametimes, pageKey, "未知"),
        startgold = getValue(dataTables.startgolds, pageKey, "未知"),
        startcrystal = getValue(dataTables.startcrystals, pageKey, "未知"),
        goldore = getValue(dataTables.goldores, pageKey, "未知"),
        crystalore = getValue(dataTables.crystalores, pageKey, "未知"),
        sizex = getValue(dataTables.sizexs, pageKey, "未知"),
        sizey = getValue(dataTables.sizeys, pageKey, "未知"),

        hpmultiplier = getValue(dataTables.hpmultipliers, pageKey, nil),

        stamp = getValue(dataTables.stamps, pageKey, nil),
        nopause = getValue(dataTables.nopauses, pageKey, false),

        challengename = getValue(dataTables.challengenames, pageKey, nil),
        challengerank = getValue(dataTables.challengeranks, pageKey, nil),
        challengestar = getValue(dataTables.challengestars, pageKey, nil),
    }

    -- 图片处理
    local mainImg = getValue(dataTables.imgs, pageKey, nil)
    local d2 = getValue(dataTables.imgd2s, pageKey, nil)
    local d3 = getValue(dataTables.imgd3s, pageKey, nil)
    local d4 = getValue(dataTables.imgd4s, pageKey, nil)
    local d4night = getValue(dataTables.imgd4nights, pageKey, nil)
    local d5 = getValue(dataTables.imgd5s, pageKey, nil)
    local d6 = getValue(dataTables.imgd6s, pageKey, nil)

    local imageWikitext = ""
    if mainImg then
        local hasExtra = d2 or d3 or d4 or d4night or d5 or d6
        if not hasExtra then
            -- 直接插入第一张图
            imageWikitext = "[[File:" .. mainImg .. ".png|1000px]]"
        else
            -- 有多张图,构建表格
            -- 收集所有图片(按显示顺序),用于确定最后一张
            local allImages = {mainImg}
            if d2 then table.insert(allImages, d2) end
            if d3 then table.insert(allImages, d3) end
            if d4 then table.insert(allImages, d4) end
            if d4night then table.insert(allImages, d4night) end
            if d5 then table.insert(allImages, d5) end
            if d6 then table.insert(allImages, d6) end
            local lastImg = allImages[#allImages]  -- 最后一张图片名

            local tbl = {}
            table.insert(tbl, '{| class="wikitable mw-collapsible mw-collapsed" style="text-align:center; width:100%;"')
            -- 第一行:所有地图,展示最后一张图片
            table.insert(tbl, "|-\n| 所有地图\n[[File:" .. lastImg ..  ".png]]")
            -- Day 1
            table.insert(tbl, "|-\n| Day 1")
            table.insert(tbl, "|-\n| [[File:" .. mainImg ..  ".png]]")

            -- 构建带标签的图片列表
            local extras = {}
            if d2 then table.insert(extras, {label = "Day 2", img = d2}) end
            if d3 then table.insert(extras, {label = "Day 3", img = d3}) end
            if d4 then table.insert(extras, {label = "Day 4", img = d4}) end
            if d4night then table.insert(extras, {label = "Day 4 Night", img = d4night}) end
            if d5 then table.insert(extras, {label = "Day 5", img = d5}) end
            if d6 then table.insert(extras, {label = "Day 6", img = d6}) end

            for _, item in ipairs(extras) do
                table.insert(tbl, "|-\n| " .. item.label)
                table.insert(tbl, "|-\n| [[File:" .. item.img ..  ".png]]")
            end
            table.insert(tbl, "|}")
            imageWikitext = table.concat(tbl, "\n")
        end
    end

    -- 构建消息框
    local msgboxLines = {}

    -- 关卡关系消息框
    if data.challenge == 0 then
        local titleText = "本关卡为战役关卡"
        local textParts = {}
        -- 检查是否存在A关卡
        local aKey = pageKey .. "A"
        if dataTables.names[aKey] then
            table.insert(textParts, "挑战:[[" .. aKey .. "]]")
        end
        -- 检查reward
        if data.reward and data.reward ~= "" then
            local rewardText
            if data.reward == "可携带塔数量" then
                rewardText = "通关获得:" .. data.reward
            else
                rewardText = "通关获得:[[" .. data.reward .. "]]"
            end
            table.insert(textParts, rewardText)
        end
        if #textParts > 0 then
            local text = table.concat(textParts, "<br />")
            table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "}}")
        end
    elseif data.challenge == 1 then
        if data.belongsto then
            local titleText = "本关卡为挑战关卡"
            local text = "战役:[[" .. data.belongsto .. "]]"
            table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "}}")
        end
    end

    -- 徽章解锁消息框
    if data.stamp then
        table.insert(msgboxLines, "{{Message box|title=本关卡需要 " .. data.stamp .. " 个徽章解锁}}")
    end

    -- 禁用暂停消息框
    if data.nopause then
        table.insert(msgboxLines, "{{Message box|text=关卡最后一夜禁用暂停与倍速}}")
    end

    -- 成就消息框
    if data.challengename then
        local titleText = "成就:" .. data.challengename
        local text
        if data.challengerank == 2 then
            text = "在极难难度下,通关关卡" .. pageKey
        else
            text = "通关关卡" .. pageKey
        end
        local star = data.challengestar or 1
        local image = "challengestar" .. star .. ".png"
        table.insert(msgboxLines, "{{Message box|title=" .. titleText .. "|text=" .. text .. "|image=" .. image .. "|image-size=60px}}")
    end
    
    -- ===================================

    -- wikitext
    local lines = {}
    
    -- 标题
    table.insert(lines, "== " .. pageKey .. " " .. data.name .. " ==")

    -- 消息框
    for _, mb in ipairs(msgboxLines) do
        table.insert(lines, mb)
    end

    -- 图片
    if imageWikitext ~= "" then
        table.insert(lines, imageWikitext)
    end
    
    -- 其他信息
    table.insert(lines, "游戏模式:" .. data.gamemode)
    table.insert(lines, "关卡时长:共 " .. data.gametime .. " 天")
    table.insert(lines, "初始资源:{{gc|" .. data.startgold .. "|" .. data.startcrystal .. "}}")
    table.insert(lines, "金矿矿地:{{c|g|" .. data.goldore .. "}}")
    table.insert(lines, "水晶矿矿地:{{c|c|" .. data.crystalore .. "}}")
    table.insert(lines, "关卡大小:" .. data.sizex .. " * " .. data.sizey)
    table.insert(lines, "关内倍率:" .. data.hpmultiplier)
    
    -- 可选信息
    -- if data.hpmultiplier then
    --     table.insert(lines, "关内倍率:" .. data.hpmultiplier)
    -- end
	
    -- 用换行符连接
    return frame:preprocess(table.concat(lines, "\n\n"))
end

return p