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

Module:EliteShipsKai

From Kancolle Wiki
Revision as of 18:29, 27 January 2015 by com>Ckwng (Elite ships table generator)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local ResourceIcons = require('Module:ResourceIcons')
local StatIcons = require('Module:StatIcons')
local MiscIcons = require('Module:MiscIcons')
local format = require('Module:StringInterpolation').format

local EliteShipsKai = {
	_table_start = [[{| class="wikitable"]],
	_row_starter = [[-]],
	_header_template = [[!No.
!Name
!Class
! style="white-space:nowrap;" | ${remodel_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: LightCoral;" | ${firepower_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: LightSkyBlue;" | ${torpedo_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: SandyBrown;" | ${aa_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Seashell;" | ${asw_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Aquamarine;" | ${los_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: PaleGreen;" | ${luck_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Pink;" | ${hp_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: yellow;" | ${armor_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Violet;" | ${evasion_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Aqua;" | ${speed_icon}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: Silver;" | ${aircraft_icon}
! ${fuel_icon}
! ${ammo_icon}
! style="text-align:left;" | Notes]],
	_row_template = [[|-
| style="text-align:center;" | ${id}
| style="text-align:center;" | ${name} ${japanese_name}
| colspan="1" rowspan="${rowspan_class}" style="text-align:center; background-color: ${color_class}" | ${class}
| colspan="1" rowspan="${rowspan_remodel_level}" style="text-align:center; background-color: ${color_remodel_level}" | ${remodel_level}
| colspan="1" rowspan="${rowspan_firepower}" style="text-align:center; background-color: ${color_firepower}" | ${firepower}
| colspan="1" rowspan="${rowspan_torpedo}" style="text-align:center; background-color: ${color_torpedo}" | ${torpedo}
| colspan="1" rowspan="${rowspan_aa}" style="text-align:center; background-color: ${color_aa}" | ${aa}
| colspan="1" rowspan="${rowspan_asw}" style="text-align:center; background-color: ${color_asw}" | ${asw}
| colspan="1" rowspan="${rowspan_los}" style="text-align:center; background-color: ${color_los}" | ${los}
| colspan="1" rowspan="${rowspan_luck}" style="text-align:center; background-color: ${color_luck}" | ${luck}
| colspan="1" rowspan="${rowspan_hp}" style="text-align:center; background-color: ${color_hp}" | ${hp}
| colspan="1" rowspan="${rowspan_armor}" style="text-align:center; background-color: ${color_armor}" | ${armor}
| colspan="1" rowspan="${rowspan_evasion}" style="text-align:center; background-color: ${color_evasion}" | ${evasion}
| colspan="1" rowspan="${rowspan_speed}" style="text-align:center; background-color: ${color_speed}" | ${speed}
| colspan="1" rowspan="${rowspan_aircraft}" style="text-align:center; background-color: ${color_aircraft}" | ${aircraft}
| colspan="1" rowspan="${rowspan_fuel}" style="text-align:center; background-color: ${color_fuel}" | ${fuel}
| colspan="1" rowspan="${rowspan_ammo}" style="text-align:center; background-color: ${color_ammo}" | ${ammo}
| colspan="1" rowspan="${rowspan_notes}" | ${notes}]],
	_columns = {
		"class",
		"remodel",
		"firepower",
		"torpedo",
		"aa",
		"asw",
		"los",
		"luck",
		"hp",
		"armor",
		"evasion",
		"speed",
		"aircraft",
		"fuel",
		"ammo",
		"notes",
	},
	_cell = [[| colspan="1" rowspan="${rowspan}" style="text-align:center; background-color: ${bg_color}" | ${value}]],
	_table_end = [[|}]],
	_rowspan_suffix = "_rowspan",
	_bg_color_suffix = "_bg_color",
	_transparent = "transparent",
}

function EliteShipsKai:name(ship)
	return format{"${link} ${japanese_name}", link = ship:link(), japanese_name = ship:japanese_name()}
end

function EliteShipsKai:id(ship)
	return ship:id()
end

function EliteShipsKai:class(ship)
	return ship:class()
end

function EliteShipsKai:remodel_level(ship)
	return ship:remodel_level()
end

function EliteShipsKai:firepower_max(ship)
	return ship:firepower_max()
end

function EliteShipsKai:torpedo_max(ship)
	return ship:torpedo_max()
end

function EliteShipsKai:aa_max(ship)
	return ship:aa_max()
end

function EliteShipsKai:asw_max(ship)
	return ship:asw_max()
end

function EliteShipsKai:los_max(ship)
	return ship:los_max()
end

function EliteShipsKai:luck_max(ship)
	return ship:luck_max()
end

function EliteShipsKai:hp(ship)
	return ship:hp()
end

function EliteShipsKai:armor_max(ship)
	return ship:armor_max()
end

function EliteShipsKai:evasion_max(ship)
	return ship:evasion_max()
end

function EliteShipsKai:speed(ship)
	return ship:speed()
end

function EliteShipsKai:aircraft(ship)
	return ship:total_space()
end

function EliteShipsKai:fuel(ship)
	return ship:fuel()
end

function EliteShipsKai:ammo(ship)
	return ship:ammo()
end

function EliteShipsKai:notes(ship)
	--stubbed out for now
	return ""
end

function EliteShipsKai:Table(ships)
	local header = format{self._header_template, remodel_icon = MiscIcons.remodel, 
	                                             firepower_icon = StatIcons.firepower, 
	                                             torpedo_icon = StatIcons.torpedo, 
	                                             aa_icon = StatIcons.aa, 
	                                             asw_icon = StatIcons.asw, 
	                                             los_icon = StatIcons.los, 
	                                             luck_icon = StatIcons.luck, 
	                                             hp_icon = StatIcons.hp, 
	                                             armor_icon = StatIcons.armor,
	                                             evasion_icon = StatIcons.evasion,
	                                             speed_icon = StatIcons.speed,
	                                             aircraft_icon = StatIcons.aircraft,
	                                             fuel_icon = ResourceIcons.fuel,
	                                             ammo_icon = ResourceIcons.ammo,
	                     }
	local rows = {self._table_start, header}

	local data_rows = {}
	for index, ship in ipairs(ships) do
		local row_values = {
			id = self:id(ship),
			name = self:name(ship),
			class = self:class(ship),
			remodel = self:remodel_level(ship),
			firepower = self:firepower_max(ship),
			torpedo = self:torpedo_max(ship),
			aa = self:aa_max(ship),
			asw = self:asw_max(ship),
			los = self:los_max(ship),
			luck = self:luck_max(ship),
			hp = self:hp(ship),
			armor = self:armor_max(ship),
			evasion = self:evasion_max(ship),
			speed = self:speed(ship),
			aircraft = self:aircraft(ship),
			fuel = self:fuel(ship),
			ammo = self:ammo(ship),
			notes = self:notes(ship),
		}
		if index > 1 then
			for _, column in ipairs(self._columns) do
				for i=index-1,1,-1 do
					if data_rows[i][column] and row_values[column] == data_rows[i][column] then
						data_rows[i][column .. self._rowspan_suffix] = data_rows[i][column .. self._rowspan_suffix] + 1
						row_values[column] = nil
					end
				end
			end
		end
		for _, column in ipairs(self._columns) do
			if row_values[column] then
				row_values[column .. self._rowspan_suffix] = 1
				row_values[column .. self._bg_color_suffix] = self._transparent
			end
		end
		table.insert(data_rows, row_values)
	end

	for index, row_values in ipairs(data_rows) do
		table.insert(rows, self._row_starter)
		table.insert(rows, format{self._cell, value = row_values.id, rowspan = 1, bg_color = self._transparent})
		table.insert(rows, format{self._cell, value = row_values.name, rowspan = 1, bg_color = self._transparent})
		for _, column in ipairs(self._columns) do
			if row_values[column] then
				table.insert(rows, format{self._cell, value = row_values[column], rowspan = row_values[column .. self._rowspan_suffix], bg_color = row_values[column .. self._bg_color_suffix]})
			end
		end
	end

	table.insert(rows, header)
	table.insert(rows, self._table_end)
	return table.concat(rows, "\n")
end

return EliteShipsKai