Module:EquipmentCategoriesKai

Revision as of 15:43, 15 February 2023 by Chocolatecravinghobo (talk | contribs) (enable aircraft_type categories)

Documentation for this module may be created at Module:EquipmentCategoriesKai/doc

local BaseData = require('Module:BaseData')
local Formatting = require('Module:Formatting')
local Equipment = require('Module:Equipment')
local EquipmentTypesPlural = require('Module:EquipmentTypesPlural')
local format = require('Module:Core').format

local EquipmentCategoriesKai = BaseData{
	_type_category_template = "Category:${equipment_type}",
	_gun_fit_group_template = "Category:Guns in ${fit_group} fit group",
}

function EquipmentCategoriesKai:Categories(args)
	return self{_args = args}:get_categories()
end

function EquipmentCategoriesKai:create_equipment()
	local name = self._args.name or self._args[1]
	if name then
		self._equipment = Equipment(name)
	end
end

function EquipmentCategoriesKai:create_static_categories()
	table.insert(self._categories, "Category:Player equipment")
end

local type_names = {
	EquipmentTypesPlural.broad_type,
	EquipmentTypesPlural.gallery_type,
	EquipmentTypesPlural, -- exact_type
	EquipmentTypesPlural.icon_type,
	EquipmentTypesPlural.aircraft_type,
}

function EquipmentCategoriesKai:create_type_categories()
	local types = self._equipment:types()
	types[3] = self._equipment:type()
	for i, type in ipairs(types) do
		local type_name = type_names[i] and type_names[i][type]
		if type_name then
			table.insert(self._categories, format{self._type_category_template, equipment_type = type_name})
		end
	end
end

-- Chocolatecravinghobo's makeshift temporary hardcode section till something better replaces it and/or the equipment categories rework happens 

function EquipmentCategoriesKai:create_stat_categories() --Tried to utilise  Formatting:format_equipment_types from Module:Formatting  and  eq_group from Module:EquipmentInfoKai  but couldn't figure it out
	local equipment_icon = self._equipment:icon()
	local equipment_type = self._equipment:type()
	if equipment_icon == 16 then
		local aa = self._equipment:aa()
		if  aa and aa >= 8  then
			table.insert(self._categories, format{"Category:High-angle Guns with 8+ AA stat"})
		end
	elseif equipment_type == 21 then
		local aa = self._equipment:aa()
		if  aa and aa >= 9  then
			table.insert(self._categories, format{"Category:${equipment_type} with 9+ AA stat", equipment_type = Formatting:format_equipment_type_plural(equipment_type)})
		end
	elseif equipment_type == 12 or equipment_type == 13 or equipment_type == 93 then
		local aa = self._equipment:aa()
		if aa and aa >= 2 then
			table.insert(self._categories, format{"Category:Air Radars"})
		end
		local los = self._equipment:los()
		if los and los >=  5 then
			table.insert(self._categories, format{"Category:Surface Radars"})
		end
	elseif equipment_type == 23 or equipment_type == 43 or equipment_type == 44 then
		table.insert(self._categories, format{"Category:Items"})
	elseif equipment_type == 7 or equipment_type == 8 or equipment_type == 10 or equipment_type == 11 or equipment_type == 25 or equipment_type == 26 or equipment_icon == 47 then
		local asw = self._equipment:asw()
		if asw and asw >= 7 then
			table.insert(self._categories, format{"Category:Aircraft with 7+ ASW stat"})
		end
	end
end

-- end of Chocolatecravinghobo makeshift section

function EquipmentCategoriesKai:create_rarity_categories()
	local rarity = self._equipment:rarity()
	if rarity then
		table.insert(self._categories, format{"Category:${rarity} rarity equipment", rarity = Formatting:format_equipment_rarity(rarity)})
	end
end

function EquipmentCategoriesKai:create_obtainability_categories()
	local buildable, obtainable_through_upgrade = self._equipment:buildable(), self._equipment:improvement_from() --improvable category disabled.  _improvements = true,  causes "Lua error in Module:EquipmentData at line 507: attempt to index field '_improvements' (a boolean value)."
	--local buildable, improvable, obtainable_through_upgrade = self._equipment:buildable(), self._equipment:improvement_products(), self._equipment:improvement_from()
	if buildable then
		table.insert(self._categories, format{"Category:Equipment buildable in Development"})
	end
	if improvable then
		table.insert(self._categories, format{"Category:Equipment improvable in Akashi's Improvement Arsenal"})
	end
	if obtainable_through_upgrade then
		table.insert(self._categories, format{"Category:Equipment obtainable by upgrade through Akashi's Improvement Arsenal"})
	end
end

function EquipmentCategoriesKai:write_categories()
	local links = {}
	for _, category in ipairs(self._categories) do
		table.insert(links, Formatting:format_link(category))
	end
	return table.concat(links)
end

function EquipmentCategoriesKai:get_categories()
	self._categories = {}
	self:create_equipment()
	if self._equipment then
		self:create_categories()
	end
	return self:write_categories()
end

function EquipmentCategoriesKai:create_categories()
	self:create_static_categories()
	self:create_type_categories()
	self:create_stat_categories() --CCH
	--self:create_rarity_categories()
	self:create_obtainability_categories()
end

return EquipmentCategoriesKai