• 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:ShipListKai"

From Kancolle Wiki
Jump to navigation Jump to search
Line 8: Line 8:
  
 
local ShipListKai = BaseTable({
 
local ShipListKai = BaseTable({
 +
_table_start = [[{| class="wikitable typography-xl-optout" style="width: -moz-fit-content; width: -webkit-fit-content; width: fit-content; text-align: center;"]],
 
_header_template = [[! style="position:sticky; top: 0px;" | No.
 
_header_template = [[! style="position:sticky; top: 0px;" | No.
 
! style="position:sticky; top: 0px; width: 100px;" | Name
 
! style="position:sticky; top: 0px; width: 100px;" | Name
Line 60: Line 61:
 
"notes",
 
"notes",
 
},
 
},
_cell = [[| style="text-align: ${text_align}; padding:5px 5px 5px 5px;" |${value}]],
+
_cell = [[| style="${text_align}; padding:5px 5px 5px 5px;" |${value}]],
 
_item_class = Ship,
 
_item_class = Ship,
 
_class_number_template = "${class_name}<br />#${class_number}",
 
_class_number_template = "${class_name}<br />#${class_number}",
Line 81: Line 82:
 
table.insert(value, Formatting:format_stat(ship:japanese_name()))
 
table.insert(value, Formatting:format_stat(ship:japanese_name()))
 
end
 
end
return {value = Formatting:id_span(tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(ship:name(), "%s+", self._dash))), self._fragment_prefix, table.concat(value, "<br />")), text_align = self._start_align}
+
return {value = Formatting:id_span(tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(ship:name(), "%s+", self._dash))), self._fragment_prefix, table.concat(value, "<br />")), text_align = "text-align: " + self._start_align}
 
end
 
end
  
 
function ShipListKai:id(ship)
 
function ShipListKai:id(ship)
 
return {value = Formatting:format_stat(ship:true_id() or ship:id()),
 
return {value = Formatting:format_stat(ship:true_id() or ship:id()),
text_align = self._center_align,
+
text_align = "",
 
}
 
}
 
end
 
end
Line 97: Line 98:
 
class_number = "??"
 
class_number = "??"
 
end
 
end
return {value = class_number and format{self._class_number_template, class_name = class_name, class_number = class_number} or class_name, text_align = self._start_align}
+
return {value = class_number and format{self._class_number_template, class_name = class_name, class_number = class_number} or class_name, text_align = "text-align: " + self._start_align}
 
end
 
end
  
 
function ShipListKai:type(ship)
 
function ShipListKai:type(ship)
return {value = Formatting:format_ship_code(ship:type()), text_align = self._start_align}
+
return {value = Formatting:format_ship_code(ship:type()), text_align = "text-align: " + self._start_align}
 
end
 
end
  
Line 109: Line 110:
 
firepower_max = ship:firepower()
 
firepower_max = ship:firepower()
 
end
 
end
return {value = Formatting:format_stat(firepower_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(firepower_max), text_align = ""}
 
end
 
end
  
Line 117: Line 118:
 
torpedo_max = ship:torpedo()
 
torpedo_max = ship:torpedo()
 
end
 
end
return {value = Formatting:format_stat(torpedo_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(torpedo_max), text_align = ""}
 
end
 
end
  
Line 135: Line 136:
 
    night_battle = night_battle + torpedo_max
 
    night_battle = night_battle + torpedo_max
 
end
 
end
return {value = Formatting:format_stat(night_battle), text_align = self._center_align}
+
return {value = Formatting:format_stat(night_battle), text_align = ""}
 
end
 
end
  
Line 143: Line 144:
 
aa_max = ship:aa()
 
aa_max = ship:aa()
 
end
 
end
return {value = Formatting:format_stat(aa_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(aa_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:asw(ship)
 
function ShipListKai:asw(ship)
return {value = Formatting:format_stat(ship:asw()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:asw()), text_align = ""}
 
end
 
end
  
Line 155: Line 156:
 
asw_max = ship:asw()
 
asw_max = ship:asw()
 
end
 
end
return {value = Formatting:format_stat(asw_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(asw_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:los(ship)
 
function ShipListKai:los(ship)
return {value = Formatting:format_stat(ship:los()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:los()), text_align = ""}
 
end
 
end
  
Line 167: Line 168:
 
los_max = ship:los()
 
los_max = ship:los()
 
end
 
end
return {value = Formatting:format_stat(los_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(los_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:luck(ship)
 
function ShipListKai:luck(ship)
return {value = Formatting:format_stat(ship:luck()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:luck()), text_align = ""}
 
end
 
end
  
Line 179: Line 180:
 
luck_max = ship:luck()
 
luck_max = ship:luck()
 
end
 
end
return {value = Formatting:format_stat(luck_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(luck_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:hp(ship)
 
function ShipListKai:hp(ship)
return {value = Formatting:format_stat(ship:hp()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:hp()), text_align = ""}
 
end
 
end
  
Line 191: Line 192:
 
armor_max = ship:armor()
 
armor_max = ship:armor()
 
end
 
end
return {value = Formatting:format_stat(armor_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(armor_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:evasion(ship)
 
function ShipListKai:evasion(ship)
return {value = Formatting:format_stat(ship:evasion()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:evasion()), text_align = ""}
 
end
 
end
  
Line 203: Line 204:
 
evasion_max = ship:evasion()
 
evasion_max = ship:evasion()
 
end
 
end
return {value = Formatting:format_stat(evasion_max), text_align = self._center_align}
+
return {value = Formatting:format_stat(evasion_max), text_align = ""}
 
end
 
end
  
 
function ShipListKai:speed(ship)
 
function ShipListKai:speed(ship)
return {value = Formatting:format_speed(ship:speed()), text_align = self._center_align}
+
return {value = Formatting:format_speed(ship:speed()), text_align = ""}
 
end
 
end
  
 
function ShipListKai:aircraft(ship)
 
function ShipListKai:aircraft(ship)
return {value = Formatting:format_stat(ship:total_space()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:total_space()), text_align = ""}
 
end
 
end
  
 
function ShipListKai:range(ship)
 
function ShipListKai:range(ship)
return {value = Formatting:format_range(ship:range()), text_align = self._center_align}
+
return {value = Formatting:format_range(ship:range()), text_align = ""}
 
end
 
end
  
 
function ShipListKai:fuel(ship)
 
function ShipListKai:fuel(ship)
return {value = Formatting:format_stat(ship:fuel()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:fuel()), text_align = ""}
 
end
 
end
  
 
function ShipListKai:ammo(ship)
 
function ShipListKai:ammo(ship)
return {value = Formatting:format_stat(ship:ammo()), text_align = self._center_align}
+
return {value = Formatting:format_stat(ship:ammo()), text_align = ""}
 
end
 
end
  
Line 271: Line 272:
 
table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = Formatting:fragment_link(tostring(remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(remodel_to:name(), "%s+", self._dash))), self._fragment_prefix, remodel_to:name()), level = remodel_level})
 
table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = Formatting:fragment_link(tostring(remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(remodel_to:name(), "%s+", self._dash))), self._fragment_prefix, remodel_to:name()), level = remodel_level})
 
end
 
end
return {value = table.concat(build_info, "<br />"), text_align = self._start_align}
+
return {value = table.concat(build_info, "<br />"), text_align = "text-align: " + self._start_align}
 
end
 
end
  
Line 277: Line 278:
 
local note = self._notes[ship]
 
local note = self._notes[ship]
 
if note then
 
if note then
return {value = note.note or "", text_align = self._start_align}
+
return {value = note.note or "", text_align = "text-align: " + self._start_align}
 
end
 
end
return {value = "", text_align = self._start_align}
+
return {value = "", text_align = "text-align: " + self._start_align}
 
end
 
end
  

Revision as of 03:48, 20 May 2022

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

local BaseTable = require('Module:BaseTable')
local Formatting = require('Module:Formatting')
local ResourceIcons = require('Module:Data/Asset')
local Ship = require('Module:Ship')
local StatIcons = require('Module:Data/Asset')

local format = require('Module:Core').format

local ShipListKai = BaseTable({
	_table_start = [[{| class="wikitable typography-xl-optout" style="width: -moz-fit-content; width: -webkit-fit-content; width: fit-content; text-align: center;"]],
	_header_template = [[! style="position:sticky; top: 0px;" | No.
! style="position:sticky; top: 0px; width: 100px;" | Name
! style="position:sticky; top: 0px; width: 75px;" | Class
! style="position:sticky; top: 0px;" | Type
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: lightcoral;" | ${firepower}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: lightskyblue;" | ${torpedo}
! style="position:sticky; top: 0px; width: 24px; text-align: center; vertical-align: middle; background-color: slategrey;" | ${firepower}${torpedo}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: sandybrown;" | ${aa}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: #9C8FEE;" | ${asw}
! style="position:sticky; top: 0px; white-space:nowrap; width: 30px; text-align: center; vertical-align: middle; background-color: #9C8FEE;" | ${asw}+
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: aquamarine;" | ${los}
! style="position:sticky; top: 0px; white-space:nowrap; width: 30px; text-align: center; vertical-align: middle; background-color: aquamarine;" | ${los}+
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: palegreen;" | ${luck}
! style="position:sticky; top: 0px; white-space:nowrap; width: 30px; text-align: center; vertical-align: middle; background-color: palegreen;" | ${luck}+
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: pink;" | ${hp}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: #F2E279;" | ${armor}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: violet;" | ${evasion}
! style="position:sticky; top: 0px; white-space:nowrap; width: 30px; text-align: center; vertical-align: middle; background-color: violet;" | ${evasion}+
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: #72E6E6;" | ${speed}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: silver;" | ${aircraft}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: lightseagreen;" | ${range}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertixal-align: middle; background-color: forestgreen;" | ${fuel}
! style="position:sticky; top: 0px; width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
! style="position:sticky; top: 0px; width: 250px; text-align: center; vertical-align: middle;" | Build / Remodel Info
! style="position:sticky; top: 0px; text-align:left;" | Notes]],
	_columns = {
		"id",
		"name",
		"class",
		"type",
		"firepower",
		"torpedo",
		"night_battle",
		"aa",
		"asw",
		"asw_max",
		"los",
		"los_max",
		"luck",
		"luck_max",
		"hp",
		"armor",
		"evasion",
		"evasion_max",
		"speed",
		"aircraft",
		"range",
		"fuel",
		"ammo",
		"build",
		"notes",
	},
	_cell = [[| style="${text_align}; padding:5px 5px 5px 5px;" |${value}]],
	_item_class = Ship,
	_class_number_template = "${class_name}<br />#${class_number}",
	_normal_construction = "Normal",
	_large_ship_construction = "LSC",
	_build_label = "Construction: ",
	_remodel_from_label = "Remodel From: ",
	_remodel_to_label = "Remodel To: ",
	_remodel_template = "${link} (Level ${level})",
	_unbuildable_label = "''Unbuildable''",
	_fragment_prefix = "shiplistkai",
	_dash = "-",
})

function ShipListKai:name(ship)
	local link, text, section = ship:link()
	local value = {Formatting:format_link(link, text, section)}
	local japanese_name = ship:japanese_name()
	if japanese_name and (text or link) ~= japanese_name then
		table.insert(value, Formatting:format_stat(ship:japanese_name()))
	end
	return {value = Formatting:id_span(tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(ship:name(), "%s+", self._dash))), self._fragment_prefix, table.concat(value, "<br />")), text_align = "text-align: " + self._start_align}
end

function ShipListKai:id(ship)
	return {value = Formatting:format_stat(ship:true_id() or ship:id()),
		text_align = "",
	}
end

function ShipListKai:class(ship)
	local class = ship:class()
	local class_name = class and class:base_name() or "??"
	local class_number = ship:class_number()
	if class_number == nil then
		class_number = "??"
	end
	return {value = class_number and format{self._class_number_template, class_name = class_name, class_number = class_number} or class_name, text_align = "text-align: " + self._start_align}
end

function ShipListKai:type(ship)
	return {value = Formatting:format_ship_code(ship:type()), text_align = "text-align: " + self._start_align}
end

function ShipListKai:firepower(ship)
	local firepower_max = ship:firepower_max()
	if firepower_max == false then
		firepower_max = ship:firepower()
	end
	return {value = Formatting:format_stat(firepower_max), text_align = ""}
end

function ShipListKai:torpedo(ship)
	local torpedo_max = ship:torpedo_max()
	if torpedo_max == false then
		torpedo_max = ship:torpedo()
	end
	return {value = Formatting:format_stat(torpedo_max), text_align = ""}
end

function ShipListKai:night_battle(ship)
	local firepower_max = ship:firepower_max()
	if firepower_max == false then
		firepower_max = ship:firepower()
	end
	local torpedo_max = ship:torpedo_max()
	if torpedo_max == false then
		torpedo_max = ship:torpedo()
	end
	local night_battle = firepower_max
	if not firepower_max then
	    night_battle = torpedo_max
	elseif torpedo_max then
	    night_battle = night_battle + torpedo_max
	end
	return {value = Formatting:format_stat(night_battle), text_align = ""}
end

function ShipListKai:aa(ship)
	local aa_max = ship:aa_max()
	if aa_max == false then
		aa_max = ship:aa()
	end
	return {value = Formatting:format_stat(aa_max), text_align = ""}
end

function ShipListKai:asw(ship)
	return {value = Formatting:format_stat(ship:asw()), text_align = ""}
end

function ShipListKai:asw_max(ship)
	local asw_max = ship:asw_max()
	if asw_max == false then
		asw_max = ship:asw()
	end
	return {value = Formatting:format_stat(asw_max), text_align = ""}
end

function ShipListKai:los(ship)
	return {value = Formatting:format_stat(ship:los()), text_align = ""}
end

function ShipListKai:los_max(ship)
	local los_max = ship:los_max()
	if los_max == false then
		los_max = ship:los()
	end
	return {value = Formatting:format_stat(los_max), text_align = ""}
end

function ShipListKai:luck(ship)
	return {value = Formatting:format_stat(ship:luck()), text_align = ""}
end

function ShipListKai:luck_max(ship)
	local luck_max = ship:luck_max()
	if luck_max == false then
		luck_max = ship:luck()
	end
	return {value = Formatting:format_stat(luck_max), text_align = ""}
end

function ShipListKai:hp(ship)
	return {value = Formatting:format_stat(ship:hp()), text_align = ""}
end

function ShipListKai:armor(ship)
	local armor_max = ship:armor_max()
	if armor_max == false then
		armor_max = ship:armor()
	end
	return {value = Formatting:format_stat(armor_max), text_align = ""}
end

function ShipListKai:evasion(ship)
	return {value = Formatting:format_stat(ship:evasion()), text_align = ""}
end

function ShipListKai:evasion_max(ship)
	local evasion_max = ship:evasion_max()
	if evasion_max == false then
		evasion_max = ship:evasion()
	end
	return {value = Formatting:format_stat(evasion_max), text_align = ""}
end

function ShipListKai:speed(ship)
	return {value = Formatting:format_speed(ship:speed()), text_align = ""}
end

function ShipListKai:aircraft(ship)
	return {value = Formatting:format_stat(ship:total_space()), text_align = ""}
end

function ShipListKai:range(ship)
	return {value = Formatting:format_range(ship:range()), text_align = ""}
end

function ShipListKai:fuel(ship)
	return {value = Formatting:format_stat(ship:fuel()), text_align = ""}
end

function ShipListKai:ammo(ship)
	return {value = Formatting:format_stat(ship:ammo()), text_align = ""}
end

function ShipListKai:build(ship)
	local remodel_from = ship:remodel_from()
	local build_info = {}
	if not remodel_from then
		local buildable = ship:buildable()
		local buildable_lsc = ship:buildable_lsc()
		local buildable_methods = {}
		if buildable then
			table.insert(buildable_methods, self._normal_construction)
		end
		if buildable_lsc then
			table.insert(buildable_methods, self._large_ship_construction)
		end
		if #buildable_methods == 0 then
			table.insert(build_info, self._unbuildable_label)
		else
			table.insert(build_info, self._build_label .. table.concat(buildable_methods, ", "))
		end
	else
		remodel_from = Ship(remodel_from)
		local remodel_level = ship:remodel_level()
		if ship:remodel_blueprint() or ship:remodel_catapult() then
			remodel_level = table.concat({remodel_level, Formatting:format_remodel_items(ship:remodel_blueprint(), ship:remodel_catapult())}, " + ")
		end
		table.insert(build_info, self._remodel_from_label .. format{self._remodel_template, link = Formatting:fragment_link(tostring(remodel_from:api_id() or mw.ustring.lower(mw.ustring.gsub(remodel_from:name(), "%s+", self._dash))), self._fragment_prefix, remodel_from:name()), level = remodel_level})
	end

	local remodel_to = ship:remodel_to()
	if remodel_to then
		local remodel_level
		if remodel_to == ship:remodel_from() then
			remodel_level = ship:remodel_to_level()
			if ship:remodel_to_blueprint() or ship:remodel_to_catapult() then
				remodel_level = table.concat({remodel_level, Formatting:format_remodel_items(ship:remodel_to_blueprint(), ship:remodel_to_catapult())}, " + ")
			end
			remodel_to = remodel_from
		else
			remodel_to = Ship(remodel_to)
			remodel_level = remodel_to:remodel_level()
			if remodel_to:remodel_blueprint() or remodel_to:remodel_catapult() then
				remodel_level = table.concat({remodel_level, Formatting:format_remodel_items(remodel_to:remodel_blueprint(), remodel_to:remodel_catapult())}, " + ")
			end
		end
		table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = Formatting:fragment_link(tostring(remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(remodel_to:name(), "%s+", self._dash))), self._fragment_prefix, remodel_to:name()), level = remodel_level})
	end
	return {value = table.concat(build_info, "<br />"), text_align = "text-align: " + self._start_align}
end

function ShipListKai:notes(ship)
	local note = self._notes[ship]
	if note then
		return {value = note.note or "", text_align = "text-align: " + self._start_align}
	end
	return {value = "", text_align = "text-align: " + self._start_align}
end

ShipListKai.process_item_key = Ship.process_item_key

ShipListKai.build_rows = ShipListKai.build_rows_breaks_as_empty_rows

function ShipListKai:create_header()
	local header_icons = {
		firepower = StatIcons.firepower, 
		torpedo = StatIcons.torpedo, 
		aa = StatIcons.aa, 
		asw = StatIcons.asw,
		asw_max = StatIcons.asw, 
		los = StatIcons.los, 
		los_max = StatIcons.los, 
		luck = StatIcons.luck, 
		luck_max = StatIcons.luck, 
		hp = StatIcons.hp, 
		armor = StatIcons.armor,
		evasion = StatIcons.evasion,
		evasion_max = StatIcons.evasion,
		speed = StatIcons.speed,
		aircraft = StatIcons.aircraft,
		range = StatIcons.range,
		fuel = ResourceIcons.fuel,
		ammo = ResourceIcons.ammo,
	}
	for key, value in pairs(header_icons) do
		header_icons[key] = Formatting:format_image{value, caption = Formatting:format_stat_name(key)}
	end
	self._header = format(self._header_template, header_icons)
end

return ShipListKai