模块:测试调用数据

可在模块:测试调用数据/doc创建此模块的帮助文档

local p = {}
local db = mw.loadData('模块:角色属性数据')
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}

p["测试调用"] = function(frame)
    local query_num = frame.args['角色编号']
    local html = mw.html.create()

    -- 执行测试输出
    html:tag('p'):wikitext("开始测试模块:角色属性数据"):done()

    if not query_num then
        html:tag('p'):wikitext("错误: 缺少角色编号参数"):done()
    else
        html:tag('p'):wikitext("查询角色编号: " .. query_num):done()
        local found = false
        for _, char in ipairs(dataList) do
            if query_num == char.owner_order then
                found = true
                html:tag('p'):wikitext("角色编号: " .. char.owner_order):done()
                for _, element in ipairs(elements) do
                    local maxAttr = "MAX" .. element
                    local maxAttrValue = char.Data_jp[maxAttr] or "数据不存在"
                    html:tag('p'):wikitext(maxAttr .. ": " .. maxAttrValue):done()
                    
                    local baseAttr = "Base" .. element
                    local baseAttrValue = char.Data_jp[baseAttr] or "数据不存在"
                    html:tag('p'):wikitext(baseAttr .. ": " .. baseAttrValue):done()
                end
            end
        end
        if not found then
            html:tag('p'):wikitext("错误: 找不到角色编号为 " .. query_num .. " 的角色"):done()
        end
    end

    html:tag('p'):wikitext("模块:角色属性数据测试完成"):done()

    return tostring(html)
end

return p