Changes

Add edit links
Line 44: Line 44:  
10
 
10
 
},
 
},
 +
_caption_template = [[|+ style="position: relative;" | ${icon}${name}<span style="position: absolute; right: 5px;">${edit_link}</span>]],
 +
_name_custom_row_template = [[! colspan="12" style="text-align: center; padding:5px 5px 5px 5px;" | ${icon}${name}: ${resources}<span style="position: absolute; right: 5px;">${edit_link}</span>]],
 +
_edit_link_text = "Edit",
 +
_equipment_data_documentation = "Template:EquipmentDataDocumentation/EditIntro",
 
_basic_resources_label = "Improvement Cost: ",
 
_basic_resources_label = "Improvement Cost: ",
 
_consumed_equipment_label = "<small>Consumes: ${list}</small>",
 
_consumed_equipment_label = "<small>Consumes: ${list}</small>",
Line 60: Line 64:  
self._single_item = true
 
self._single_item = true
 
end
 
end
for _, item in ipairs(self._items) do
+
for item_index, item in ipairs(self._items) do
local products = item:improvement_products()
+
if type(item) ~= "string" then
if self._single_item then
+
local products = item:improvement_products()
self._title_row = format{[[|+ ${icon}${name}]], icon = Formatting:format_image{Formatting:format_equipment_icon(item:icon())}, name = Formatting:format_link(item:link())}
+
local edit_link = Formatting:format_edit_link(Equipment:get_module(self._args[item_index]), self._edit_link_text, self._equipment_data_documentation)
else
+
if self._single_item then
self._custom_rows[item:name()] = format{[[! colspan="12" style="text-align: center; padding:5px 5px 5px 5px;" | ${icon}${name}: ${resources}]], icon = Formatting:format_image{Formatting:format_equipment_icon(item:icon())}, name = Formatting:format_link(item:link()), resources = Formatting:format_resources(item:improvement_resources() or {devmat = false, screw = false})}
+
self._title_row = format{self._caption_template,  
table.insert(result, item:name())
+
icon = Formatting:format_image{Formatting:format_equipment_icon(item:icon())},  
end
+
name = Formatting:format_link(item:link()),
if products then
+
edit_link = edit_link,
for _, product in ipairs(products) do
+
}
local ships = item:improvement_ships(product)
+
else
local availability = {}
+
self._custom_rows[item:name()] = format{self._name_custom_row_template,  
local ship_data = {}
+
icon = Formatting:format_image{Formatting:format_equipment_icon(item:icon())},  
for _, ship in ipairs(ships) do
+
name = Formatting:format_link(item:link()),  
availability[ship] = item:improvement_availability(product, ship)
+
resources = Formatting:format_resources(item:improvement_resources() or {devmat = false, screw = false}),
if type(ship) == "string" then
+
edit_link = edit_link,
ship_data[ship] = Ship(ship)
+
}
 +
table.insert(result, item:name())
 +
end
 +
if products then
 +
for _, product in ipairs(products) do
 +
local ships = item:improvement_ships(product)
 +
local availability = {}
 +
local ship_data = {}
 +
for _, ship in ipairs(ships) do
 +
availability[ship] = item:improvement_availability(product, ship)
 +
if type(ship) == "string" then
 +
ship_data[ship] = Ship(ship)
 +
end
 
end
 
end
end
+
local ships_to_skip = {[true] = true}
local ships_to_skip = {[true] = true}
+
local indexes_to_delete = {}
local indexes_to_delete = {}
+
for index, ship in ipairs(ships) do
for index, ship in ipairs(ships) do
+
if not ships_to_skip[ship] then
if not ships_to_skip[ship] then
+
local remodel_from = ship_data[ship]:remodel_from()
local remodel_from = ship_data[ship]:remodel_from()
+
if ship_data[remodel_from] then
if ship_data[remodel_from] then
+
local identical = true
local identical = true
+
for day, possible in pairs(availability[ship]) do
for day, possible in pairs(availability[ship]) do
+
if availability[remodel_from][day] ~= possible then
if availability[remodel_from][day] ~= possible then
+
identical = false
identical = false
+
end
 +
end
 +
if identical then
 +
ships_to_skip[ship] = true
 +
table.insert(indexes_to_delete, index)
 
end
 
end
end
  −
if identical then
  −
ships_to_skip[ship] = true
  −
table.insert(indexes_to_delete, index)
   
end
 
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
 +
for _, stars in ipairs(self._improvement_brackets) do
 +
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
table.sort(indexes_to_delete, function(a,b) return a > b end)
+
else
for _, index in ipairs(indexes_to_delete) do
  −
table.remove(ships, index)
  −
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, ship_data = ship_data, availability = availability, resources = item:improvement_resources(false, product, stars), resources_x = item:improvement_resources(true, product, stars)})
+
table.insert(result, {item = item, stars = stars})
 
end
 
end
end
  −
else
  −
for _, stars in ipairs(self._improvement_brackets) do
  −
table.insert(result, {item = item, stars = stars})
   
end
 
end
 
end
 
end
Anonymous user