模块:测试调用数据:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第62行: | 第62行: | ||
html:tag('p'):wikitext("查询角色编号: " .. query_num):done() | html:tag('p'):wikitext("查询角色编号: " .. query_num):done() | ||
if char.Data_cn then | if char.Data_cn then | ||
local tabberHtml = mw.html.create('div'):addClass('tabber') | |||
tabberHtml:tag('ul') | |||
:tag('li'):wikitext('国服数据') | |||
:tag('div'):addClass('tabbertab'):wikitext(tableToString(generateTable(char, "cn"))):done() | |||
:done() | |||
:tag('li'):wikitext('日服数据') | |||
:tag('div'):addClass('tabbertab'):wikitext(tableToString(generateTable(char, "jp"))):done() | |||
:done() | |||
:done() | |||
html:node(tabberHtml) | |||
function tableToString(tbl) | |||
if type(tbl) == "table" then | |||
return mw.text.jsonEncode(tbl) | |||
else | |||
return tostring(tbl) | |||
end | |||
end | |||
else | else | ||
local jpTable = generateTable(char, "jp") | local jpTable = generateTable(char, "jp") |
2024年6月28日 (五) 13:12的版本
可在模块:测试调用数据/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)
local attrValues = {}
for _, data in ipairs(dataList) do
local value = tonumber(lang == "cn" and data.Data_cn and data.Data_cn[attr] or data.Data_jp and data.Data_jp[attr])
if value then
table.insert(attrValues, value)
end
end
table.sort(attrValues, function(a, b) return a > b end)
local targetData = tonumber(lang == "cn" and char.Data_cn and char.Data_cn[attr] or char.Data_jp and char.Data_jp[attr])
for i, value in ipairs(attrValues) do
if value == targetData then
return i
end
end
return "暂无"
end
local function generateTable(char, lang)
local tableHtml = mw.html.create('table'):addClass('wikitable'):css('width', '100%')
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 baseAttr = "Base" .. element
local maxAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[maxAttr] or char.Data_jp and char.Data_jp[maxAttr] or ""
local baseAttrValue = lang == "cn" and char.Data_cn and char.Data_cn[baseAttr] or char.Data_jp and char.Data_jp[baseAttr] or ""
local maxRank = numvalue(char, maxAttr, lang)
local baseRank = numvalue(char, baseAttr, lang)
tableHtml:tag('tr')
:tag('td'):wikitext(elementName):done()
:tag('td'):wikitext(baseAttrValue .. " (" .. baseRank .. ")"):done()
:tag('td'):wikitext(maxAttrValue .. " (" .. maxRank .. ")"):done()
:done()
end
return tableHtml
end
for _, char in ipairs(dataList) do
if query_num == char.owner_order then
html:tag('p'):wikitext("查询角色编号: " .. query_num):done()
if char.Data_cn then
local tabberHtml = mw.html.create('div'):addClass('tabber')
tabberHtml:tag('ul')
:tag('li'):wikitext('国服数据')
:tag('div'):addClass('tabbertab'):wikitext(tableToString(generateTable(char, "cn"))):done()
:done()
:tag('li'):wikitext('日服数据')
:tag('div'):addClass('tabbertab'):wikitext(tableToString(generateTable(char, "jp"))):done()
:done()
:done()
html:node(tabberHtml)
function tableToString(tbl)
if type(tbl) == "table" then
return mw.text.jsonEncode(tbl)
else
return tostring(tbl)
end
end
else
local jpTable = generateTable(char, "jp")
html:node(jpTable)
end
end
end
return tostring(html)
end
return p