如果你看到本段文字,说明该页面未正常加载全局JS,部分功能将无法使用,请点击 刷新 重新加载页面。
如果打开页面显示缩略图创建出错,请点击刷新或页面右上WIKI功能中的刷新按钮清除页面缓存并刷新,如果还有问题,请多尝试几次。
全站通知:

模块:装备图鉴导航

来自碧蓝航线WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:装备图鉴导航/doc创建

local p = require [[Module:装备数据]]


local TypeSpanDefination = {
	{
		text = '舰炮',
		sub_type = {
			1, 2, 3, 11, 4
		},
		sub_text = {
			'驱逐', '轻巡', '重巡', '大口径重巡', '战列'
		}
	};
	{
		text = '鱼雷',
		sub_type = { 5, 13 },
		sub_text = { '水面', '潜艇' }
	};
	{
		text = '防空炮',
		sub_type = { 6, 21 },
		sub_text = { '近程', '远程' }
	};
	{
		text = '舰载机',
		sub_type = { 7, 8, 9 },
		sub_text = { '战斗机', '鱼雷机', '轰炸机' }
	};
	{
		text = '设备',
		sub_type = { 10, 14 },
		sub_text = { '通常', '反潜' }
	};
	{
		text = '水上机',
		type = 12
	};
	{
		text = '反潜机',
		type = 15
	};
	{
		text = '直升机',
		type = 17
	};
	{
		text = '货物',
		type = 18
	};
	{
		text = '导弹',
		type = 20
	};
	{
		text = '通常',
		type = 101
	};
	{
		text = '专属',
		type = 102,
		sub_type = {
			1, 2, 3, 18, 4, 5, 10, 6, 7, 8, 17, 9, 11, 12, 13, 19, 22, 106, 108, 109, 110, 999
		},
		sub_text = {
			'驱逐', '轻巡', '重巡', '超巡', '战巡', '战列', '航战', '轻航', '航母', '潜艇', '潜母', '航巡', '雷巡', '维修', '重炮', '运输', '风帆', '维纳斯假期', 'SSSS', 'Atelier Ryza', '闪乱神乐NL', '其他'
		}
	};
}

--------------------------------------------------
--	公开函数
--------------------------------------------------

--显示按国籍、类型划分的导航面板
p.ShowEquipNavPannel = function()

	--当前页面的名称
	local curEquip = mw.title.getCurrentTitle().text
	local curNation;
	curEquip = curEquip:match('^(.+)T%d$') or curEquip
	
	--加载模块
	local equip_data = p.equip_data
		
	--分类汇总
	local data = {}
	for _, v in pairs(equip_data) do
		data[v.nationality] = data[v.nationality] or {}
		data[v.nationality][v.type] = data[v.nationality][v.type] or {}
		if v.type == 102 then --专属兵装
			v.ship_type = v.ship_type or 999
			data[v.nationality][v.type][v.ship_type] = data[v.nationality][v.type][v.ship_type] or {}
		end
		
		local sub_equip = v.sub_equips[#v.sub_equips]

			if sub_equip.tech == 0 then
				v.tech = 4
			else
				v.tech = sub_equip.tech
			end
		v.rarity = sub_equip.rarity
		
		--找寻当前激活的页面
		curNation = curNation or ((v.name == curEquip) or (v.displayname == curEquip)) and v.nationality
		
		if v.type == 102 then
			table.insert(data[v.nationality][v.type][v.ship_type], v)
		else
			table.insert(data[v.nationality][v.type], v)
		end
	end
	
	curNation = curNation or 0
	
	--标签页面板参数
	local args = {
		theme = 'shiptable',
		label_style = '',
		[1] = { 
			title = '通用',
			text = 'xx鱼雷 xx机枪',
			id = 'en',
			active = 1
		}
	}
	
	--整理表data的索引
	local nation_list = {}
	for nation, _ in pairs(data) do
		table.insert(nation_list, nation)
	end
	table.sort(nation_list)
	
	--遍历所有阵营
	for index, nation in ipairs(nation_list) do
		
		--表格开始
		local content = [[

<table class="table-ShowEquipNavPannel" width="100%">
]]
		local type_equip_dict = data[nation]
		
		--遍历每一个大类
		for _, def in ipairs(TypeSpanDefination) do
			
			--计算这个大类有哪些子类/要横跨多少行
			local rowspan = 0
			if def.sub_type then
				if def.type == 102 and type_equip_dict[def.type] then --专属兵装
					for _, sub_type in ipairs(def.sub_type) do
						if type_equip_dict[def.type][sub_type] then
							rowspan = rowspan + 1
						end
					end
				else
					for _, sub_type in ipairs(def.sub_type) do
						if type_equip_dict[sub_type] then
							rowspan = rowspan + 1
						end
					end
				end
			elseif def.type and type_equip_dict[def.type] then
				rowspan = 1
			end
			
			if rowspan < 1 then	--这个大类是空的,跳过
			else
				--遍历每一个子类
				local sub_type_list = def.sub_type or { def.type }
				local row_index = 0
				for i, equip_type in ipairs(sub_type_list) do
					local equip_list
					if def.type == 102 then --专属兵装
						if type_equip_dict[def.type] then
							equip_list = type_equip_dict[def.type][equip_type]
						else
							equip_list = nil
						end
					else
						equip_list = type_equip_dict[equip_type]
					end
					
					if not equip_list then
						--子类的装备列表是空的
					else
						row_index = row_index + 1
						
						--绘制表头<th>
						if row_index == 1 and def.type and def.type ~= 102 then
							-- [防空炮] | xx, xx, xxx
							content = content .. ([[
<tr class="tr-top">
<th class="th-equip-type" colspan="2">%s
</th>
]]):format(def.text)
						elseif row_index == 1 then
							-- [舰炮] | 驱逐 | xx, xx
							content = content .. ([[
<tr class="tr-top">
<th class="th-equip-type" rowspan="%d">%s
</th>
<th class="th-equip-subtype">%s
</th>
]]):format(rowspan, def.text, def.sub_text[i] or '')
						else
							-- [  ] | 战列 | xx, xx
							content = content .. ([[
<tr>
<th class="th-equip-subtype">%s
</th>
]]):format(def.sub_text[i] or '')
							
						end
						
						
						--对装备排序
						table.sort(equip_list, function(a, b)
								if a.rarity ~= b.rarity then
									return a.rarity > b.rarity
								elseif a.tech ~= b.tech then
									return a.tech > b.tech
								end
								return a.id > b.id
							end
						)
						
						
						--遍历每一个装备
						for j = 1, #equip_list do
							--解析为HTML文本
							local selflink = equip_list[j].name == curEquip
							equip_list[j] = equipHtmlSerializer(equip_list[j], selflink);
						end
						
						--绘制装备的单元格
						content = content .. ([[
<td>%s
</td>
</tr>
]]):format(table.concat(equip_list))
					end
				end
			end
		end
		
		--表格结束
		content = content.. '</table>\n'
		
		args[index] = {
			title = nationIdToName(nation),
			text = content,
			id = 'Nav-'..nation,
			active = curNation == nation
			}
	end
	
	
	local mTBP = require('Module:选项卡面板')
	return mTBP.GenerateWholePanel(args)
end



p['显示装备导航面板'] = function(frame)

	return p.ShowEquipNavPannel()
end


--------------------------------------------------
--	私有函数
--------------------------------------------------

--查找项目
function indexOf(t, val)
	for i, v in ipairs(t) do
		if v == val then return i end
	end
	return -1
end

--将稀有度转换为颜色
function rarityToColor(rare)
	if rare == 1 then
		return '#808080'	--白色
	elseif rare == 2 then
		return '#808080'	--白色
	elseif rare == 3 then
		return '#3b8bff'	--蓝色
	elseif rare == 4 then
		return '#8000ff'	--紫色
	elseif rare == 5 then
		return '#c90'	--金色
	elseif rare == 6 then
		return '#f37f82'	--彩色
	end
		return 'red'		--不存在
end

function typeIdToName(id)
	return p.equip_type[id] or '未知'
end

function nationIdToName(id)
	local nation_data = {
		[0] = '其他',
		[1] = '白鹰',
		[2] = '皇家',
		[3] = '重樱',
		[4] = '铁血',
		[5] = '东煌',
		[6] = '撒丁帝国',
		[7] = '北方联合',
		[8] = '鸢尾教国',
		[9] = '维希教廷',
		[10] = '鸢尾教国',
		[96] = '飓风',
		[101] = '海王星',
		[102] = '哔哩哔哩',
		[103] = '传颂之物',
		[104] = 'KizunaAI',
		[105] = 'Hololive',
		[106] = '维纳斯假期',
		[107] = '偶像大师',
		[108] = 'SSSS',
		[109] = 'Atelier Ryza',
		[110] = '闪乱神乐NL',
		[999] = '特殊兵装',
	}
	return nation_data[id] or '未知'
end

--将装备数据转换为有样式的HTML文本
function equipHtmlSerializer(equip, selflink)
	
	return selflink and 
('<span class="nowrap">&nbsp;•&nbsp;<strong class="selflink" style="color:#808080;">%s</strong></span> ')
		:format(equip.displayname or equip.name) or 
('<span class="nowrap">&nbsp;•&nbsp;[[%s|<span style="color:%s;">%s</span>]]</span> ')
		:format(equip.name, rarityToColor((equip.nationality==999 and equip.rarity+1) or equip.rarity), equip.displayname or equip.name)
end

return p