模块:测试调用数据:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第9行: | 第9行: | ||
local html = mw.html.create() | local html = mw.html.create() | ||
-- 排序属性 | |||
local function numvalue(char, attr, lang) | local function numvalue(char, attr, lang) | ||
-- 提取所有非 nil 值 | -- 提取所有非 nil 值 | ||
第42行: | 第43行: | ||
if query_num == char.owner_order then | if query_num == char.owner_order then | ||
html:tag('p'):wikitext("查询角色编号: " .. query_num):done() | html:tag('p'):wikitext("查询角色编号: " .. query_num):done() | ||
-- 创建属性表,日服一个,国服一个 | |||
local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%') | local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%') | ||
tableHtml:tag('tr') | local tableHtml = tableHtml:tag('tr') | ||
:tag('th'):wikitext('属性'):done() | :tag('th'):wikitext('属性'):done() | ||
:tag('th'):wikitext('Base'):done() | :tag('th'):wikitext('Base'):done() | ||
第58行: | 第61行: | ||
-- 获取排名 | -- 获取排名 | ||
local maxRank = numvalue(char, maxAttr | local maxRank = numvalue(char, maxAttr) | ||
local baseRank = numvalue(char, baseAttr | local baseRank = numvalue(char, baseAttr) | ||
tableHtml:tag('tr') | local tableHtml_jp = tableHtml:tag('tr') | ||
:tag('td'):wikitext(elementName):done() | :tag('td'):wikitext(elementName):done() | ||
:tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done() | :tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done() | ||
第67行: | 第70行: | ||
:done() | :done() | ||
end | end | ||
html:node(tableHtml_jp) | |||
html:node( | if char.Data_cn then | ||
for i, element in ipairs(elements) do | |||
local elementName = elementsName[i] | |||
local maxAttr = "MAX" .. element | |||
local maxAttrValue = char.Data_cn[maxAttr] or "" | |||
local baseAttr = "Base" .. element | |||
local baseAttrValue = char.Data_cn[baseAttr] or "" | |||
-- 获取排名 | |||
local maxRank = numvalue(char, maxAttr, "cn") | |||
local baseRank = numvalue(char, baseAttr, "cn") | |||
local tableHtml_cn = tableHtml:tag('tr') | |||
:tag('td'):wikitext(elementName):done() | |||
:tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done() | |||
:tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done() | |||
:done() | |||
end | |||
end | |||
html:node(tableHtml_cn) | |||
end | end | ||
end | end |
2024年6月28日 (五) 12:27的版本
可在模块:测试调用数据/doc创建此模块的帮助文档
local p = {}
local db = mw.loadData('模块:角色属性数据')
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local elementsName = {"HP", "SP", "物攻", "物防", "属攻", "属防", "会心", "速度"}
p["测试调用"] = function(frame)
local query_num = frame.args['角色编号']
local html = mw.html.create()
-- 排序属性
local function numvalue(char, attr, lang)
-- 提取所有非 nil 值
local attrValues = {}
for _, data in ipairs(dataList) do
local value = nil
if lang == "cn" and data.Data_cn and data.Data_cn[attr] then
value = tonumber(data.Data_cn[attr])
elseif data.Data_jp and data.Data_jp[attr] then
value = tonumber(data.Data_jp[attr])
end
if value then
table.insert(attrValues, value)
end
end
-- 排序部分
table.sort(attrValues, function(a, b) return a > b end)
local targetData = char.Data_cn and char.Data_cn[attr] or char.Data_jp and char.Data_jp[attr]
local charValue = tonumber(targetData)
for i, value in ipairs(attrValues) do
if value == charValue then
return i
end
end
return "暂无"
end
-- 执行测试输出
for _, char in ipairs(dataList) do
if query_num == char.owner_order then
html:tag('p'):wikitext("查询角色编号: " .. query_num):done()
-- 创建属性表,日服一个,国服一个
local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%')
local tableHtml = tableHtml:tag('tr')
:tag('th'):wikitext('属性'):done()
:tag('th'):wikitext('Base'):done()
:tag('th'):wikitext('MAX'):done()
:done()
for i, element in ipairs(elements) do
local elementName = elementsName[i]
local maxAttr = "MAX" .. element
local maxAttrValue = char.Data_jp[maxAttr] or ""
local baseAttr = "Base" .. element
local baseAttrValue = char.Data_jp[baseAttr] or ""
-- 获取排名
local maxRank = numvalue(char, maxAttr)
local baseRank = numvalue(char, baseAttr)
local tableHtml_jp = tableHtml:tag('tr')
:tag('td'):wikitext(elementName):done()
:tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done()
:tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done()
:done()
end
html:node(tableHtml_jp)
if char.Data_cn then
for i, element in ipairs(elements) do
local elementName = elementsName[i]
local maxAttr = "MAX" .. element
local maxAttrValue = char.Data_cn[maxAttr] or ""
local baseAttr = "Base" .. element
local baseAttrValue = char.Data_cn[baseAttr] or ""
-- 获取排名
local maxRank = numvalue(char, maxAttr, "cn")
local baseRank = numvalue(char, baseAttr, "cn")
local tableHtml_cn = tableHtml:tag('tr')
:tag('td'):wikitext(elementName):done()
:tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done()
:tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done()
:done()
end
end
html:node(tableHtml_cn)
end
end
return tostring(html)
end
return p