• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Difference between revisions of "Module:EquipmentCategoriesKai"

From Kancolle Wiki
Jump to navigation Jump to search
m (fix)
 
(24 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
 
local Equipment = require('Module:Equipment')
 
local Equipment = require('Module:Equipment')
 
+
local EquipmentTypesPlural = require('Module:EquipmentTypesPlural')
 
local format = require('Module:Core').format
 
local format = require('Module:Core').format
  
Line 11: Line 11:
  
 
function EquipmentCategoriesKai:Categories(args)
 
function EquipmentCategoriesKai:Categories(args)
return self{
+
return self{_args = args}:get_categories()
_args = args
 
}:get_categories()
 
 
end
 
end
  
Line 26: Line 24:
 
table.insert(self._categories, "Category:Player equipment")
 
table.insert(self._categories, "Category:Player equipment")
 
end
 
end
 +
 +
local type_names = {
 +
EquipmentTypesPlural.broad_type,
 +
EquipmentTypesPlural.gallery_type,
 +
EquipmentTypesPlural, -- exact_type
 +
EquipmentTypesPlural.icon_type,
 +
-- EquipmentTypesPlural.aircraft_type,
 +
}
  
 
function EquipmentCategoriesKai:create_type_categories()
 
function EquipmentCategoriesKai:create_type_categories()
local equipment_type = self._equipment:type()
+
local types = self._equipment:types()
if equipment_type then
+
types[3] = self._equipment:type()
table.insert(self._categories, format{self._type_category_template, equipment_type = Formatting:format_equipment_type_plural(equipment_type)})
+
for i, type in ipairs(types) do
end
+
local type_name = type_names[i] and type_names[i][type]
if equipment_type == 3 or equipment_type == 38 then
+
if type_name then
local fit_group = self._equipment:gun_fit_group()
+
table.insert(self._categories, format{self._type_category_template, equipment_type = type_name})
if fit_group then
 
table.insert(self._categories, format{self._gun_fit_group_template, fit_group = fit_group})
 
 
end
 
end
 
end
 
end
 +
-- if types[3] == 3 or types[3] == 38 then
 +
-- local fit_group = self._equipment:gun_fit_group()
 +
-- if fit_group then
 +
-- table.insert(self._categories, format{self._gun_fit_group_template, fit_group = fit_group})
 +
-- end
 +
-- end
 
end
 
end
  
 
-- Chocolatecravinghobo's makeshift temporary hardcode section till something better replaces it and/or the equipment categories rework happens  
 
-- Chocolatecravinghobo's makeshift temporary hardcode section till something better replaces it and/or the equipment categories rework happens  
 
function EquipmentCategoriesKai:create_icon_categories() --CCH
 
local equipment_icon = self._equipment:icon()
 
if equipment_icon == 16 then
 
table.insert(self._categories, format{"Category:High-angle Guns"})
 
elseif equipment_icon == 45 then
 
table.insert(self._categories, format{"Category:Night Fighter Aircraft"})
 
elseif equipment_icon == 46 then
 
table.insert(self._categories, format{"Category:Night Torpedo Bombers"})
 
elseif equipment_icon == 47 then
 
table.insert(self._categories, format{"Category:Land-based Patrol Aircraft"})
 
elseif equipment_icon == 48 then
 
table.insert(self._categories, format{"Category:Land-based Assault Aircraft"})
 
elseif equipment_icon == 50 then
 
table.insert(self._categories, format{"Category:Night Recon Seaplanes"})
 
end
 
end
 
  
 
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
 
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_icon = self._equipment:icon()
 
local equipment_type = self._equipment:type()
 
local equipment_type = self._equipment:type()
if equipment_icon == 16 then
+
-- if equipment_icon == 16 then --HA/MG AA categories disabled due to being phased out. Could make a comeback so disabled rather than deleted.
if self._equipment:aa() >= 8  then
+
-- local aa = self._equipment:aa()
table.insert(self._categories, format{"Category:High-angle Guns with 8+ AA stat"})
+
-- 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
 +
if 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
 
end
elseif equipment_type == 21 then
+
elseif equipment_type == 23 or equipment_type == 43 or equipment_type == 44 then
if self._equipment:aa() >= then
+
table.insert(self._categories, format{"Category:Items"})
table.insert(self._categories, format{"Category:${equipment_type} with 9+ AA stat", equipment_type = Formatting:format_equipment_type_plural(equipment_type)})
+
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
 +
--equip ID category hardcode section
 +
local equipment_id = self._equipment:id()
 +
if 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_type == 47 or equipment_type == 57 then --All non-fighter aircraft
 +
local equipment_aircraft = self._equipment:types()
 +
local equipment_aircraft = equipment_aircraft[5]
 +
if equipment_id == 207 or equipment_aircraft == 32 then --all Zuiuns but id 207 use aircraft_type 32
 +
table.insert(self._categories, format{"Category:Zuiuns"})  
 
end
 
end
elseif eq_type == 12 or eq_type == 13 or eq_type == 93 then
+
if equipment_id == 154 or equipment_id == 242 or equipment_id == 243 or equipment_id == 244 or equipment_id == 244 or equipment_id == 320 or equipment_icon == 45 or equipment_icon == 46 then
if self._equipment:aa() >= 2 then
+
table.insert(self._categories, format{"Category:Carrier-based Night Aircraft"})
table.insert(self._categories, format{"Category:Air Radar"})
 
 
end
 
end
if self._equipment:los() >= 5 then
+
if equipment_id == 93 or equipment_id == 94 or equipment_id == 143 or equipment_id == 144 or equipment_id == 343 or equipment_id == 374 or equipment_id == 466 or equipment_id == 481 or equipment_id == 545 --Carrier-based Torpedo Bombers
table.insert(self._categories, format{"Category:Surface Radar"})
+
or equipment_id == 99 or equipment_id == 100 or equipment_id == 154 or equipment_id == 319 or equipment_id == 320 or equipment_id == 474 or equipment_id == 475 or equipment_id == 476 or equipment_id == 487 --Carrier-based Dive Bombers
 +
or equipment_id == 79 or equipment_id == 80 or equipment_id == 81 or equipment_id == 208 or equipment_id == 237 or equipment_id == 322 or equipment_id == 323 or equipment_id == 490 --Seaplane Bombers
 +
or equipment_id == 491 --Anti-submarine Patrol Aircraft
 +
or equipment_id == 199 or equipment_id == 200 --Jet-powered Fighter-Bombers
 +
or equipment_id == 170 or equipment_id == 224 or equipment_id == 388 or equipment_id == 404 or equipment_id == 405 or equipment_id == 406 or equipment_id == 433 or equipment_id == 444 or equipment_id == 453 or equipment_id == 454 or equipment_id == 479 or equipment_id == 484 or equipment_id == 504 then --Land-based Attack Aircraft
 +
table.insert(self._categories, format{"Category:Planes with Anti-Air Resistance"})
 
end
 
end
elseif eq_type == 7 or eq_type == 8 or eq_type == 10 or eq_type == 11 or eq_type == 25 or eq_type == 26 or eq_icon == 47 then
+
if equipment_type == 7 then
if eq_type == 25 then
+
if equipment_id == 64 or equipment_id == 148 or equipment_id == 233 or equipment_id == 277 or equipment_id == 305 or equipment_id == 306 or equipment_id == 319 or equipment_id == 320 or equipment_id == 391 or equipment_id == 392 or equipment_id == 420 or equipment_id == 421 or equipment_id == 474 then
local equipment_id = self._equipment:id()
+
table.insert(self._categories, format{"Category:Anti-Installation Dive Bombers"})
if equipment_id == 326 or equipment_id == 327 then
 
table.insert(self._categories, format{"Category:Helicopters"})
 
 
end
 
end
 
end
 
end
if self._equipment:asw() >= 7 then
+
elseif equipment_id == 350 or equipment_id == 351 or equipment_id == 352 then
table.insert(self._categories, format{"Category:Aircraft with with 7+ ASW stat"})
+
table.insert(self._categories, format{"Category:High Altitude Interceptors"})
 +
elseif equipment_id == 213 or equipment_id == 214 or equipment_id == 383 or equipment_id == 441 or equipment_id == 443 or equipment_id == 457 or equipment_id == 461 or equipment_id == 512 then
 +
table.insert(self._categories, format{"Category:Late Model Submarine Torpedoes"})
 +
elseif equipment_type == 15 then
 +
if equipment_id == 44 or equipment_id == 45 or equipment_id == 287 or equipment_id == 288 or equipment_id == 377 or equipment_id == 472 then
 +
table.insert(self._categories, format{"Category:Depth Charge Projectors"})
 +
elseif equipment_id == 226 or equipment_id == 227 or equipment_id == 378 or equipment_id == 439 or equipment_id == 488 then
 +
table.insert(self._categories, format{"Category:Depth Charge Racks"})
 +
elseif equipment_id == 346 or equipment_id == 347 then
 +
table.insert(self._categories, format{"Category:ASW Mortars"})
 +
else table.insert(self._categories, format{"Category:Unknown-type Depth Charge"}) --Not a category, acts as a notice/warning.
 
end
 
end
 
end
 
end
Line 100: Line 132:
  
 
function EquipmentCategoriesKai:create_obtainability_categories()
 
function EquipmentCategoriesKai:create_obtainability_categories()
local buildable, improvable, obtainable_through_upgrade = self._equipment:buildable(), self._equipment:improvement_products(), self._equipment:improvement_from()
+
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
 
if buildable then
 
table.insert(self._categories, format{"Category:Equipment buildable in Development"})
 
table.insert(self._categories, format{"Category:Equipment buildable in Development"})
Line 132: Line 165:
 
self:create_static_categories()
 
self:create_static_categories()
 
self:create_type_categories()
 
self:create_type_categories()
self:create_icon_categories() --CCH
 
 
self:create_stat_categories() --CCH
 
self:create_stat_categories() --CCH
 
--self:create_rarity_categories()
 
--self:create_rarity_categories()

Latest revision as of 19:33, 12 August 2024

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
--	if types[3] == 3 or types[3] == 38 then
--		local fit_group = self._equipment:gun_fit_group()
--		if fit_group then
--			table.insert(self._categories, format{self._gun_fit_group_template, fit_group = fit_group})
--		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	--HA/MG AA categories disabled due to being phased out. Could make a comeback so disabled rather than deleted.
--		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
	if 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
	--equip ID category hardcode section
	local equipment_id = self._equipment:id()
	if 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_type == 47 or equipment_type == 57 then --All non-fighter aircraft
		local equipment_aircraft = self._equipment:types()
		local equipment_aircraft = equipment_aircraft[5]
		if equipment_id == 207 or equipment_aircraft == 32 then --all Zuiuns but id 207 use aircraft_type 32
			table.insert(self._categories, format{"Category:Zuiuns"}) 
		end
		if equipment_id == 154 or equipment_id == 242 or equipment_id == 243 or equipment_id == 244 or equipment_id == 244 or equipment_id == 320 or equipment_icon == 45 or equipment_icon == 46 then
			table.insert(self._categories, format{"Category:Carrier-based Night Aircraft"})
		end
		if equipment_id == 93 or equipment_id == 94 or equipment_id == 143 or equipment_id == 144 or equipment_id == 343 or equipment_id == 374 or equipment_id == 466 or equipment_id == 481 or equipment_id == 545 --Carrier-based Torpedo Bombers
		or equipment_id == 99 or equipment_id == 100 or equipment_id == 154 or equipment_id == 319 or equipment_id == 320 or equipment_id == 474 or equipment_id == 475 or equipment_id == 476 or equipment_id == 487 --Carrier-based Dive Bombers
		or equipment_id == 79 or equipment_id == 80 or equipment_id == 81 or equipment_id == 208 or equipment_id == 237 or equipment_id == 322 or equipment_id == 323 or equipment_id == 490 --Seaplane Bombers
		or equipment_id == 491 --Anti-submarine Patrol Aircraft
		or equipment_id == 199 or equipment_id == 200 --Jet-powered Fighter-Bombers 
		or equipment_id == 170 or equipment_id == 224 or equipment_id == 388 or equipment_id == 404 or equipment_id == 405 or equipment_id == 406 or equipment_id == 433 or equipment_id == 444 or equipment_id == 453 or equipment_id == 454 or equipment_id == 479 or equipment_id == 484 or equipment_id == 504 then --Land-based Attack Aircraft 
			table.insert(self._categories, format{"Category:Planes with Anti-Air Resistance"})
		end
		if equipment_type == 7 then
			if equipment_id == 64 or equipment_id == 148 or equipment_id == 233 or equipment_id == 277 or equipment_id == 305 or equipment_id == 306 or equipment_id == 319 or equipment_id == 320 or equipment_id == 391 or equipment_id == 392 or equipment_id == 420 or equipment_id == 421 or equipment_id == 474 then
				table.insert(self._categories, format{"Category:Anti-Installation Dive Bombers"})
			end
		end
	elseif equipment_id == 350 or equipment_id == 351 or equipment_id == 352 then
		table.insert(self._categories, format{"Category:High Altitude Interceptors"})
	elseif equipment_id == 213 or equipment_id == 214 or equipment_id == 383 or equipment_id == 441 or equipment_id == 443 or equipment_id == 457 or equipment_id == 461 or equipment_id == 512 then
		table.insert(self._categories, format{"Category:Late Model Submarine Torpedoes"})
	elseif equipment_type == 15 then
		if equipment_id == 44 or equipment_id == 45 or equipment_id == 287 or equipment_id == 288 or equipment_id == 377 or equipment_id == 472 then
			table.insert(self._categories, format{"Category:Depth Charge Projectors"})
		elseif equipment_id == 226 or equipment_id == 227 or equipment_id == 378 or equipment_id == 439 or equipment_id == 488 then
			table.insert(self._categories, format{"Category:Depth Charge Racks"})
		elseif equipment_id == 346 or equipment_id == 347 then
			table.insert(self._categories, format{"Category:ASW Mortars"})
		else table.insert(self._categories, format{"Category:Unknown-type Depth Charge"}) --Not a category, acts as a notice/warning.
		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