WIKI公告栏
欢迎各位引航者访问卡拉彼丘WIKI,由于游客访问页面会有一定的页面旧版缓存,建议你登陆B站账号进行浏览,如果您觉得本WIKI有帮助到你,欢迎推荐给身边的引航者。
全站通知:

模块:印迹

来自卡拉彼丘WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:印迹/doc创建

local p = {}

local data = mw.text.jsonDecode(mw.title.new('Module:印迹/Data.json'):getContent() or '{}')

------获取调用页面名
local function getPageTitle()
	return mw.title.getCurrentTitle().text
end


------印迹页面、角色印迹模板
function p.main(frame)
    local Achievementrole = frame.args[1]
    local Achievementlevel = tonumber(frame.args[2])
    local tempList = {}

    for key, AchievementData in pairs(data) do
        if Achievementrole == AchievementData.Role and Achievementlevel == AchievementData.Level then
            table.insert(tempList, { key = key, data = AchievementData })
        end
    end

    table.sort(tempList, function(a, b)
        return a.key < b.key
    end)

    local resultList = {}
    for _, item in ipairs(tempList) do
        local AchievementData = item.data
        local html = AchievementData.File .. "|'''<big>" .. AchievementData.Name .. "</big>'''<br /><small>" 
        .. AchievementData.Desc_string .. "</small><br /><br />'''获得方式:'''" .. AchievementData.Get
        table.insert(resultList, tostring(html))
    end
    local result = table.concat(resultList, "\n")
    return frame:preprocess('\n<gallery mode="packed">\n' .. result .. '\n</gallery>')
end


------勋章页面印迹勋章部分
function p.main2(frame)
    local Achievementrole = frame.args[1]
    local groupedAchievements = {}

    -- 遍历数据,将同一角色的印迹按组分类,并存储每组的最高等级
    for key, AchievementData in pairs(data) do
        if Achievementrole == AchievementData.Role then
            -- 获取组的基础ID,通过截取key的前几位实现(例如: 33500014 -> 3350001)
            local baseKey = string.sub(key, 1, 7)
            groupedAchievements[baseKey] = groupedAchievements[baseKey] or {}

            -- 比较并存储每组中的最高等级印迹
            if not groupedAchievements[baseKey].maxLevel or AchievementData.Level > groupedAchievements[baseKey].maxLevel then
                groupedAchievements[baseKey].maxLevel = AchievementData.Level
                groupedAchievements[baseKey].data = AchievementData
            end
        end
    end

    -- 生成最终输出结果
    local resultList = {}
    for _, groupData in pairs(groupedAchievements) do
        local AchievementData = groupData.data
        local html = AchievementData.File .. "|'''<big>" .. AchievementData.Name .. "</big>'''"
        table.insert(resultList, tostring(html))
    end

    local result = table.concat(resultList, "\n")
    return frame:preprocess('\n<gallery mode="packed">\n' .. result .. '\n</gallery>')
end

return p