• 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
com>Ckwng
com>Ckwng
Line 28: Line 28:
 
! style="width: 30px; text-align: center; vertical-align: middle;" | Build / Remodel Info
 
! style="width: 30px; text-align: center; vertical-align: middle;" | Build / Remodel Info
 
! style="text-align:left;" | Notes]],
 
! style="text-align:left;" | Notes]],
_column_cell_templates = {
 
id = [[| colspan="${colspan}" rowspan="${rowspan}" style="text-align: ${text_align}; background-color: ${bg_color}; padding:5px 5px 5px 5px;${extra_style}" |${values.value}]]
 
},
 
 
_columns = {
 
_columns = {
 
"id",
 
"id",
Line 53: Line 50:
 
"notes",
 
"notes",
 
},
 
},
 +
_empty_cell = [[| colspan="1" rowspan="1" |]],
 
_item_class = Ship,
 
_item_class = Ship,
_class_number_template = "${class_name} - ${class_number}",
+
_class_number_template = "${class_name}<br />${class_number}",
 
_normal_construction = "Normal",
 
_normal_construction = "Normal",
 
_large_ship_construction = "LSC",
 
_large_ship_construction = "LSC",
Line 70: Line 68:
 
table.insert(value, Formatting:format_stat(ship:japanese_name()))
 
table.insert(value, Formatting:format_stat(ship:japanese_name()))
 
end
 
end
return {values = {value = table.concat(value, " ")}, bg_color = self._transparent, text_align = self._center_align}
+
return {values = {value = table.concat(value, "<br />")}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
 
function ShipListKai:id(ship)
 
function ShipListKai:id(ship)
local back = ship:back()
 
 
return {values = {value = Formatting:format_stat(ship:id())},  
 
return {values = {value = Formatting:format_stat(ship:id())},  
bg_color = self._transparent, --Formatting:format_ship_back(back),  
+
bg_color = self._transparent,
extra_style = "", --Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
+
text_align = self._center_align,
text_align = self._center_align
 
 
}
 
}
 
end
 
end
Line 86: Line 82:
 
local class_name = class and class:base_name() or "??"
 
local class_name = class and class:base_name() or "??"
 
local class_number = ship:class_number()
 
local class_number = ship:class_number()
return {values = {value = format{self._class_number_template, class_name = class_name, class_number = class_number}}, bg_color = self._transparent, text_align = self._center_align}
+
if class_number == nil then
 +
class_number = "??"
 +
end
 +
return {values = {value = class_number and format{self._class_number_template, class_name = class_name, class_number = class_number} or class_name}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
Line 114: Line 113:
  
 
function ShipListKai:luck(ship)
 
function ShipListKai:luck(ship)
return {values = {luck = Formatting:format_stat(ship:luck())}, bg_color = self._transparent, text_align = self._center_align}
+
return {values = {value = Formatting:format_stat(ship:luck())}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
Line 165: Line 164:
 
else
 
else
 
remodel_from = Ship(self:process_item_key(remodel_from))
 
remodel_from = Ship(self:process_item_key(remodel_from))
table.insert(build_info, self._remodel_from_label .. format{self._remodel_template, link = remodel_from:link(), level = ship:remodel_level()})
+
table.insert(build_info, self._remodel_from_label .. format{self._remodel_template, link = Formatting:format_link(remodel_from:link()), level = ship:remodel_level()})
 
end
 
end
  
Line 171: Line 170:
 
if remodel_to then
 
if remodel_to then
 
remodel_to = Ship(self:process_item_key(remodel_to))
 
remodel_to = Ship(self:process_item_key(remodel_to))
table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = remodel_to:link(), level = remodel_to:remodel_level()})
+
table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = Formatting:format_link(remodel_to:link()), level = remodel_to:remodel_level()})
 
end
 
end
 
return {values = {value = table.concat(build_info, "<br />")}, bg_color = self._transparent, text_align = self._center_align}
 
return {values = {value = table.concat(build_info, "<br />")}, bg_color = self._transparent, text_align = self._center_align}
Line 179: Line 178:
 
local note = self._notes[ship]
 
local note = self._notes[ship]
 
if note then
 
if note then
local bg_color
 
if note.highlight == "outstanding" then
 
bg_color = self._outstanding_stat_color
 
elseif note.highlight == "good" then
 
bg_color = self._good_stat_color
 
else
 
bg_color = self._transparent
 
end
 
 
return {values = {value = note.note or ""}, bg_color = self._transparent, text_align = self._start_align}
 
return {values = {value = note.note or ""}, bg_color = self._transparent, text_align = self._start_align}
 
end
 
end
Line 202: Line 193:
 
end
 
end
 
return ship_base_name, ship_suffix
 
return ship_base_name, ship_suffix
 +
end
 +
 +
function BaseTable:build_rows()
 +
for index, row_values in ipairs(self._data_rows) do
 +
table.insert(self._rows, self._row_starter)
 +
if row_values == "break" then
 +
for _, column in ipairs(self._columns) do
 +
table.insert(self._rows, format(self._empty_cell))
 +
end
 +
elseif row_values == "header" then
 +
table.insert(self._rows, self._header)
 +
elseif type(row_values) == "table" then
 +
for _, column in ipairs(self._columns) do
 +
if row_values[column] then
 +
table.insert(self._rows, format(self._column_cell_templates[column] or self._cell, row_values[column]))
 +
end
 +
end
 +
else
 +
table.insert(self._rows,
 +
format{self._cell,
 +
colspan = #self._columns, rowspan = 1,
 +
text_align = self._args[self._custom_row_prefix .. row_values .. self._text_align_suffix] or self._start_align,
 +
bg_color = self._args[self._custom_row_prefix .. row_values .. self._bg_color_suffix] or self._transparent,
 +
values = {
 +
value = self._args[self._custom_row_prefix .. row_values .. self._content_suffix] or "",
 +
},
 +
}
 +
)
 +
end
 +
end
 
end
 
end
  

Revision as of 05:47, 24 April 2015

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:ResourceIcons')
local Ship = require('Module:Ship')
local StatIcons = require('Module:StatIcons')

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

local ShipListKai = BaseTable({
	_header_template = [[! No.
! Name
! Class
! Type
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightcoral;" | ${firepower}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightskyblue;" | ${torpedo}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: sandybrown;" | ${aa}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: #9C8FEE;" | ${asw}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: aquamarine;" | ${los}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: palegreen;" | ${luck}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: pink;" | ${hp}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: #F2E279;" | ${armor}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: violet;" | ${evasion}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: #72E6E6;" | ${speed}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: silver;" | ${aircraft}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightseagreen;" | ${range}
! style="width: 30px; text-align: center; vertixal-align: middle; background-color: forestgreen;" | ${fuel}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
! style="width: 30px; text-align: center; vertical-align: middle;" | Build / Remodel Info
! style="text-align:left;" | Notes]],
	_columns = {
		"id",
		"name",
		"class",
		"type",
		"firepower",
		"torpedo",
		"aa",
		"asw",
		"los",
		"luck",
		"hp",
		"armor",
		"evasion",
		"speed",
		"aircraft",
		"range",
		"fuel",
		"ammo",
		"build",
		"notes",
	},
	_empty_cell = [[| colspan="1" rowspan="1" |]],
	_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})",
})

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 {values = {value = table.concat(value, "<br />")}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:id(ship)
	return {values = {value = Formatting:format_stat(ship:id())}, 
		bg_color = self._transparent,
		text_align = self._center_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 {values = {value = class_number and format{self._class_number_template, class_name = class_name, class_number = class_number} or class_name}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:type(ship)
	return {values = {value = Formatting:format_ship_type(ship:type())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:firepower(ship)
	return {values = {value = Formatting:format_stat(ship:firepower())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:torpedo(ship)
	return {values = {value = Formatting:format_stat(ship:torpedo())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:aa(ship)
	return {values = {value = Formatting:format_stat(ship:aa())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:asw(ship)
	return {values = {value = Formatting:format_stat(ship:asw())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:los(ship)
	return {values = {value = Formatting:format_stat(ship:los())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:luck(ship)
	return {values = {value = Formatting:format_stat(ship:luck())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:hp(ship)
	return {values = {value = Formatting:format_stat(ship:hp())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:armor(ship)
	return {values = {value = Formatting:format_stat(ship:armor())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:evasion(ship)
	return {values = {value = Formatting:format_stat(ship:evasion())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:speed(ship)
	return {values = {value = Formatting:format_speed(ship:speed())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:aircraft(ship)
	return {values = {value = Formatting:format_stat(ship:total_space())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:range(ship)
	return {values = {value = Formatting:format_range(ship:range())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:fuel(ship)
	return {values = {value = Formatting:format_stat(ship:fuel())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:ammo(ship)
	return {values = {value = Formatting:format_stat(ship:ammo())}, bg_color = self._transparent, text_align = self._center_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
		table.insert(build_info, self._build_label .. table.concat(buildable_methods, ", "))
	else
		remodel_from = Ship(self:process_item_key(remodel_from))
		table.insert(build_info, self._remodel_from_label .. format{self._remodel_template, link = Formatting:format_link(remodel_from:link()), level = ship:remodel_level()})
	end

	local remodel_to = ship:remodel_to()
	if remodel_to then
		remodel_to = Ship(self:process_item_key(remodel_to))
		table.insert(build_info, self._remodel_to_label .. format{self._remodel_template, link = Formatting:format_link(remodel_to:link()), level = remodel_to:remodel_level()})
	end
	return {values = {value = table.concat(build_info, "<br />")}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipListKai:notes(ship)
	local note = self._notes[ship]
	if note then
		return {values = {value = note.note or ""}, bg_color = self._transparent, text_align = self._start_align}
	end
	return {values = {value = ""}, bg_color = self._transparent, text_align = self._start_align}
end

function ShipListKai:process_item_key(item_key)
	local split = mw.ustring.find(item_key, '/')
	local ship_base_name, ship_suffix
	if split == nil then
		ship_base_name = item_key
	else
		ship_base_name = mw.ustring.sub(item_key, 1, split - 1)
		ship_suffix = mw.ustring.sub(item_key, split + 1, -1)
	end
	return ship_base_name, ship_suffix
end

function BaseTable:build_rows()
	for index, row_values in ipairs(self._data_rows) do
			table.insert(self._rows, self._row_starter)
			if row_values == "break" then
				for _, column in ipairs(self._columns) do
					table.insert(self._rows, format(self._empty_cell))
				end
			elseif row_values == "header" then
				table.insert(self._rows, self._header)
			elseif type(row_values) == "table" then
				for _, column in ipairs(self._columns) do
					if row_values[column] then
						table.insert(self._rows, format(self._column_cell_templates[column] or self._cell, row_values[column]))
					end
				end
			else
				table.insert(self._rows, 
					format{self._cell, 
						colspan = #self._columns, rowspan = 1, 
						text_align = self._args[self._custom_row_prefix .. row_values .. self._text_align_suffix] or self._start_align, 
						bg_color = self._args[self._custom_row_prefix .. row_values .. self._bg_color_suffix] or self._transparent,
						values = {
							value = self._args[self._custom_row_prefix .. row_values .. self._content_suffix] or "",
						},
					}
				)
			end
	end
end

function ShipListKai:create_header()
	local header_icons = {
		firepower = StatIcons.firepower, 
		torpedo = StatIcons.torpedo, 
		aa = StatIcons.aa, 
		asw = StatIcons.asw, 
		los = StatIcons.los, 
		luck = StatIcons.luck, 
		hp = StatIcons.hp, 
		armor = StatIcons.armor,
		evasion = 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