模块:角色属性:修订间差异

(141933945移动页面模块:处理角色属性模块:角色属性,不留重定向)
(修改数组为中日文俩个)
第1行: 第1行:
local p = {}
local p = {}
local db = require('模块:角色数据属性')
local db = mw.loadData('模块:角色属性数据')
local dataList = db.char_self_data
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local charBaseData = {}


-- 查询并缓存数据
-- 生成中文日文俩个数组,键名保持一致
local function filterCharData(query_num)
local Data_jp = {}
     if charBaseData[query_num] then
local Data_cn = {}
         return charBaseData[query_num]
 
    end
local function createDataList(dataList, elements)
     for _, charData in pairs(dataList) do
         local charData_jp = {}
        local charData_cn = {}


    local filteredData = {}
        for _, element in ipairs(elements) do
            local maxKey = "MAX" .. element
            local baseKey = "Base" .. element
            charData_jp[element] = {
                MAX = charData[maxKey],
                Base = charData[baseKey]
            }


    for _, v in ipairs(dataList) do
            local maxKey_cn = "MAX" .. element .. "_cn"
        if v.owner_order == query_num then
            local baseKey_cn = "Base" .. element .. "_cn"
             table.insert(filteredData, v)
            charData_cn[element] = {
                MAX = charData[maxKey_cn] or charData[maxKey],
                Base = charData[baseKey_cn] or charData[baseKey]
             }
         end
         end
        charData_jp.owner_order = charData.owner_order
        charData_cn.owner_order = charData.owner_order
        table.insert(Data_jp, charData_jp)
        table.insert(Data_cn, charData_cn)
     end
     end
    charBaseData[query_num] = filteredData
   
    return filteredData
end
end


-- 角色白值函数
createDataList(dataList, elements)
p["角色白值"] = function(frame)
local query_num = frame.args['角色编号']
    local charData = filterCharData(query_num)
 
    local html = mw.html.create('table')


     for _, w in ipairs(charData) do
local function printDataKeys(dataList, title)
         local row = html:tag('tr')  
    print(title)
         for _, emt in ipairs(elements) do
     for _, charData in ipairs(dataList) do
             local emtname = "Base" .. emt
         print("Owner Order: " .. charData.owner_order)
            if w[emtname] then
         for element, values in pairs(charData) do
                 row:tag('td'):wikitext(w[emtname]):done()
             if element ~= "owner_order" then
            else
                 print(element .. ": MAX = " .. values.MAX .. ", Base = " .. values.Base)
                row:tag('td'):wikitext("N/A"):done()  
             end
             end
         end
         end
        print("----------")
     end
     end
end


    return tostring(html)
-- Print the 日服数据 and 国服数据 (for verification purposes)
end
printDataKeys(Data_jp, "日服数据键名和值")
printDataKeys(Data_cn, "国服数据键名和值")


return p
return p

2024年6月23日 (日) 08:35的版本

可在模块:角色属性/doc创建此模块的帮助文档

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

-- 生成中文日文俩个数组,键名保持一致
local Data_jp = {}
local Data_cn = {}

local function createDataList(dataList, elements)
    for _, charData in pairs(dataList) do
        local charData_jp = {}
        local charData_cn = {}

        for _, element in ipairs(elements) do
            local maxKey = "MAX" .. element
            local baseKey = "Base" .. element
            charData_jp[element] = {
                MAX = charData[maxKey],
                Base = charData[baseKey]
            }

            local maxKey_cn = "MAX" .. element .. "_cn"
            local baseKey_cn = "Base" .. element .. "_cn"
            charData_cn[element] = {
                MAX = charData[maxKey_cn] or charData[maxKey],
                Base = charData[baseKey_cn] or charData[baseKey]
            }
        end

        charData_jp.owner_order = charData.owner_order
        charData_cn.owner_order = charData.owner_order

        table.insert(Data_jp, charData_jp)
        table.insert(Data_cn, charData_cn)
    end
end

createDataList(dataList, elements)

local function printDataKeys(dataList, title)
    print(title)
    for _, charData in ipairs(dataList) do
        print("Owner Order: " .. charData.owner_order)
        for element, values in pairs(charData) do
            if element ~= "owner_order" then
                print(element .. ": MAX = " .. values.MAX .. ", Base = " .. values.Base)
            end
        end
        print("----------")
    end
end

-- Print the 日服数据 and 国服数据 (for verification purposes)
printDataKeys(Data_jp, "日服数据键名和值")
printDataKeys(Data_cn, "国服数据键名和值")

return p