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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(Rmove center align on name column)
 
(77 intermediate revisions by 8 users not shown)
Line 1: Line 1:
local BaseData = require('Module:BaseData')
+
local BaseTable = require('Module:BaseTable')
 
local Equipment = require('Module:Equipment')
 
local Equipment = require('Module:Equipment')
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
 +
local StatIcons = require('Module:Data/Asset')
 +
local EquipmentLink = require('Module:EquipmentLink')
  
local format = require('Module:StringInterpolation').format
+
local format = require('Module:Core').format
  
local EquipmentListKai = BaseData{
+
-- [[Category:Todo]]: hardcoded iconsClasses
 +
local EquipmentListKai = BaseTable{
 +
_item_class = Equipment,
 
_table_start = [[{| class="wikitable"]],
 
_table_start = [[{| class="wikitable"]],
_row_starter = "|-",
+
_header_template = [=[! No.
_header_template = [[!No.
+
! Rarity
!Rarity
+
! style="width:240px" | Name
!Name
+
! style="width:120px" | Equipment Type
 
${stat_columns}
 
${stat_columns}
!Classes
+
! style="width:120px" | Refittable Types
!Craftable
+
! [[File:Icon_Dev.png|20px|Craftable|link=Development]]
! style="white-space:nowrap;width:130px;" |Notes]],
+
! [[File:Icon_Imp.png|20px|Improvable|link=Improvement]]
_column_header_cell_template = "!${value}",
+
! style="white-space:nowrap" | Notes]=],
 
_column_cell_templates = {
 
_column_cell_templates = {
name = [[| colspan="1" rowspan="${rowspan}" style="background-color: ${bg_color};" |${values.name}<br />${values.icon} ${values.japanese_name}]]
+
id = [[| style="${text_align};background-color:${bg_color}" |${values.value}]],
},
+
rarity = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
_icons = {
+
name = [[| style="${text_align};background-color:${bg_color}" |${values.name}<br />${values.icon} ${values.japanese_name}]],
firepower = "${stat_icons.firepower}",
+
equipment_type = [[| rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]],
torpedo = "${stat_icons.torpedo}",
+
stats = [[| style="${text_align};background-color:${bg_color}" |${values.value}]],
bombing = "${stat_icons.bombing}",
+
compatibility = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
aa = "${stat_icons.aa}",
+
buildable = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
asw = "${stat_icons.asw}",
+
improvable = [[| rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]],
los = "${stat_icons.los}",
+
notes = [[| class="${classes}" rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]]
armor = "${stat_icons.armor}",
 
accuracy = "${stat_icons.accuracy}",
 
evasion = "${stat_icons.evasion}",
 
range = "${stat_icons.range}",
 
},
 
_comparison_columns = {
 
"id",
 
"stars",
 
"name",
 
"firepower",
 
"torpedo",
 
"bombing",
 
"aa",
 
"asw",
 
"los",
 
"armor",
 
"accuracy",
 
"evasion",
 
"range",
 
"compatibility",
 
"buildable",
 
"notes",
 
 
},
 
},
 
_columns = {
 
_columns = {
 
"id",
 
"id",
"stars",
+
"rarity",
 
"name",
 
"name",
 +
"equipment_type",
 
"stats",
 
"stats",
 
"compatibility",
 
"compatibility",
 
"buildable",
 
"buildable",
 +
"improvable",
 
"notes",
 
"notes",
 
},
 
},
_cell_color = {
 
firepower = "#F0C0C0",
 
torpedo = "#C0E4FA",
 
aa = "#F4CAA6",
 
asw = "#C5BEEE",
 
los = "#CCFFEE",
 
luck = "#C9FBC9",
 
hp = "#FFD9DF",
 
armor = "#F2ECC2",
 
evasion = "#EEBEEE",
 
speed = "#B8E6E6",
 
aircraft = "#D9D9D9",
 
fuel = "#94E094",
 
ammo = "palegoldenrod",
 
},
 
_cell = [[| colspan="1" rowspan="${rowspan}" style="text-align:center; background-color: ${bg_color};" |${values.value}]],
 
_transparent = "transparent",
 
_notes_suffix = "_notes",
 
 
_stats_column_label = "Stats",
 
_stats_column_label = "Stats",
_table_end = [[|}]],
 
 
}
 
}
 
function EquipmentListKai:Table(args)
 
return self{
 
_args = args,
 
}:create_table()
 
end
 
  
 
function EquipmentListKai:id(equipment)
 
function EquipmentListKai:id(equipment)
return {values = {value = Formatting:format_stat(equipment:id())}, bg_color = self._transparent}
+
return {values = {value = Formatting:format_stat(equipment:id())}, bg_color = self._transparent, text_align = ""}
 
end
 
end
  
function EquipmentListKai:stars(equipment)
+
function EquipmentListKai:rarity(equipment)
return {values = {value = Formatting:format_stars(equipment:stars())}, bg_color = self._transparent}
+
return {values = {value = Formatting:tooltip(Formatting:format_stars(equipment:stars()), Formatting:format_equipment_rarity(equipment:rarity()), nil, Formatting._display_inline_block_css)}, bg_color = self._transparent, text_align = ""}
 
end
 
end
  
 
function EquipmentListKai:name(equipment)
 
function EquipmentListKai:name(equipment)
return {values = {name = Formatting:format_link(equipment:link()),  
+
return {values = {
 +
name = EquipmentLink.format(nil, { equipment:name() }),  
 
icon = Formatting:format_image{Formatting:format_equipment_icon(equipment:icon())},  
 
icon = Formatting:format_image{Formatting:format_equipment_icon(equipment:icon())},  
 
japanese_name = Formatting:format_stat(equipment:japanese_name())
 
japanese_name = Formatting:format_stat(equipment:japanese_name())
 
},  
 
},  
 
bg_color = self._transparent,
 
bg_color = self._transparent,
 +
text_align = "text-align: " .. self._start_align,
 
}
 
}
 +
end
 +
 +
function EquipmentListKai:equipment_type(equipment)
 +
    return {values = {value = Formatting:format_equipment_type(equipment:type())}, bg_color = self._transparent, text_align = ""}
 
end
 
end
  
 
function EquipmentListKai:stats(equipment)
 
function EquipmentListKai:stats(equipment)
return {values = {value = Formatting:format_stat("placeholder")}, bg_color = self._transparent}
+
    local stats = {
 +
firepower = equipment:firepower(),
 +
bombing = equipment:bombing(),
 +
torpedo = equipment:torpedo(),
 +
aa = equipment:aa(),
 +
armor = equipment:armor(),
 +
asw = equipment:asw(),
 +
shelling_accuracy = equipment:shelling_accuracy(),
 +
torpedo_accuracy = equipment:torpedo_accuracy(),
 +
evasion = equipment:evasion(),
 +
los = equipment:los(),
 +
speed = Formatting:format_speed(equipment:speed()),
 +
luck = equipment:luck(),
 +
range = Formatting:format_range(equipment:range()),
 +
special = false,
 +
}
 +
return {values = {value = equipment:type() == 48 and Formatting:format_stat_bonuses_interceptor(stats, "<br />") or Formatting:format_stat_bonuses(stats, "<br />"),
 +
},  
 +
bg_color = self._transparent,
 +
text_align = "text-align: " .. self._start_align,
 +
}
 
end
 
end
  
 
function EquipmentListKai:compatibility(equipment)
 
function EquipmentListKai:compatibility(equipment)
return {values = {value = Formatting:format_stat("placeholder2")}, bg_color = self._transparent}
+
local value = Formatting:format_ship_compatibility(equipment:equippable())
 +
if equipment:is_lbas_plane() then
 +
value = value == "" and "LBAS" or value .. "; LBAS"
 +
end
 +
return {values = {value = value}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align}
 
end
 
end
  
 
function EquipmentListKai:buildable(equipment)
 
function EquipmentListKai:buildable(equipment)
return {values = {value = Formatting:format_stat(equipment:buildable())}, bg_color = self._transparent}
+
return {values = {value = Formatting:format_boolean_short(equipment:buildable())}, bg_color = self._transparent, text_align = ""}
 
end
 
end
  
function EquipmentListKai:notes(equipment)
+
function EquipmentListKai:improvable(equipment)
return {values = {value = ""}, bg_color = self._transparent}
+
return {values = {value = Formatting:format_boolean_short(equipment:improvable())}, bg_color = self._transparent, text_align = ""}
 
end
 
end
  
function EquipmentListKai:create_table()
+
function EquipmentListKai:notes(equipment)
local equipment_list = {}
+
local note = self._notes[equipment]
self._notes = {}
+
if note then
for index, equipment_name in ipairs(self._args) do
+
return {values = {value = note.note or ""}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align}
table.insert(equipment_list, Equipment(equipment_name))
 
local note = self._args[equipment_name .. self._notes_suffix]
 
if note then
 
self._notes[equipment_name] = note
 
end
 
end
 
 
 
local rows = {self._table_start}
 
local header
 
 
 
if self._args.comparison == "true" then
 
--create comparison table
 
else
 
local header = format{self._header_template, stat_columns = format{self._column_header_cell_template, value = self._stats_column_label}}
 
table.insert(rows, header)
 
local data_rows = {}
 
 
 
for _, equipment in ipairs(equipment_list) do
 
local row_values = {}
 
for _, column in ipairs(self._columns) do
 
row_values[column] = self[column](self, equipment)
 
row_values[column].rowspan = 1
 
end
 
table.insert(data_rows, row_values)
 
end
 
 
 
for index, row_values in ipairs(data_rows) do
 
if row_values ~= "break" then
 
table.insert(rows, self._row_starter)
 
if row_values == "header" then
 
table.insert(rows, header)
 
else
 
for _, column in ipairs(self._columns) do
 
if row_values[column] then
 
table.insert(rows, format(self._column_cell_templates[column] or self._cell, row_values[column]))
 
end
 
end
 
end
 
end
 
end
 
 
end
 
end
table.insert(rows, self._row_starter)
+
return {values = {value = ""}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align}
table.insert(rows, header)
 
table.insert(rows, self._table_end)
 
return table.concat(rows, "\n")
 
 
end
 
end
  
function EquipmentListKai.test(frame)
+
function EquipmentListKai:create_header()
local getArgs = require('Module:GetArgs')
+
self._header = format{self._header_template, stat_columns = format{self._column_header_cell_template, value = self._stats_column_label}}
local args = getArgs{frame = frame}
 
return EquipmentListKai:Table(args)
 
 
end
 
end
  
 
return EquipmentListKai
 
return EquipmentListKai

Latest revision as of 20:11, 6 April 2024

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

local BaseTable = require('Module:BaseTable')
local Equipment = require('Module:Equipment')
local Formatting = require('Module:Formatting')
local StatIcons = require('Module:Data/Asset')
local EquipmentLink = require('Module:EquipmentLink')

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

-- [[Category:Todo]]: hardcoded iconsClasses
local EquipmentListKai = BaseTable{
	_item_class = Equipment,
	_table_start = [[{| class="wikitable"]],
	_header_template = [=[! No.
! Rarity
! style="width:240px" | Name
! style="width:120px" | Equipment Type
${stat_columns}
! style="width:120px" | Refittable Types
! [[File:Icon_Dev.png|20px|Craftable|link=Development]]
! [[File:Icon_Imp.png|20px|Improvable|link=Improvement]]
! style="white-space:nowrap" | Notes]=],
	_column_cell_templates = {
		id = [[| style="${text_align};background-color:${bg_color}" |${values.value}]],
		rarity = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
		name = [[| style="${text_align};background-color:${bg_color}" |${values.name}<br />${values.icon} ${values.japanese_name}]],
		equipment_type = [[| rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]],
		stats = [[| style="${text_align};background-color:${bg_color}" |${values.value}]],
		compatibility = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
		buildable = [[| rowspan="${rowspan}"style="${text_align};background-color:${bg_color}" |${values.value}]],
		improvable = [[| rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]],
		notes = [[| class="${classes}" rowspan="${rowspan}" style="${text_align};background-color:${bg_color}" |${values.value}]]
	},
	_columns = {
		"id",
		"rarity",
		"name",
		"equipment_type",
		"stats",
		"compatibility",
		"buildable",
		"improvable",
		"notes",
	},
	_stats_column_label = "Stats",
}

function EquipmentListKai:id(equipment)
	return {values = {value = Formatting:format_stat(equipment:id())}, bg_color = self._transparent, text_align = ""}
end

function EquipmentListKai:rarity(equipment)
	return {values = {value = Formatting:tooltip(Formatting:format_stars(equipment:stars()), Formatting:format_equipment_rarity(equipment:rarity()), nil, Formatting._display_inline_block_css)}, bg_color = self._transparent, text_align = ""}
end

function EquipmentListKai:name(equipment)
	return {values = {
			name = EquipmentLink.format(nil, { equipment:name() }), 
			icon = Formatting:format_image{Formatting:format_equipment_icon(equipment:icon())}, 
			japanese_name = Formatting:format_stat(equipment:japanese_name())
		}, 
		bg_color = self._transparent,
		text_align = "text-align: " .. self._start_align,
	}
end

function EquipmentListKai:equipment_type(equipment)
    return {values = {value = Formatting:format_equipment_type(equipment:type())}, bg_color = self._transparent, text_align = ""}
end

function EquipmentListKai:stats(equipment)
    local stats = {
		firepower = equipment:firepower(), 
		bombing = equipment:bombing(), 
		torpedo = equipment:torpedo(), 
		aa = equipment:aa(), 
		armor = equipment:armor(), 
		asw = equipment:asw(), 
		shelling_accuracy = equipment:shelling_accuracy(),
		torpedo_accuracy = equipment:torpedo_accuracy(),
		evasion = equipment:evasion(),
		los = equipment:los(),
		speed = Formatting:format_speed(equipment:speed()),
		luck = equipment:luck(),
		range = Formatting:format_range(equipment:range()),
		special = false,
	}
	return {values = {value = equipment:type() == 48 and Formatting:format_stat_bonuses_interceptor(stats, "<br />") or Formatting:format_stat_bonuses(stats, "<br />"),
		}, 
		bg_color = self._transparent, 
		text_align = "text-align: " .. self._start_align,
	}
end

function EquipmentListKai:compatibility(equipment)
	local value = Formatting:format_ship_compatibility(equipment:equippable())
	if equipment:is_lbas_plane() then
		value = value == "" and "LBAS" or value .. "; LBAS"
	end
	return {values = {value = value}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align}
end

function EquipmentListKai:buildable(equipment)
	return {values = {value = Formatting:format_boolean_short(equipment:buildable())}, bg_color = self._transparent, text_align = ""}
end

function EquipmentListKai:improvable(equipment)
	return {values = {value = Formatting:format_boolean_short(equipment:improvable())}, bg_color = self._transparent, text_align = ""}
end

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

function EquipmentListKai:create_header()
	self._header = format{self._header_template, stat_columns = format{self._column_header_cell_template, value = self._stats_column_label}}
end

return EquipmentListKai