Changes

Groundwork for streamlining data for helper ships with the same base
Line 71: Line 71:  
local ships = item:improvement_ships(product)
 
local ships = item:improvement_ships(product)
 
local availability = {}
 
local availability = {}
 +
local ship_data = {}
 
for _, ship in ipairs(ships) do
 
for _, ship in ipairs(ships) do
 
availability[ship] = item:improvement_availability(product, ship)
 
availability[ship] = item:improvement_availability(product, ship)
 +
if type(ship) == "string" then
 +
ship_data[ship] = Ship(ship)
 +
end
 +
end
 +
local ships_to_skip = {[true] = true}
 +
local indexes_to_delete = {}
 +
for index, ship in ipairs(ships) do
 +
if not ships_to_skip[ship] then
 +
local remodel_to = ship_data[ship]:remodel_to()
 +
if ship_data[remodel_to] then
 +
local identical = true
 +
for day, possible in pairs(availability[ship]) do
 +
if availability[remodel_to][day] ~= possible then
 +
identical = false
 +
end
 +
end
 +
if identical then
 +
ships_to_skip[ship] = true
 +
table.insert(indexes_to_delete, index)
 +
end
 +
end
 +
end
 +
end
 +
table.sort(indexes_to_delete, function(a,b) return a > b end)
 +
for _, index in ipairs(indexes_to_delete) do
 +
table.remove(ships, index)
 
end
 
end
 
for _, stars in ipairs(self._improvement_brackets) do
 
for _, stars in ipairs(self._improvement_brackets) do
table.insert(result, {item = item, product = product, stars = stars, ships = ships, availability = availability, resources = item:improvement_resources(false, product, stars), resources_x = item:improvement_resources(true, product, stars)})
+
table.insert(result, {item = item, product = product, stars = stars, ships = ships, ship_data = ship_data, availability = availability, resources = item:improvement_resources(false, product, stars), resources_x = item:improvement_resources(true, product, stars)})
 
end
 
end
 
end
 
end
Line 155: Line 182:  
local ship_initial
 
local ship_initial
 
if ship ~= true then
 
if ship ~= true then
if not self._helper_ships then
+
ship_initial = mw.ustring.sub(row_data.ship_data[ship]:name(), 1, 2)
self._helper_ships = {}
  −
end
  −
self._helper_ships[ship] = Ship(ship)
  −
ship_initial = mw.ustring.sub(self._helper_ships[ship]:name(), 1, 2)
   
else
 
else
 
ship_initial = "✓"
 
ship_initial = "✓"
Line 175: Line 198:  
for index, ship in ipairs(row_data.ships) do
 
for index, ship in ipairs(row_data.ships) do
 
if ship ~= true then
 
if ship ~= true then
table.insert(ships, Formatting:format_link(Ship(ship):link()))
+
table.insert(ships, Formatting:format_link(row_data.ship_data[ship]:link()))
 
else
 
else
 
table.insert(ships, "Any")
 
table.insert(ships, "Any")
Anonymous user