模块:角色属性:修订间差异
(创建页面,内容为“local p = {} local db = require('模块:角色数据属性') local dataList = db.char_self_data local query_num = frame.args['角色编号'] local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"} local charBaseData = {} -- 查询并缓存数据 function filterCharData(query_num) if charBaseData[query_num] then return charBaseData[query_num] end local filteredData = {} for _, v in ipairs(dataList) do if v.owne…”) |
无编辑摘要 |
||
第2行: | 第2行: | ||
local db = require('模块:角色数据属性') | local db = require('模块:角色数据属性') | ||
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 charBaseData = {} | ||
local query_num = frame.args['角色编号'] | |||
-- 查询并缓存数据 | -- 查询并缓存数据 | ||
function filterCharData(query_num) | local function filterCharData(query_num) | ||
if charBaseData[query_num] then | if charBaseData[query_num] then | ||
return charBaseData[query_num] | return charBaseData[query_num] | ||
第25行: | 第25行: | ||
end | end | ||
p["角色白值"]=function(frame) | -- 角色白值函数 | ||
local charData = | p["角色白值"] = function(frame) | ||
local charData = filterCharData(query_num) | |||
local html = mw.html.create() | |||
local html = mw.html.create('table') | |||
for _, w in ipairs(charData) do | for _, w in ipairs(charData) do | ||
local row = html:tag('tr') | |||
for _, emt in ipairs(elements) do | |||
local emtname = "Base" .. emt | local emtname = "Base" .. emt | ||
if w[emtname] then | if w[emtname] then | ||
row:tag('td'):wikitext(w[emtname]):done() | row:tag('td'):wikitext(w[emtname]):done() | ||
else | else | ||
row:tag('td'):wikitext("N/A"):done() | row:tag('td'):wikitext("N/A"):done() | ||
end | end | ||
end | end | ||
end | end | ||
return tostring(html) | |||
end | end | ||
return p | return p |
2024年6月22日 (六) 22:09的版本
可在模块:角色属性/doc创建此模块的帮助文档
local p = {}
local db = require('模块:角色数据属性')
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
local charBaseData = {}
local query_num = frame.args['角色编号']
-- 查询并缓存数据
local function filterCharData(query_num)
if charBaseData[query_num] then
return charBaseData[query_num]
end
local filteredData = {}
for _, v in ipairs(dataList) do
if v.owner_order == query_num then
table.insert(filteredData, v)
end
end
charBaseData[query_num] = filteredData
return filteredData
end
-- 角色白值函数
p["角色白值"] = function(frame)
local charData = filterCharData(query_num)
local html = mw.html.create('table')
for _, w in ipairs(charData) do
local row = html:tag('tr')
for _, emt in ipairs(elements) do
local emtname = "Base" .. emt
if w[emtname] then
row:tag('td'):wikitext(w[emtname]):done()
else
row:tag('td'):wikitext("N/A"):done()
end
end
end
return tostring(html)
end
return p