置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:碧蓝航线

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

该模块作为碧蓝航线系列条目的重要模块,编辑请尽量使用原生编辑页面,并且保存前请务必预览Template:碧蓝航线的显示情况。

关于{{碧蓝航线links}}

逻辑代码位于模块:碧蓝航线Ships

数据位于模块:碧蓝航线Ships/Data

目前数据由脚本自动更新,有编辑组专人负责。

local module = {}

local translist_favor = {
	[0] = { ["好感度1"] = "好感度-失望", ["好感度2"] = "好感度-陌生", ["好感度3"] = "好感度-友好", ["好感度4"] = "好感度-喜欢", ["好感度5"] = "好感度-爱" },
	[97] = { ["好感度1"] = "好感度-未知", ["好感度2"] = "好感度-调率", ["好感度3"] = "好感度-理解", ["好感度4"] = "好感度-同步", ["好感度5"] = "好感度-共鸣" },
	[107] = { ["好感度1"] = "好感度-失望", ["好感度2"] = "好感度-普通", ["好感度3"] = "好感度-友好", ["好感度4"] = "好感度-协作", ["好感度5"] = "好感度-应援" },
}

local tranform_favor = function (ship_info, arg_name)
	return (translist_favor[ship_info.nation] or translist_favor[0])[arg_name]
end

local arglist = {
	{"获得", "登录", "查看详情", { "主界面[1-9][0-9]?", list = true, display = "主界面" }, "触摸", "摸头", "特殊触摸", "任务提醒", "任务完成", "邮件提醒", "回港", "委托完成", "强化成功", "旗舰开战", "胜利MVP", "失败",
		"技能", "HP告急", "彩蛋", { "彩蛋[1-9][0-9]?", list = true, display = "彩蛋" }, { "20%d%d情人节礼物", noaudio = true } },
	{"简介", { "好感度[1-5]", ["display"] = tranform_favor }, "好感度-失望", "好感度-陌生", "好感度-友好", "好感度-喜欢", "好感度-爱", "誓约", "掉落描述" },
	{"获得", "登录", "查看详情", { "主界面[1-9][0-9]?" }, "触摸", "摸头", "特殊触摸", "任务提醒", "任务完成", "邮件提醒", "回港", "委托完成", "简介", "好感度-失望", "好感度-陌生", "好感度-友好", "好感度-喜欢", "好感度-爱", "誓约", "强化成功",
		"旗舰开战", "胜利MVP", "失败", "技能", "HP告急", "彩蛋", { "彩蛋[1-9]", list = true, display = "彩蛋" } }
}

local hidelist = { ["礼物-喜欢"] = true, ["礼物-不喜欢"] = true, ["礼物-喜欢语音"] = true, ["礼物-不喜欢语音"] = true }
local g_frame = nil

function get_arg(name)
	return g_frame.args[name] and mw.text.trim(g_frame.args[name]) or ''
end

function bkcolor(level)
	if level == 1 then
		return "#d0d0d0"
	elseif level == 2 then
		return"#aae6fd"
	elseif level == 3 then
		return"#b9a7db"
	elseif level == 4 then
		return"#f9f593"
	elseif level == 5 then
		return"rgba(162, 214, 245,0.8)"
	elseif level == 6 then
		return"#d3aa4f"
	elseif level == 7 then
		return"#dcceff"
	elseif level == 14 then
		return"#9e5c22"	
	elseif level == 13 then
		return"#a676fc"
	else
		return"#d0d0d0"
	end
end

shipmodule = nil
function shipModule()
	if not shipmodule then
		shipmodule = require("Module:碧蓝航线Ships")
	end
	return shipmodule
end

function module.LinesUnit(frame)
	local parent = frame:getParent()
	local index = nil
	if parent then
		index = mw.ustring.match(parent:getTitle(), "^Template:碧蓝航线台词([1-3])$")
		if index then frame = parent end
	else
		index = frame.args["index"]
	end
	g_frame = frame
	if index then index = tonumber(index) else return end
	local num_level = frame:callParserFunction("#var", "levelnum", "")
	if num_level == "" then
		local obj_title = mw.title.getCurrentTitle()
		if obj_title.namespace == 0 then
			local name = mw.ustring.match(obj_title.text,"^碧蓝航线:(.+)")
			num_level = shipModule().innerlevel(name)
		end
	else
		num_level = tonumber(num_level)
	end
	if index == 3 and get_arg('改造') ~= '' then
		num_level = num_level + 1
	end
	local color_bkg = bkcolor(num_level)
	local hasAudio, hasDouble = false, false
	local used = { }
	local incorrect = { }
	local Incorrect_Add = function(key, group)
		if mw.title.getCurrentTitle().namespace ~= 0 then return end
		group = group or "模板参数不正确"
		if not incorrect[1] then table.insert(incorrect, "[[Category:碧蓝航线:" .. group .. "]]") end
		table.insert(incorrect, "[[Category:碧蓝航线:" .. group .. "/" .. key .. "]]")
	end
	local html = mw.html.create()
	local box = html:tag("table"):addClass("customers"):attr("width", "100%"):css("border-collapse", "separate"):css("border-spacing", "0 0.3em"):css("background-color", "rgba(235,248,255,0.5)"):css("border-radius", "0.3em")
	local Work_Audio = function(arg_name)
		local arg_audio = mw.text.trim(frame.args[arg_name])
		if arg_audio == "" then return "" end
		local arg_split = mw.text.split(arg_audio, ";", true)
		for index, file_audio in ipairs(arg_split) do
			local file_path = frame:callParserFunction("filepath", file_audio)
			if file_path == "" then
				Incorrect_Add(arg_name, "语音文件不存在")
				arg_split[index] = '<div class="error">语音文件不存在:' .. file_audio .. '</div>'
			else
				arg_split[index] = frame:extensionTag("sm2", file_audio)
			end
		end
		arg_audio = table.concat(arg_split)
		return arg_audio
	end
	local InsertItem = function(item, title, noaudio)
		local tr_item = box:tag("tr")
		tr_item:tag("td"):css("background", color_bkg):css("text-align", "center"):css("width", "110px"):css("border-top-left-radius","0.2em"):css("border-bottom-left-radius","0.2em"):tag("b"):wikitext(title or item)
		if mw.ustring.find(frame.args[item], "<u>") then hasDouble = true end
		local text = mw.ustring.gsub(frame.args[item], "(.+)\n\n+", "<p>%1</p>")
		tr_item:tag("td"):wikitext(text)
		local arg_audio = item .. "语音"
		if frame.args[arg_audio] and not noaudio then
			local text_audio = Work_Audio(arg_audio)
			if text_audio then
				hasAudio = true
				tr_item:tag("td"):attr("width", "40px"):wikitext(text_audio)
			elseif hasAudio then
				tr_item:tag("td")
			end
			used[arg_audio] = true
		elseif hasAudio then
			tr_item:tag("td")
		end
		used[item] = true
	end
	local InsertSubItems = function(itemlist, title, noaudio)
		local tr_item = box:tag("tr")
		tr_item:tag("td"):attr("rowspan", #itemlist):css("background", color_bkg):css("text-align", "center"):css("width", "110px"):css("border-top-left-radius","0.2em"):css("border-bottom-left-radius","0.2em"):tag("b"):wikitext(title or "")
		for idx, item in ipairs(itemlist) do
			if mw.ustring.find(frame.args[item], "<u>") then hasDouble = true end
			local text = mw.ustring.gsub(frame.args[item], "(.+)\n\n+", "<p>%1</p>")
			tr_item:tag("td"):wikitext(text)
			local arg_audio = item .. "语音"
			if frame.args[arg_audio] and not noaudio then
				local text_audio = Work_Audio(arg_audio)
				if text_audio then
					hasAudio = true
					tr_item:tag("td"):attr("width", "40px"):wikitext(text_audio)
				elseif hasAudio then
					tr_item:tag("td")
				end
				used[arg_audio] = true
			elseif hasAudio then
				tr_item:tag("td")
			end
			if itemlist[idx + 1] then tr_item = box:tag("tr") end
			used[item] = true
		end
	end
	if index == 1 and get_arg('登录欢迎语音') ~= '' then
		frame.args["登录欢迎"] = "碧蓝航线!"
		InsertItem("登录欢迎")
	end
	for _, item in ipairs(arglist[index]) do
		if type(item) == "table" then
			local pattern = item[1]
			local itemlist = { }
			for key, value in pairs(frame.args) do
				if mw.ustring.match(key, "^" ..pattern .. "$") and mw.text.trim(value) ~= "" then
					table.insert(itemlist, key)
				end
			end
			table.sort(itemlist)
			if item.list and itemlist[1] then
				InsertSubItems(itemlist, item.display, item.noaudio)
			elseif itemlist[1] then
				for _, name in ipairs(itemlist) do
					if type(item.display) == "table" then
						InsertItem(name, item.display[name] or name, item.noaudio)
					elseif type(item.display) == "function" then
						local ship_name = mw.ustring.match(mw.title.getCurrentTitle().text,"^碧蓝航线:(.+)")
						local ship_info = shipModule().get_data(ship_name or 'null')
						InsertItem(name, item.display(ship_info, name), item.noaudio)
					else
						InsertItem(name, name, item.noaudio)
					end
				end
			end
		else
			if frame.args[item] then
				if mw.text.trim(frame.args[item]) ~= "" then
					InsertItem(item)
				else
					used[item] = true
					if frame.args[item .. "语音"] then used[item .. "语音"] = true end
				end
			end
		end
	end
	local retn = tostring(html)
	if hasDouble then
		retn = '<ul class="margin-left-set" style="margin-left: 1.2em;"><li>下方有底线为誓约新增额外台词</li></ul>' .. retn
	end
	for key, value in pairs(frame.args) do
		if (not used[key] and (index ~= 3 or key ~= "改造") and not hidelist[key]) or (key == "登录欢迎") then
			Incorrect_Add(key)
		elseif mw.ustring.match(value, "[暂暫][无無]") then
			Incorrect_Add("暂无")
		elseif key == "彩蛋" and mw.ustring.match(value, "\n\n") then
			Incorrect_Add("彩蛋")
		end
	end
	if incorrect[1] then retn = retn .. table.concat(incorrect) end

	return retn
end

-- 阵营名称相关([[Template:碧蓝航线阵营]])
local translist = { ["Eagle"] = "白[鹰鷹]", ["Royal"] = "皇家", ["Sakura"] = "重[樱櫻]", ["Metalblood"] = "[铁鐵]血", ["Eastern"] = "[东東]煌", ["North"] = "北方[联聯]合", ["Iris"] = "自由[鸢鳶]尾", ["Vichya"] = "[维維]希教廷",
	["Sardinia"] = "撒丁", ["Neptunia"] = { "海王星", "hyperdimension" }, ["Utawarerumono"] = { "传颂", "傳頌" }, ["Kizuna"] = "绊爱", ["Hololive"] = 0, ["DOAXVV"] = { "维纳斯假期", "維納斯假期" },["META"] = 0, ["Bilibili"] = "哔哩哔哩", ["None"] = { "无阵营", "無陣營", "布里神教" }
, ["iM@S"] = "偶像大师", ["SSSS"] = "SSSS", ["Tempesta"] = { "飓风", "颶風" }, ["Atelier Ryza"] = { "Atelier Ryza" }}

local mapslist = { ["Eagle"] = "碧蓝航线-白鹰", ["Royal"] = "碧蓝航线-皇家", ["Sakura"] = "赤色中轴-重樱", ["Metalblood"] = "赤色中轴-铁血", ["Eastern"] = "碧蓝航线-东煌", ["North"] = "碧蓝航线-北方联合", ["Iris"] = "碧蓝航线-自由鸢尾", ["Vichya"] = "赤色中轴-维希教廷",
	["Neptunia"] = "????-海王星", ["Utawarerumono"] = "????-传颂之物", ["Kizuna"] = "????-KizunaAI", ["Hololive"] = "????-hololive", ["DOAXVV"] = "????-维纳斯假期", ["Sardinia"] = "赤色中轴-撒丁帝国", ["Bilibili"] = "????-哔哩哔哩", ["None"] = "????-其他",["META"] = "META-???"
	, ["iM@S"] = "????-偶像大师", ["SSSS"] = "????-SSSS", ["Tempesta"] = "????-飓风", ["Atelier Ryza"] = "????-Atelier Ryza"}

function module.team_getcode(frame)
	local arg_input = mw.ustring.lower(frame.args[1])
	for key, value in pairs(translist) do
		if mw.ustring.find(arg_input, mw.ustring.lower(key)) then return key end
		if type(value) == "string" then
			if mw.ustring.find(arg_input, value) then return key end
		elseif type(value) == "table" then
			for _, item in pairs(value) do
				if mw.ustring.find(arg_input, item) then return key end
			end
		end
	end
	return "Unknow"
end

function module.team_normalize(frame)
	local code = module.team_getcode(frame)
	return mapslist[code] or "阵营信息"
end

local alphabet = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N" }

function module.MapsGen(frame)
	local parent = frame:getParent()
	if parent and parent:getTitle() == "Template:碧蓝航线地图" then
		frame = parent
	end
	g_frame = frame
	local rows = frame.args["行数"]
	rows = rows and tonumber(rows) or 1
	local cols = frame.args["列数"]
	cols = cols and tonumber(cols) or 1
	local html = mw.html.create()
	local box = html:tag("table"):addClass("Azur_Maps"):css( {
		["position"] = "relative",
		["z-index"] = "2",
		["margin"] = "0",
		["border-collapse"] = "collapse",
		["text-align"] = "center",
		["color"] = "white",
		["font-weight"] = "bold",
	} )
	local tr_line = box:tag("tr"):tag("td"):done()
	for col = 1, cols do
		tr_line:tag("td"):wikitext(alphabet[col])
	end

	local arg_list = { '起点', '敌人', '塞壬', 'BOSS', '潜艇' }
	local objects = {}
	for _, arg in ipairs(arg_list) do
		value = get_arg(arg)
		mw.log(arg, value)
		if (value ~= '') then
			objects[arg] = frame:expandTemplate{ title = '碧蓝航线地图/Item', args = { arg } }
			list_pos = mw.text.split(value, ',')
			for _, pos in ipairs(list_pos) do
				objects[pos] = objects[arg]
			end
		end
	end

	local arg_name = ""
	for row = 1, rows do
		tr_line = box:tag("tr")
		tr_line:tag("td"):wikitext(tostring(row))
		for col = 1, cols do
			arg_name = tostring(row) .. alphabet[col]
			tr_line:tag("td"):wikitext(objects[arg_name] or frame.args[arg_name])
		end
	end
	return html
end

return module