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

模块:舰船型号

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

此模块的文档可以在模块:舰船型号/doc创建

--------------------------------------------------
--	调用模块:舰娘数据/型号
--	调用模块:舰娘数据
--------------------------------------------------
local p = require('模块:舰娘数据/型号')
mSD = require('模块:舰娘数据')


--------------------------------------------------
--	主要过程
--------------------------------------------------

function ShowShipClassList()
	
	local data = {}
	--分类汇总
	for ship, v in pairs(p.ship_data_class) do
		local t = math.floor(v.id / 1000 % 10)
		t = t == 0 and 1 or t
		data[t] = data[t] or {}
		local cc = v.class_des or '其他'
		data[t][cc] = data[t][cc] or {}
		table.insert(data[t][cc], ship)
	
		-- data[t][cc].type_des = data[t][cc].type_des
				-- or not v.class_des and ''
				-- or v.type_des and v.class_des .. v.type_des
				-- or ''
	end
	
	local result = [[
{| style="width:100%;" class="table-ShowShipClassList"
]]
	local maxt = table.maxn(data)
	--遍历所有舰船类型
	for ship_type = 1, maxt do
		local type_data = data[ship_type]
		if type_data then
		
			--舰船级别排序
			local keys = {}
			
			for k, _ in pairs(type_data) do
				table.insert(keys, k)
			end
			if #keys > 1 then
				table.sort(keys, function(a,b)
						if a == '其他' then
							return false
						elseif b == '其他' then
							return true
						end
						local shipA = type_data[a][1]
						local shipB = type_data[b][1]
						return p.ship_data_class[shipA].id 
							< p.ship_data_class[shipB].id
					end
				)
			end
			
			--类别表头
			if ship_type > 1 then
				result = result .. ([[
|- 
! width="100px" rowspan=%s style="background:#337ab7;color:white;font-size:large;" | %s
]]):format(#keys, typeIdToName(ship_type))
			else
				result = result .. ([[
|- style="border-top-style:none; border-bottom-style:none;"
! width="100px" rowspan=%s style="background:#337ab7;color:white;font-size:large;" | %s
]]):format(#keys, typeIdToName(ship_type))
			end
			
			--遍历所有级别
			for i, ship_class in ipairs(keys) do
				local list = type_data[ship_class]
				local ship_v = p.ship_data_class[list[1]]
				for j = 1, #list do
					local ship = list[j]
					list[j] = ('• [[%s]] '):format(ship)
				end
				ship_class = ship_class ~= '其他' and ship_v.type_des 
							and ship_class..ship_v.type_des
							or ship_class
					
				
				--级别表头
				if i > 1 then
					result = result .. ([[
|- style = "border-top-style:none"
! width="200px" | %s
| %s
]]):format(ship_class, table.concat(list))
				else
					result = result .. ([[
! width="200px" | %s
| %s
]]):format(ship_class, table.concat(list))
				
				end
				
			end
			
		end
	end
	return result .. '|}\n'
end

p['显示舰船型号列表'] = ShowShipClassList

function ShowShipClassDetail()
	
	local ship_list = {}
	for k, _ in pairs(p.ship_data_class) do
		table.insert(ship_list,k)
	end
	table.sort(ship_list, function(a,b)
			return p.ship_data_class[a].id < p.ship_data_class[b].id
		end
	)
	
	local result = [[
{| class="wikitable  sortable"
|-
! 序号 !! 舰船 !! 阵营 !! 类型 !! 舰船型号 !! 舰船类型 !! 舰船序列 !! 舷号
]]
	result = ''

	for i, k in ipairs(ship_list) do
		local v = p.ship_data_class[k]
		local nation = math.floor(v.id / 100000)
		local ship_type = math.floor(v.id / 1000 % 10)
		if v.id < 101000 then
			nation = 0
			ship_type = 1
		end
		result = result .. ([[
|-
| %s || %s || %s || %s || %s || %s || %s || %s 
]]):format(	i, ('[[%s]]'):format(k), 
			nationIdToName(nation),
			typeIdToName(ship_type),
			v.class_des or '',
			v.type_des or '',
			v.serial_no and ('%s号舰'):format(v.serial_no) or '',
			v.pennant_code or ''
		)
	end
	return result
end

p['显示舰船型号详细信息'] = ShowShipClassDetail

--------------------------------------------------
--	工具函数
--------------------------------------------------

function nationIdToName(id)
	return mSD.NationIdToName(id, '未知')
end

function typeIdToName(id)
	return mSD.TypeIdToName(id,  '未知')
end

return p