Changes

Add categories feature
Line 59: Line 59:  
_small_icon_size = "24x24px",
 
_small_icon_size = "24x24px",
 
_combined_names_template = "${text}<small> (${combined_text})</small>",
 
_combined_names_template = "${text}<small> (${combined_text})</small>",
 +
_required_ship_category_template = "Category:Equipment that require ${ship_name} to be improved",
 +
_consumed_equip_category_template = "Category:Equipment that consume ${equip_name} during improvement",
 
}
 
}
   Line 95: Line 97:  
if type(ship) == "string" then
 
if type(ship) == "string" then
 
ship_data[ship] = Ship(ship)
 
ship_data[ship] = Ship(ship)
 +
    if self._single_item and self._args.categories then
 +
        self._ships = self._ships or {}
 +
        self._ships[ship] = ship_data[ship]
 +
    end
 
end
 
end
 
end
 
end
Line 247: Line 253:  
else
 
else
 
equipment = row_data.item
 
equipment = row_data.item
 +
end
 +
if self._single_item and self._args.categories then
 +
    self._consumed_equipment = self._consumed_equipment or {}
 +
    self._consumed_equipment[equip == true and equipment:name() or equip] = equipment
 
end
 
end
 
table.insert(consumed_equipment, format{self._equipment_item, count = count or Formatting:format_stat(nil), icon = Formatting:format_image{Formatting:format_equipment_icon_simple(equipment:icon()), size = self._small_icon_size}, name = equip == true and Formatting:format_stat(equipment:name()) or Formatting:format_link(equipment:link())})
 
table.insert(consumed_equipment, format{self._equipment_item, count = count or Formatting:format_stat(nil), icon = Formatting:format_image{Formatting:format_equipment_icon_simple(equipment:icon()), size = self._small_icon_size}, name = equip == true and Formatting:format_stat(equipment:name()) or Formatting:format_link(equipment:link())})
Line 409: Line 419:  
end
 
end
 
table.insert(self._rows, self._table_end)
 
table.insert(self._rows, self._table_end)
 +
end
 +
 +
function ImprovementTableKai:post_process()
 +
    if self._single_item and self._args.categories then
 +
        local categories = {}
 +
        local ships_index = {}
 +
        for ship, ship_data in pairs(self._ships) do
 +
            table.insert(ships_index, ship)
 +
        end
 +
        table.sort(ships_index)
 +
        for _, ship in ipairs(ships_index) do
 +
            table.insert(categories, Formatting:format_link(format{self._required_ship_category_template, ship_name = self._ships[ship]:name()}))
 +
        end
 +
        local equip_index = {}
 +
        for equip, equip_data in pairs(self._consumed_equipment) do
 +
            table.insert(equip_index, equip)
 +
        end
 +
        table.sort(equip_index)
 +
        for _, equip in ipairs(equip_index) do
 +
            table.insert(categories, Formatting:format_link(format{self._consumed_equip_category_template, equip_name = self._consumed_equipment[equip]:name()}))
 +
        end
 +
        self._result = self._result .. table.concat(categories)
 +
    end
 
end
 
end
  
Anonymous user