• 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
(Soften bg colors, don't color when no value)
com>Ckwng
(Fix text-align, fix no bg color when no data)
Line 64: Line 64:
 
return self:name(self._left)
 
return self:name(self._left)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 72: Line 72:
 
return self:name(self._right)
 
return self:name(self._right)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 80: Line 80:
 
return self:firepower_mod(self._left_modernization)
 
return self:firepower_mod(self._left_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 88: Line 88:
 
return self:firepower_mod(self._right_modernization)
 
return self:firepower_mod(self._right_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 96: Line 96:
 
return self:torpedo_mod(self._left_modernization)
 
return self:torpedo_mod(self._left_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 104: Line 104:
 
return self:torpedo_mod(self._right_modernization)
 
return self:torpedo_mod(self._right_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 112: Line 112:
 
return self:aa_mod(self._left_modernization)
 
return self:aa_mod(self._left_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 120: Line 120:
 
return self:aa_mod(self._right_modernization)
 
return self:aa_mod(self._right_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 128: Line 128:
 
return self:armor_mod(self._left_modernization)
 
return self:armor_mod(self._left_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 136: Line 136:
 
return self:armor_mod(self._right_modernization)
 
return self:armor_mod(self._right_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 144: Line 144:
 
return self:luck_mod(self._left_modernization)
 
return self:luck_mod(self._left_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 152: Line 152:
 
return self:luck_mod(self._right_modernization)
 
return self:luck_mod(self._right_modernization)
 
else
 
else
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._start_align}
+
return {values = {value = self._dash}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
 
end
 
end
Line 167: Line 167:
  
 
function ShipModernizationListKai:firepower_mod(modernization)
 
function ShipModernizationListKai:firepower_mod(modernization)
return {values = {value = Formatting:format_bonus(modernization.firepower, nil, self._dash)}, bg_color = self._column_bg_colors.firepower, text_align = self._center_align}
+
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
 
end
  
 
function ShipModernizationListKai:torpedo_mod(modernization)
 
function ShipModernizationListKai:torpedo_mod(modernization)
return {values = {value = Formatting:format_bonus(modernization.torpedo, nil, self._dash)}, bg_color = self._column_bg_colors.torpedo, text_align = self._center_align}
+
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
 
end
  
 
function ShipModernizationListKai:aa_mod(modernization)
 
function ShipModernizationListKai:aa_mod(modernization)
return {values = {value = Formatting:format_bonus(modernization.aa, nil, self._dash)}, bg_color = self._column_bg_colors.aa, text_align = self._center_align}
+
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
 
end
  
 
function ShipModernizationListKai:armor_mod(modernization)
 
function ShipModernizationListKai:armor_mod(modernization)
return {values = {value = Formatting:format_bonus(modernization.armor, nil, self._dash)}, bg_color = self._column_bg_colors.armor, text_align = self._center_align}
+
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
 
end
  
 
function ShipModernizationListKai:luck_mod(modernization)
 
function ShipModernizationListKai:luck_mod(modernization)
return {values = {value = Formatting:format_bonus(modernization.luck, nil, self._dash, true)}, bg_color = self._column_bg_colors.luck, text_align = self._center_align}
+
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
 
end
  

Revision as of 00:19, 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._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
	local class = (pair[1] or pair[2]):class()
	return {values = {value = class and class:base_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
	local even = false
	for _, item in ipairs(self._items) do
		if type(item) == "string" then
			if item == "empty" then
				if even then
					right = false
					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)
			end
		elseif even then
			right = item
			table.insert(items, {left, right})
			left = false
			right = false
			even = false
		else
			left = item
			even = true
		end
	end
	if even 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