Changes

Implement comparison table.
Line 2: Line 2:  
local Equipment = require('Module:Equipment')
 
local Equipment = require('Module:Equipment')
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
 +
local StatIcons = require('Module:StatIcons')
    
local format = require('Module:StringInterpolation').format
 
local format = require('Module:StringInterpolation').format
Line 43: Line 44:  
"asw",
 
"asw",
 
"los",
 
"los",
 +
"luck",
 +
"hp",
 
"armor",
 
"armor",
 
"accuracy",
 
"accuracy",
 
"evasion",
 
"evasion",
 +
"speed",
 
"range",
 
"range",
 
"compatibility",
 
"compatibility",
Line 134: Line 138:  
text_align = self._start_align,
 
text_align = self._start_align,
 
}
 
}
 +
end
 +
 +
function EquipmentListKai:firepower(equipment)
 +
local firepower = equipment:firepower()
 +
if firepower ~= false then
 +
self._shown_stats.firepower = true
 +
end
 +
return {values = {value = Formatting:format_stat(firepower)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:torpedo(equipment)
 +
local torpedo = equipment:torpedo()
 +
if torpedo ~= false then
 +
self._shown_stats.torpedo = true
 +
end
 +
return {values = {value = Formatting:format_stat()}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:bombing(equipment)
 +
local bombing = equipment:bombing()
 +
if bombing ~= false then
 +
self._shown_stats.bombing = true
 +
end
 +
return {values = {value = Formatting:format_stat(bombing)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:aa(equipment)
 +
local aa = equipment:aa()
 +
if aa ~= false then
 +
self._shown_stats.aa = true
 +
end
 +
return {values = {value = Formatting:format_stat(aa)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:asw(equipment)
 +
local asw = equipment:asw()
 +
if asw ~= false then
 +
self._shown_stats.asw = true
 +
end
 +
return {values = {value = Formatting:format_stat(asw)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:los(equipment)
 +
local los = equipment:los()
 +
if los ~= false then
 +
self._shown_stats.los = true
 +
end
 +
return {values = {value = Formatting:format_stat(los)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:luck(equipment)
 +
local luck = equipment:luck()
 +
if luck ~= false then
 +
self._shown_stats.luck = true
 +
end
 +
return {values = {value = Formatting:format_stat(luck)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:hp(equipment)
 +
local hp = equipment:hp()
 +
if hp ~= false then
 +
self._shown_stats.hp = true
 +
end
 +
return {values = {value = Formatting:format_stat(hp)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:armor(equipment)
 +
local armor = equipment:armor()
 +
if armor ~= false then
 +
self._shown_stats.armor = true
 +
end
 +
return {values = {value = Formatting:format_stat(armor)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:shelling_accuracy(equipment)
 +
local shelling_accuracy = equipment:shelling_accuracy()
 +
if shelling_accuracy ~= false then
 +
self._shown_stats.shelling_accuracy = true
 +
end
 +
return {values = {value = Formatting:format_stat(shelling_accuracy)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:evasion(equipment)
 +
local evasion = equipment:evasion()
 +
if evasion ~= false then
 +
self._shown_stats.evasion = true
 +
end
 +
return {values = {value = Formatting:format_stat(evasion)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:speed(equipment)
 +
local speed = equipment:speed()
 +
if speed ~= false then
 +
self._shown_stats.speed = true
 +
end
 +
return {values = {value = Formatting:format_speed(speed)}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 +
function EquipmentListKai:range(equipment)
 +
local range = equipment:range()
 +
if range ~= false then
 +
self._shown_stats.range = true
 +
end
 +
return {values = {value = Formatting:format_range(range)}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
   Line 146: Line 254:  
function EquipmentListKai:notes(equipment)
 
function EquipmentListKai:notes(equipment)
 
return {values = {value = ""}, bg_color = self._transparent, text_align = self._start_align}
 
return {values = {value = ""}, bg_color = self._transparent, text_align = self._start_align}
 +
end
 +
 +
function EquipmentListKai.compare_values(val1, val2)
 +
if #val1 == #val2 then
 +
for value_type, value in pairs(val1) do
 +
if value ~= val2[value_type] then
 +
return false
 +
end
 +
end
 +
else
 +
return false
 +
end
 +
return true
 
end
 
end
   Line 167: Line 288:  
local rows = {self._table_start}
 
local rows = {self._table_start}
 
local header
 
local header
 +
local data_rows = {}
    
if self._args.comparison == "true" then
 
if self._args.comparison == "true" then
--create comparison table
+
self._shown_stats = {}
 +
 
 +
for _, equipment in ipairs(equipment_list) do
 +
local row_values
 +
if type(equipment) == "string" then
 +
row_values = equipment
 +
else
 +
row_values = {}
 +
for _, column in ipairs(self._stat_columns) do
 +
row_values[column] = self[column](self, equipment)
 +
end
 +
if index > 1 then
 +
for _, column in ipairs(self._stat_columns) do
 +
for i=index-1,1,-1 do
 +
local previous_row = data_rows[i]
 +
local previous_row_type = type(previous_row) ~= "string"
 +
local previous_cell = previous_row_type and previous_row[column] or false
 +
if previous_cell then
 +
if self.compare_values(row_values[column].values, previous_cell.values) then
 +
previous_cell.rowspan = previous_cell.rowspan + 1
 +
row_values[column] = nil
 +
else
 +
row_values[column].rowspan = 1
 +
end
 +
break
 +
elseif not previous_row_type then
 +
row_values[column].rowspan = 1
 +
break
 +
end
 +
end
 +
end
 +
else
 +
for _, column in ipairs(self._columns) do
 +
row_values[column].rowspan = 1
 +
end
 +
end
 +
end
 +
table.insert(data_rows, row_values)
 +
end
 +
 
 +
local stat_columns = {}
 +
local stat_columns_set = {}
 +
for _, stat_column in pairs(self._shown_stats) do
 +
table.insert(stat_columns, Formatting:format_image(StatIcons[stat_column]))
 +
stat_columns_set[stat_column] = true
 +
end
 +
for _, column in ipairs(self._stat_columns) do
 +
if not stat_columns_set[column] then
 +
for _, row_values in ipairs(data_rows) do
 +
row_values[column] = nil
 +
end
 +
end
 +
end
 +
header = format{self._header_template, stat_columns = table.concat(stat_columns, "\n")}
 
else
 
else
local header = format{self._header_template, stat_columns = format{self._column_header_cell_template, value = self._stats_column_label}}
+
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
 
for _, equipment in ipairs(equipment_list) do
 
local row_values
 
local row_values
Line 188: Line 360:  
table.insert(data_rows, row_values)
 
table.insert(data_rows, row_values)
 
end
 
end
 
+
end
for index, row_values in ipairs(data_rows) do
+
if row_values ~= "break" then
+
table.insert(rows, header)
table.insert(rows, self._row_starter)
+
for index, row_values in ipairs(data_rows) do
if row_values == "header" then
+
if row_values ~= "break" then
table.insert(rows, header)
+
table.insert(rows, self._row_starter)
else
+
if row_values == "header" then
for _, column in ipairs(self._columns) do
+
table.insert(rows, header)
if row_values[column] then
+
else
table.insert(rows, format(self._column_cell_templates[column] or self._cell, row_values[column]))
+
for _, column in ipairs(self._columns) do
end
+
if row_values[column] then
 +
table.insert(rows, format(self._column_cell_templates[column] or self._cell, row_values[column]))
 
end
 
end
 
end
 
end
Anonymous user