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:StatIcons') | + | 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 |
− | ! Name | + | ! style="width:240px" | Name |
− | ! style="width: 120px" | Type | + | ! style="width:120px" | Equipment Type |
| ${stat_columns} | | ${stat_columns} |
− | ! style="width: 120px" | 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="text-align: ${text_align}; 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}]], |
| + | 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}]] |
| }, | | }, |
− | _icons = { | + | _columns = { |
− | firepower = "${stat_icons.firepower}",
| |
− | torpedo = "${stat_icons.torpedo}",
| |
− | bombing = "${stat_icons.bombing}",
| |
− | aa = "${stat_icons.aa}",
| |
− | asw = "${stat_icons.asw}",
| |
− | los = "${stat_icons.los}",
| |
− | armor = "${stat_icons.armor}",
| |
− | accuracy = "${stat_icons.accuracy}",
| |
− | evasion = "${stat_icons.evasion}",
| |
− | range = "${stat_icons.range}",
| |
− | },
| |
− | _comparison_columns = {
| |
| "id", | | "id", |
− | "stars", | + | "rarity", |
− | "name",
| |
− | "equipment_type",
| |
− | "firepower",
| |
− | "torpedo",
| |
− | "bombing",
| |
− | "aa",
| |
− | "asw",
| |
− | "los",
| |
− | "luck",
| |
− | "armor",
| |
− | "shelling_accuracy",
| |
− | "evasion",
| |
− | "speed",
| |
− | "range",
| |
− | "compatibility",
| |
− | "buildable",
| |
− | "notes",
| |
− | },
| |
− | _stat_columns = {
| |
− | "firepower",
| |
− | "torpedo",
| |
− | "bombing",
| |
− | "aa",
| |
− | "asw",
| |
− | "los",
| |
− | "luck",
| |
− | "armor",
| |
− | "shelling_accuracy",
| |
− | "evasion",
| |
− | "speed",
| |
− | "range",
| |
− | },
| |
− | _list_columns = {
| |
− | "id",
| |
− | "stars",
| |
| "name", | | "name", |
| "equipment_type", | | "equipment_type", |
Line 76: |
Line 39: |
| "compatibility", | | "compatibility", |
| "buildable", | | "buildable", |
| + | "improvable", |
| "notes", | | "notes", |
| }, | | }, |
− | _cell_color = {
| |
− | },
| |
− | _cell = [[| colspan="1" rowspan="${rowspan}" style="text-align: ${text_align}; background-color: ${bg_color};" |${values.value}]],
| |
− | _good_stat_color = "#ffff40",
| |
− | _outstanding_stat_color = "#73ff4d",
| |
− | _transparent = "transparent",
| |
− | _start_align = "start",
| |
− | _center_align = "center",
| |
− | _notes_suffix = "_notes",
| |
− | _highlight_suffix = "_highlight",
| |
| _stats_column_label = "Stats", | | _stats_column_label = "Stats", |
− | _table_end = [[|}]],
| |
− | _operators = {
| |
− | ["<"] = function(x,y) return x < y end,
| |
− | [">"] = function(x,y) return x > y 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, text_align = self._center_align} | + | 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, text_align = self._center_align} | + | 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 = self._start_align, | + | text_align = "text-align: " .. self._start_align, |
| } | | } |
| end | | end |
| | | |
| function EquipmentListKai:equipment_type(equipment) | | function EquipmentListKai:equipment_type(equipment) |
− | return {values = {value = Formatting:format_equipment_type(equipment:type())}, bg_color = self._transparent, text_align = self._center_align}
| + | 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_bonuses({
| + | local stats = { |
− | firepower = equipment:firepower(),
| + | firepower = equipment:firepower(), |
− | bombing = equipment:bombing(),
| + | bombing = equipment:bombing(), |
− | torpedo = equipment:torpedo(),
| + | torpedo = equipment:torpedo(), |
− | aa = equipment:aa(),
| + | aa = equipment:aa(), |
− | armor = equipment:armor(),
| + | armor = equipment:armor(), |
− | asw = equipment:asw(),
| + | asw = equipment:asw(), |
− | shelling_accuracy = equipment:shelling_accuracy(),
| + | shelling_accuracy = equipment:shelling_accuracy(), |
− | torpedo_accuracy = equipment:torpedo_accuracy(),
| + | torpedo_accuracy = equipment:torpedo_accuracy(), |
− | evasion = equipment:evasion(),
| + | evasion = equipment:evasion(), |
− | los = equipment:los(),
| + | los = equipment:los(), |
− | speed = Formatting:format_speed(equipment:speed()),
| + | speed = Formatting:format_speed(equipment:speed()), |
− | luck = equipment:luck(),
| + | luck = equipment:luck(), |
− | range = Formatting:format_range(equipment:range()),
| + | range = Formatting:format_range(equipment:range()), |
− | special = false,
| + | special = false, |
− | }, "<br />"),
| + | } |
| + | 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, | | bg_color = self._transparent, |
− | text_align = self._start_align, | + | text_align = "text-align: " .. self._start_align, |
| } | | } |
| end | | end |
| | | |
− | function EquipmentListKai:firepower(equipment) | + | function EquipmentListKai:compatibility(equipment) |
− | local firepower = equipment:firepower() | + | local value = Formatting:format_ship_compatibility(equipment:equippable()) |
− | if firepower ~= false then | + | if equipment:is_lbas_plane() then |
− | self._shown_stats.firepower = true | + | value = value == "" and "LBAS" or value .. "; LBAS" |
− | else
| |
− | firepower = 0
| |
| end | | end |
− | return {values = {value = Formatting:format_stat(firepower)}, bg_color = self:get_bg_color(self._cell_color.firepower, firepower, self._args.firepower_operator, self._args.firepower_outstanding, self._args.firepower_good), text_align = self._center_align} | + | return {values = {value = value}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align} |
| end | | end |
| | | |
− | function EquipmentListKai:torpedo(equipment) | + | function EquipmentListKai:buildable(equipment) |
− | local torpedo = equipment:torpedo()
| + | return {values = {value = Formatting:format_boolean_short(equipment:buildable())}, bg_color = self._transparent, text_align = ""} |
− | if torpedo ~= false then
| |
− | self._shown_stats.torpedo = true
| |
− | else
| |
− | torpedo = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(torpedo)}, bg_color = self:get_bg_color(self._cell_color.torpedo, torpedo, self._args.torpedo_operator, self._args.torpedo_outstanding, self._args.torpedo_good), text_align = self._center_align} | |
| end | | end |
| | | |
− | function EquipmentListKai:bombing(equipment) | + | function EquipmentListKai:improvable(equipment) |
− | local bombing = equipment:bombing()
| + | return {values = {value = Formatting:format_boolean_short(equipment:improvable())}, bg_color = self._transparent, text_align = ""} |
− | if bombing ~= false then
| |
− | self._shown_stats.bombing = true
| |
− | else
| |
− | bombing = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(bombing)}, bg_color = self:get_bg_color(self._cell_color.bombing, bombing, self._args.bombing_operator, self._args.bombing_outstanding, self._args.bombing_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:aa(equipment)
| |
− | local aa = equipment:aa()
| |
− | if aa ~= false then
| |
− | self._shown_stats.aa = true
| |
− | else
| |
− | aa = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(aa)}, bg_color = self:get_bg_color(self._cell_color.aa, aa, self._args.aa_operator, self._args.aa_outstanding, self._args.aa_good), text_align = self._center_align} | |
− | end
| |
− | | |
− | function EquipmentListKai:asw(equipment)
| |
− | local asw = equipment:asw()
| |
− | if asw ~= false then
| |
− | self._shown_stats.asw = true
| |
− | else
| |
− | asw = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(asw)}, bg_color = self:get_bg_color(self._cell_color.asw, asw, self._args.asw_operator, self._args.asw_outstanding, self._args.asw_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:los(equipment)
| |
− | local los = equipment:los()
| |
− | if los ~= false then
| |
− | self._shown_stats.los = true
| |
− | else
| |
− | los = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(los)}, bg_color = self:get_bg_color(self._cell_color.los, los, self._args.los_operator, self._args.los_outstanding, self._args.los_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:luck(equipment)
| |
− | local luck = equipment:luck()
| |
− | if luck ~= false then
| |
− | self._shown_stats.luck = true
| |
− | else
| |
− | luck = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(luck)}, bg_color = self:get_bg_color(self._cell_color.luck, luck, self._args.luck_operator, self._args.luck_outstanding, self._args.luck_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:armor(equipment)
| |
− | local armor = equipment:armor()
| |
− | if armor ~= false then
| |
− | self._shown_stats.armor = true
| |
− | else
| |
− | armor = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(armor)}, bg_color = self:get_bg_color(self._cell_color.armor, armor, self._args.armor_operator, self._args.armor_outstanding, self._args.armor_good), 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
| |
− | else
| |
− | shelling_accuracy = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(shelling_accuracy)}, bg_color = self:get_bg_color(self._cell_color.shelling_accuracy, shelling_accuracy, self._args.shelling_accuracy_operator, self._args.shelling_accuracy_outstanding, self._args.shelling_accuracy_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:evasion(equipment)
| |
− | local evasion = equipment:evasion()
| |
− | if evasion ~= false then
| |
− | self._shown_stats.evasion = true
| |
− | else
| |
− | evasion = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_stat(evasion)}, bg_color = self:get_bg_color(self._cell_color.evasion, evasion, self._args.evasion_operator, self._args.evasion_outstanding, self._args.evasion_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:speed(equipment)
| |
− | local speed = equipment:speed()
| |
− | if speed ~= false then
| |
− | self._shown_stats.speed = true
| |
− | else
| |
− | speed = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_speed(speed)}, bg_color = self:get_bg_color(self._cell_color.speed, speed, self._args.speed_operator, self._args.speed_outstanding, self._args.speed_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:range(equipment)
| |
− | local range = equipment:range()
| |
− | if range ~= false then
| |
− | self._shown_stats.range = true
| |
− | else
| |
− | range = 0
| |
− | end
| |
− | return {values = {value = Formatting:format_range(range)}, bg_color = self:get_bg_color(self._cell_color.range, range, self._args.range_operator, self._args.range_outstanding, self._args.range_good), text_align = self._center_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:compatibility(equipment)
| |
− | return {values = {value = Formatting:format_ship_compatibility(equipment:equippable())}, bg_color = self._transparent, text_align = self._start_align}
| |
− | end
| |
− | | |
− | function EquipmentListKai:buildable(equipment)
| |
− | return {values = {value = Formatting:format_boolean(equipment:buildable())}, bg_color = self._transparent, text_align = self._center_align}
| |
| end | | end |
| | | |
Line 278: |
Line 111: |
| local note = self._notes[equipment] | | local note = self._notes[equipment] |
| if note then | | if note then |
− | local bg_color
| + | return {values = {value = note.note or ""}, bg_color = self._transparent, text_align = "text-align: " .. self._start_align} |
− | if note.highlight == "outstanding" then
| |
− | bg_color = self._outstanding_stat_color
| |
− | elseif note.highlight == "good" then
| |
− | bg_color = self._good_stat_color
| |
− | else
| |
− | bg_color = self._transparent
| |
− | end
| |
− | return {values = {value = note.note or ""}, bg_color = bg_color} | |
− | end
| |
− | return {values = {value = ""}, bg_color = self._transparent}
| |
− | end
| |
− | | |
− | function EquipmentListKai:get_bg_color(default, value, operator, outstanding, good)
| |
− | if not value then
| |
− | return default or self._transparent
| |
− | end
| |
− | local comparison = self._operators[operator or ">"]
| |
− | if outstanding and comparison(value, tonumber(outstanding)) then
| |
− | return self._outstanding_stat_color
| |
− | elseif good and comparison(value, tonumber(good)) then
| |
− | return self._good_stat_color
| |
− | else
| |
− | return default or self._transparent
| |
− | end
| |
− | 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
| |
− | | |
− | function EquipmentListKai:create_table()
| |
− | local equipment_list = {}
| |
− | self._notes = {}
| |
− | for index, equipment_name in ipairs(self._args) do
| |
− | if equipment_name == "-" then
| |
− | table.insert(equipment_list, "break")
| |
− | elseif equipment_name == "#" then
| |
− | table.insert(equipment_list, "header")
| |
− | else
| |
− | local equipment = Equipment(equipment_name)
| |
− | table.insert(equipment_list, equipment)
| |
− | local note = self._args[equipment_name .. self._notes_suffix]
| |
− | if note then
| |
− | note = {note = note}
| |
− | local note_highlight = self._args[equipment_name .. self._notes_suffix .. self._highlight_suffix]
| |
− | if note_highlight then
| |
− | note.highlight = note_highlight
| |
− | end
| |
− | self._notes[equipment] = note
| |
− | end
| |
− | end
| |
− | end
| |
− | | |
− | local rows = {self._table_start}
| |
− | local header
| |
− | local data_rows = {}
| |
− | | |
− | if self._args.comparison then
| |
− | self._columns = self._comparison_columns
| |
− | self._shown_stats = {}
| |
− | | |
− | for index, 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._columns) do
| |
− | row_values[column] = self[column](self, equipment)
| |
− | end
| |
− | if index > 1 then
| |
− | for _, column in ipairs(self._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 = {}
| |
− | for _, column in ipairs(self._stat_columns) do
| |
− | if self._shown_stats[column] then
| |
− | table.insert(stat_columns, format{self._column_header_cell_template, value = Formatting:format_image{StatIcons[column], caption = Formatting:format_stat_name(column)}})
| |
− | else
| |
− | 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
| |
− | self._columns = self._list_columns
| |
− | header = format{self._header_template, stat_columns = format{self._column_header_cell_template, value = self._stats_column_label}}
| |
− | 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._columns) do
| |
− | row_values[column] = self[column](self, equipment)
| |
− | row_values[column].rowspan = 1
| |
− | end
| |
− | end
| |
− | table.insert(data_rows, row_values)
| |
− | end
| |
− | end
| |
− |
| |
− | table.insert(rows, header)
| |
− | 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 |
− | 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 |