Module:碧蓝航线/性能
跳转到导航
跳转到搜索
local module = { }
local map_items = { ["耐久"] = 1, ["炮击"] = 2, ["雷击"] = 3, ["防空"] = 4, ["航空"] = 5, ["装填"] = 6, ["射程"] = 7, ["命中"] = 8, ["机动"] = 9, ["航速"] = 10, ["幸运"] = 11, ["反潜"] = 12 }
local map_notrans = { [7] = true, [11] = true }
local data = mw.loadData("Module:碧蓝航线/性能/Data")
local function args_err(info)
return '<div class="error">参数错误:' .. info .. '</div>'
end
function module.main(frame)
local parent = frame:getParent()
if parent and parent:getTitle() == "Template:碧蓝航线舰船性能" then
frame = parent
end
local arg_name = frame.args[1] or ""
arg_name = mw.text.trim(arg_name)
if arg_name == "" or not data[arg_name] then return args_err("1") end
local arg_type = frame.args["type"] or "0"
arg_type = tonumber(arg_type)
local arg_item = frame.args["item"] or "1"
if map_items[arg_item] then
arg_item = map_items[arg_item]
else
arg_item = tonumber(arg_item)
end
if not arg_item or arg_item < 1 or arg_item > 12 then return args_err("item") end
local arg_check = frame.args["check"] or ""
if arg_type == 1 or map_notrans[arg_item] then
local arg_index = frame.args["index"] or "1"
arg_index = tonumber(arg_index)
if data[arg_name][arg_index] then
return data[arg_name][arg_index][arg_item]
else
return args_err("index")
end
else
local retn, matches = { }, { }
local last, needChk = nil, false
for num in mw.ustring.gmatch(arg_check, "%d+") do
table.insert(matches, num)
end
for index, item in ipairs(data[arg_name]) do
if matches[index] and tonumber(matches[index]) ~= item[arg_item] then
needChk = true
end
if not last or last ~= item[arg_item] then
last = item[arg_item]
if index == 3 then
table.insert(retn, frame:expandTemplate{ title = "Color", args = { "orange", item[arg_item] } } .. (needChk and "[[Category:碧蓝航线:数据需要检查]][[Category:碧蓝航线:数据需要检查/" .. frame.args["item"] .. "]]" or "") )
else
table.insert(retn, item[arg_item])
end
end
end
return table.concat(retn, "→")
end
end
function module.check(frame)
local arg_name = frame.args[1] or ""
arg_name = mw.text.trim(arg_name)
if arg_name == "" or not data[arg_name] then return "" end
return arg_name
end
return module