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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(Fix text-align, fix no bg color when no data)
com>Ckwng
(Completely change call signature)
Line 53: Line 53:
 
function ShipModernizationListKai:class(pair)
 
function ShipModernizationListKai:class(pair)
 
self._left = pair[1]
 
self._left = pair[1]
 +
self._left_modernization = self._left and self._left:modernization() or false
 
self._right = pair[2]
 
self._right = pair[2]
self._left_modernization = self._left and self._left:modernization() or false
 
 
self._right_modernization = self._right and self._right:modernization() or false
 
self._right_modernization = self._right and self._right:modernization() or false
local class = (pair[1] or pair[2]):class()
+
local left_class, right_class, class_name = self._left and self._left:class(), self._right and self._right:class(), false
return {values = {value = class and class:base_name() or self._question_marks}, bg_color = self._transparent, text_align = self._center_align}
+
if left_class or right_class then
 +
if left_class == right_class or not right_class then
 +
class_name = left_class:base_name()
 +
elseif not left_class then
 +
class_name = right_class:base_name()
 +
else
 +
class_name = left_class:base_name() .. "/" .. right_class:base_name()
 +
end
 +
end
 +
return {values = {value = class_name or self._question_marks}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
Line 192: Line 201:
 
local left = false
 
local left = false
 
local right = false
 
local right = false
local even = false
 
 
for _, item in ipairs(self._items) do
 
for _, item in ipairs(self._items) do
 
if type(item) == "string" then
 
if type(item) == "string" then
if item == "empty" then
+
table.insert(items, {left, right})
if even then
+
left, right = false, false
right = false
+
if item == "break" then
table.insert(items, {left, right})
 
left = false
 
right = false
 
even = false
 
else
 
left = false
 
even = true
 
end
 
else
 
if even then
 
table.insert(items, {left, right})
 
left = false
 
even = false
 
end
 
 
table.insert(items, item)
 
table.insert(items, item)
 
end
 
end
elseif even then
+
elseif left then
 +
if right then
 +
table.insert(items, {left, right})
 +
end
 
right = item
 
right = item
table.insert(items, {left, right})
 
left = false
 
right = false
 
even = false
 
 
else
 
else
 
left = item
 
left = item
even = true
+
right = false
 
end
 
end
 
end
 
end
if even then
+
if left then
 
table.insert(items, {left, right})
 
table.insert(items, {left, right})
 
end
 
end

Revision as of 04:34, 11 June 2015

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

local BaseTable = require('Module:BaseTable')
local Formatting = require('Module:Formatting')
local StatIcons = require('Module:StatIcons')
local Ship = require('Module:Ship')

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

local ShipModernizationListKai = BaseTable{
	_header_template = [[! style="width: 75px;" | Class
! style="width: 100px;" | Name
! 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: #F2E279;" | ${armor}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: palegreen;" | ${luck}
! style="width: 100px;" | Name
! 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: #F2E279;" | ${armor}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: palegreen;" | ${luck}]],
	_columns = {
		"class",
		"name1",
		"firepower_mod1",
		"torpedo_mod1",
		"aa_mod1",
		"armor_mod1",
		"luck_mod1",
		"name2",
		"firepower_mod2",
		"torpedo_mod2",
		"aa_mod2",
		"armor_mod2",
		"luck_mod2",
	},
	_empty_cell = [[| style="text-align: center; vertical-align: middle;" | -]],
	_column_empty_cells = {
		arrow = [[| style="text-align: center; vertical-align: middle;" | ⇒]],
	},
	_item_class = Ship,
	_dash = "-",
	_question_marks = "??",
	_column_bg_colors = {
		firepower = "#e6cfcf",
		torpedo = "#cfdde6",
		aa = "#e6d9cf",
		armor = "#e6e3cf",
		luck = "#cfe6cf",
	},
}

function ShipModernizationListKai:class(pair)
	self._left = pair[1]
	self._left_modernization = self._left and self._left:modernization() or false
	self._right = pair[2]
	self._right_modernization = self._right and self._right:modernization() or false
	local left_class, right_class, class_name = self._left and self._left:class(), self._right and self._right:class(), false
	if left_class or right_class then
		if left_class == right_class or not right_class then
			class_name = left_class:base_name()
		elseif not left_class then
			class_name = right_class:base_name()
		else
			class_name = left_class:base_name() .. "/" .. right_class:base_name()
		end
	end
	return {values = {value = class_name or self._question_marks}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipModernizationListKai:name1()
	if self._left then
		return self:name(self._left)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:name2()
	if self._right then
		return self:name(self._right)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:firepower_mod1()
	if self._left then
		return self:firepower_mod(self._left_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:firepower_mod2()
	if self._right then
		return self:firepower_mod(self._right_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:torpedo_mod1()
	if self._left then
		return self:torpedo_mod(self._left_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:torpedo_mod2()
	if self._right then
		return self:torpedo_mod(self._right_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:aa_mod1()
	if self._left then
		return self:aa_mod(self._left_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:aa_mod2()
	if self._right then
		return self:aa_mod(self._right_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:armor_mod1()
	if self._left then
		return self:armor_mod(self._left_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:armor_mod2()
	if self._right then
		return self:armor_mod(self._right_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:luck_mod1()
	if self._left then
		return self:luck_mod(self._left_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai:luck_mod2()
	if self._right then
		return self:luck_mod(self._right_modernization)
	else
		return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
	end
end

function ShipModernizationListKai: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, " ")}, bg_color = self._transparent, text_align = self._start_align}
end

function ShipModernizationListKai:firepower_mod(modernization)
	return {values = {value = Formatting:format_bonus(modernization.firepower, nil, self._dash)}, bg_color = modernization.firepower and self._column_bg_colors.firepower or self._transparent, text_align = self._center_align}
end

function ShipModernizationListKai:torpedo_mod(modernization)
	return {values = {value = Formatting:format_bonus(modernization.torpedo, nil, self._dash)}, bg_color = modernization.torpedo and self._column_bg_colors.torpedo or self._transparent, text_align = self._center_align}
end

function ShipModernizationListKai:aa_mod(modernization)
	return {values = {value = Formatting:format_bonus(modernization.aa, nil, self._dash)}, bg_color = modernization.aa and self._column_bg_colors.aa or self._transparent, text_align = self._center_align}
end

function ShipModernizationListKai:armor_mod(modernization)
	return {values = {value = Formatting:format_bonus(modernization.armor, nil, self._dash)}, bg_color = modernization.armor and self._column_bg_colors.armor or self._transparent, text_align = self._center_align}
end

function ShipModernizationListKai:luck_mod(modernization)
	return {values = {value = Formatting:format_bonus(modernization.luck, nil, self._dash, true)}, bg_color = modernization.luck and self._column_bg_colors.luck or self._transparent, text_align = self._center_align}
end

ShipModernizationListKai.create_data_rows = ShipModernizationListKai.create_data_rows_merge_vertical

function ShipModernizationListKai:create_items_post()
	local items = {}
	local left = false
	local right = false
	for _, item in ipairs(self._items) do
		if type(item) == "string" then
			table.insert(items, {left, right})
			left, right = false, false
			if item == "break" then
				table.insert(items, item)
			end
		elseif left then
			if right then
				table.insert(items, {left, right})
			end
			right = item
		else
			left = item
			right = false
		end
	end
	if left then
		table.insert(items, {left, right})
	end
	self._items = items
end

function ShipModernizationListKai:create_header()
	local header_icons = {
		firepower = StatIcons.firepower,
		torpedo = StatIcons.torpedo,
		aa = StatIcons.aa,
		armor = StatIcons.armor,
		luck = StatIcons.luck,
	}
	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 ShipModernizationListKai