more-descriptions/data-final-fixes.lua

changeset 17
df60e9144d82
parent 16
2cdb59ae5fcf
--- a/more-descriptions/data-final-fixes.lua	Wed Jul 23 14:46:54 2025 +0300
+++ b/more-descriptions/data-final-fixes.lua	Wed Jul 23 16:08:48 2025 +0300
@@ -27,6 +27,18 @@
 	end
 end
 
+local function basic_order(a)
+	return 100 + a
+end
+
+local function generic_order(a)
+	return 150 + a
+end
+
+local function specific_order(a)
+	return 200 + a
+end
+
 ---@param x string
 local function energy_zero(x)
 	return x == nil or energy_zero_table[x]
@@ -264,10 +276,10 @@
 	then
 		ammo_categories[ammo.ammo_category] = ammo_categories[ammo.ammo_category] .. "..."
 	end
-end	
+end
 
 ---@param proto data.Prototype
----@param tooltip_field LocalisedString
+---@param tooltip_field data.CustomTooltipField
 local function generic_add_description(proto, tooltip_field)
 	if not proto.custom_tooltip_fields
 	then
@@ -276,6 +288,30 @@
 	table.insert(proto.custom_tooltip_fields, tooltip_field)
 end
 
+---@param proto data.Prototype
+---@param attack_parameters  data.AttackParameters
+local function add_ammo_from_attack_parameters(proto, attack_parameters)
+	if attack_parameters.ammo_category and ammo_categories[attack_parameters.ammo_category]
+	then
+		generic_add_description(proto, {
+			name = {"more-descriptions-mod.gun-accepts-ammo"},
+			value = ammo_categories[attack_parameters.ammo_category],
+			order = generic_order(10),
+		})
+	end
+	for _, category in pairs(attack_parameters.ammo_categories or {})
+	do
+		if ammo_categories[category]
+		then
+			generic_add_description(proto, {
+				name = {"more-descriptions-mod.gun-accepts-ammo"},
+				value = ammo_categories[category],
+				order = generic_order(0),
+			})
+		end
+	end
+end
+
 for _, item_type in pairs(item_categories)
 do
 	for _, item in pairs(data.raw[item_type] or {})
@@ -286,25 +322,6 @@
 		local function add_description(tooltip_field)
 			generic_add_description(item, tooltip_field)
 		end
-
-		local add_ammo_from_attack_parameters = function(attack_parameters)
-			if attack_parameters.ammo_category and ammo_categories[attack_parameters.ammo_category]
-			then
-				add_description{
-					name = {"more-descriptions-mod.gun-accepts-ammo"},
-					value = ammo_categories[attack_parameters.ammo_category]}
-			end
-			for _, category in pairs(attack_parameters.ammo_categories or {})
-			do
-				if ammo_categories[category]
-				then
-					add_description{
-						name = {"more-descriptions-mod.gun-accepts-ammo"},
-						value = ammo_categories[category]}
-				end
-			end
-		end
-
 		if recycling_recipe ~= nil
 		then
 			local recycling_results = {""}
@@ -319,6 +336,7 @@
 					seconds(recycling_recipe.energy_required),
 					snap(recycling_results),
 				},
+				order = generic_order(0),
             }
 		end
 
@@ -330,12 +348,15 @@
 				add_description{
 					name = {"more-descriptions-mod.refining-cost"},
 					value = seconds(refining_recipe.energy_required),
+					order = generic_order(1),
 				}
 			elseif recycling_recipe ~= nil
 			then
 				add_description{
 					name = {"more-descriptions-mod.cannot-be-refined"},
-					value = ""}
+					value = "",
+					order = generic_order(1),
+				}
 			end
 		end
 
@@ -344,6 +365,7 @@
 			add_description{
 				name = {"more-descriptions-mod.reload-time"},
 				value = seconds(tostring(item.reload_time / 60.0)),
+				order = specific_order(0),
 			}
 		end
 
@@ -352,6 +374,7 @@
 			add_description{
 				name = {"more-descriptions-mod.fires-automatically"},
 				value = "",
+				order = specific_order(0),
 			}
 		end
 
@@ -360,265 +383,13 @@
 			add_description{
 				name = {"more-descriptions-mod.armor-provides-flight"},
 				value = "",
+				order = specific_order(0),
 			}
 		end
 
 		if item.type == "gun"
 		then
-			add_ammo_from_attack_parameters(item.attack_parameters)
-		end
-
-		local entity = item.place_result and find_entity(item.place_result) or nil
-		if entity ~= nil
-		then
-			if entity.collision_box
-			then
-				local cb = entity.collision_box
-				local width = math.ceil(cb[2][1] - cb[1][1])
-				local height = math.ceil(cb[2][2] - cb[1][2])
-				add_description{
-					name = {"more-descriptions-mod.entity-size"},
-					value = {
-						"more-descriptions-mod.size",
-						tostring(width),
-						tostring(height),
-					},
-				}
-			end
-
-			if entity.drops_full_belt_stacks
-			then
-				add_description{
-					name = {"more-descriptions-mod.drops-full-belt-stacks"},
-					value = ""}
-			end
-
-			if entity.heat_buffer and entity.heat_buffer.specific_heat
-			then
-				add_description{
-					name = {"more-descriptions-mod.specific-heat"},
-					value = {
-						"more-descriptions-mod.energy-per-degrees-celsius",
-						entity.heat_buffer.specific_heat,
-					},
-				}
-			elseif entity.energy_source
-				and entity.energy_source.type == "heat"
-				and entity.energy_source.specific_heat
-			then
-				add_description{
-					name = {"more-descriptions-mod.specific-heat"},
-					value = entity.energy_source.specific_heat,
-				}
-			end
-
-			if entity.is_military_target
-			then
-				add_description{
-					name = {"more-descriptions-mod.is-military-target"},
-					value = "",
-				}
-			end
-
-			if not energy_zero(entity.heating_energy or "0W")
-			then
-				local value = entity.heating_energy
-				if entity.type == "underground-belt" or entity.type == "pipe-to-ground"
-				then
-					value = {"more-descriptions-mod.value-per-end", value}
-				end
-				add_description{
-					name = {"more-descriptions-mod.heating-energy"},
-					value = value,
-				}
-			elseif freezable_entity_categories[entity.type]
-			then
-				add_description{
-					name = {"more-descriptions-mod.no-heating-energy"},
-					value = "",
-				}
-			end
-
-			if entity.type == "agricultural-tower"
-			then
-				local cb = entity.collision_box
-				local W = math.ceil(cb[2][1] - cb[1][1])
-				local w = (entity.growth_grid_tile_size or 3)
-				-- width of the "buffer" area around the agricultural tower
-				local z = (2 * w * math.ceil((W - w) / 2 / w)) + w
-				-- num of growth cells extending from the edges of the tower
-				local r = math.floor(entity.radius) -- why is it double..?
-				add_description{
-					name = {"more-descriptions-mod.agricultural-tower-num-inputs"},
-					value = tostring(entity.input_inventory_size)
-				}
-				add_description{
-					name = {"more-descriptions-mod.agricultural-tower-growth-cell-size"},
-					value = {
-						"more-descriptions-mod.size",
-						tostring(w),
-						tostring(w),
-					}
-				}
-				add_description{
-					name = {"more-descriptions-mod.agricultural-tower-growth-cell-count"},
-					value = tostring(4 * r * (r + (z / w)))
-				}
-				total_size = tostring(z + 2 * r * w)
-				add_description{
-					name = {"more-descriptions-mod.agricultural-tower-total-size"},
-					value = {
-						"more-descriptions-mod.size",
-						total_size,
-						total_size,
-					},
-				}
-			elseif entity.type == "ammo-turret"
-			then
-				if entity.energy_per_shot ~= nil
-				then
-					add_description{
-						name = {"more-descriptions-mod.energy-per-shot-fired"},
-						value = entity.energy_per_shot}
-				end
-				add_ammo_from_attack_parameters(entity.attack_parameters)
-			elseif entity.type == "beacon"
-			then
-				add_description{
-					name = {"more-descriptions-mod.beacon-supply-area-distance"},
-					value = tostring(entity.supply_area_distance)
-				}
-			elseif entity.type == "car"
-			then
-				local immunities = ""
-				if (entity.immune_to_tree_impacts or false)
-				then
-					immunities = immunities.."[entity=tree-01]"
-				end
-				if (entity.immune_to_rock_impacts or false)
-				then
-					immunities = immunities.."[entity=big-rock]"
-				end
-				if (entity.immune_to_cliff_impacts or true)
-				then
-					immunities = immunities.."[entity=cliff]"
-				end
-				if immunities ~= ""
-				then
-					add_description{
-						name = {"more-descriptions-mod.car-immune-to-impacts"},value = immunities}
-				end
-			elseif entity.type == "constant-combinator"
-			then
-				-- used by pushbutton mod
-				if (entity.pulse_duration or 0) > 60
-				then
-					add_description{
-						name = {"more-descriptions-mod.constant-combinator-pulse-duration"},
-						value = seconds(entity.pulse_duration / 60.0),
-					}
-				elseif (entity.pulse_duration or 0) > 0
-				then
-					add_description{
-						name = {"more-descriptions-mod.constant-combinator-pulse-duration"},
-						value = {
-							"more-descriptions-mod.ticks",
-							tostring(entity.pulse_duration),
-						},
-					}
-				end
-			elseif (entity.type == "container" or entity.type == "logistic-container")
-			then
-				if entity.inventory_type == "with_filters_and_bar"
-				then
-					add_description{
-						name = {"more-descriptions-mod.container-filters"},
-						value = "",
-					}
-				end
-			elseif entity.type == "cargo-wagon"
-			then
-				-- all cargo wagons support filters
-				add_description{
-					name = {"more-descriptions-mod.container-filters"},
-					value = "",
-				}
-			elseif entity.type == "display-panel"
-			then
-				add_description{
-					name = {"more-descriptions-mod.display-panel-max-text-width"},
-					value = tostring(entity.max_text_width or 400),
-				}
-			elseif entity.type == "logistic-robot" or entity.type == "construction-robot"
-			then
-				if entity.speed_multiplier_when_out_of_energy > 0
-				then
-					add_description{
-						name = {"more-descriptions-mod.robot-speed-multiplier-when-out-of-energy"},
-						value = tostring(entity.speed_multiplier_when_out_of_energy * 100),
-					}
-				else
-					add_description{
-						name = {"more-descriptions-mod.robot-crashes-when-out-of-energy"},
-						value = "",
-					}
-				end
-			elseif entity.type == "inserter"
-			then
-				if entity.bulk
-				then
-					add_description{
-						name = {"more-descriptions-mod.inserter-bulk"},
-						value = tostring(entity.filter_count),
-					}
-				end
-				if entity.wait_for_full_hand
-				then
-					add_description{
-						name = {"more-descriptions-mod.inserter-wait-for-full-hand"},
-						value = "",
-					}
-				end
-				if entity.enter_drop_mode_if_held_stack_spoiled
-				then
-					add_description{
-						name = {"more-descriptions-mod.inserter-enters-drop-mode-if-held-stack-spoils"},
-						value = "",
-					}
-				end
-			elseif entity.type == "land-mine"
-			then
-				add_description{
-					name = {"more-descriptions-mod.land-mine-timeout"},
-					value = seconds((entity.timeout or 120) / 60.0),
-				}
-			elseif entity.type == "radar"
-			then
-				if entity.connects_to_other_radars ~= false
-				then
-					add_description{
-						name = {"more-descriptions-mod.radar-connection"},
-						value = "",
-					}
-				end
-			end
-			if entity.filter_count
-			then
-				add_description{
-					name = {"more-descriptions-mod.filter-count"},
-					value = tostring(entity.filter_count),
-				}
-			end
-			for _, flag in pairs(entity.flags or {})
-			do
-				if flag == "no-automated-item-insertion"
-				then
-					add_description{
-						name = {"more-descriptions-mod.no-automated-item-insertion"},
-						value = "",
-					}
-				end
-			end
+			add_ammo_from_attack_parameters(item, item.attack_parameters)
 		end
 	end
 end
@@ -661,7 +432,6 @@
 	end
 end
 
--- Stuff mostly specific for entities that you don't place with items (like biters)
 for _, entity_category in pairs(entity_categories)
 do
 	for _, entity in pairs(data.raw[entity_category] or {})
@@ -670,12 +440,28 @@
 		local function add_description(tooltip_field)
 			generic_add_description(entity, tooltip_field)
 		end
+		if entity.collision_box
+		then
+			local cb = entity.collision_box
+			local width = math.ceil(cb[2][1] - cb[1][1])
+			local height = math.ceil(cb[2][2] - cb[1][2])
+			add_description{
+				name = {"more-descriptions-mod.entity-size"},
+				value = {
+					"more-descriptions-mod.size",
+					tostring(width),
+					tostring(height),
+				},
+				order = basic_order(0),
+			}
+		end
 
 		if entity.minable
 		then
 			add_description{
 				name = {"more-descriptions-mod.mining-time"},
 				value = seconds(entity.minable.mining_time),
+				order = basic_order(1),
 			}
 		end
 
@@ -686,6 +472,7 @@
 				add_description{
 					name = {"more-descriptions-mod.breathes-air"},
 					value = "",
+					order = generic_order(0),
 				}
 			end
 		end
@@ -697,6 +484,270 @@
 				add_description{
 					name = {"more-descriptions-mod.unit-spawner-time-to-capture"},
 					value = seconds(entity.time_to_capture / 60.0),
+					order = specific_order(0),
+				}
+			end
+		end
+
+		if entity.drops_full_belt_stacks
+		then
+			add_description{
+				name = {"more-descriptions-mod.drops-full-belt-stacks"},
+				value = "",
+				order = generic_order(10),
+			}
+		end
+
+		if entity.heat_buffer and entity.heat_buffer.specific_heat
+		then
+			add_description{
+				name = {"more-descriptions-mod.specific-heat"},
+				value = {
+					"more-descriptions-mod.energy-per-degrees-celsius",
+					entity.heat_buffer.specific_heat,
+				},
+				order = generic_order(10),
+			}
+		elseif entity.energy_source
+			and entity.energy_source.type == "heat"
+			and entity.energy_source.specific_heat
+		then
+			add_description{
+				name = {"more-descriptions-mod.specific-heat"},
+				value = entity.energy_source.specific_heat,
+				order = generic_order(10),
+			}
+		end
+
+		if entity.is_military_target
+		then
+			add_description{
+				name = {"more-descriptions-mod.is-military-target"},
+				value = "",
+				order = generic_order(11),
+			}
+		end
+
+		if not energy_zero(entity.heating_energy or "0W")
+		then
+			local value = entity.heating_energy
+			if entity.type == "underground-belt" or entity.type == "pipe-to-ground"
+			then
+				value = {"more-descriptions-mod.value-per-end", value}
+			end
+			add_description{
+				name = {"more-descriptions-mod.heating-energy"},
+				value = value,
+				order = basic_order(5),
+			}
+		elseif freezable_entity_categories[entity.type]
+		then
+			add_description{
+				name = {"more-descriptions-mod.no-heating-energy"},
+				value = "",
+				order = basic_order(5),
+			}
+		end
+
+		if entity.type == "agricultural-tower"
+		then
+			local cb = entity.collision_box
+			local W = math.ceil(cb[2][1] - cb[1][1])
+			local w = (entity.growth_grid_tile_size or 3)
+			-- width of the "buffer" area around the agricultural tower
+			local z = (2 * w * math.ceil((W - w) / 2 / w)) + w
+			-- num of growth cells extending from the edges of the tower
+			local r = math.floor(entity.radius) -- why is it double..?
+			add_description{
+				name = {"more-descriptions-mod.agricultural-tower-num-inputs"},
+				value = tostring(entity.input_inventory_size)
+			}
+			add_description{
+				name = {"more-descriptions-mod.agricultural-tower-growth-cell-size"},
+				value = {
+					"more-descriptions-mod.size",
+					tostring(w),
+					tostring(w),
+				},
+				order = specific_order(0),
+			}
+			add_description{
+				name = {"more-descriptions-mod.agricultural-tower-growth-cell-count"},
+				value = tostring(4 * r * (r + (z / w))), -- maths
+				order = specific_order(1),
+			}
+			total_size = tostring(z + 2 * r * w)
+			add_description{
+				name = {"more-descriptions-mod.agricultural-tower-total-size"},
+				value = {
+					"more-descriptions-mod.size",
+					total_size,
+					total_size,
+				},
+				order = specific_order(2),
+			}
+		elseif entity.type == "ammo-turret"
+		then
+			if entity.energy_per_shot ~= nil
+			then
+				add_description{
+					name = {"more-descriptions-mod.energy-per-shot-fired"},
+					value = entity.energy_per_shot,
+					order = generic_order(11),
+				}
+			end
+			add_ammo_from_attack_parameters(entity, entity.attack_parameters)
+		elseif entity.type == "beacon"
+		then
+			add_description{
+				name = {"more-descriptions-mod.beacon-supply-area-distance"},
+				value = tostring(entity.supply_area_distance),
+				order = specific_order(0),
+			}
+		elseif entity.type == "car"
+		then
+			local immunities = ""
+			if (entity.immune_to_tree_impacts or false)
+			then
+				immunities = immunities.."[entity=tree-01]"
+			end
+			if (entity.immune_to_rock_impacts or false)
+			then
+				immunities = immunities.."[entity=big-rock]"
+			end
+			if (entity.immune_to_cliff_impacts or true)
+			then
+				immunities = immunities.."[entity=cliff]"
+			end
+			if immunities ~= ""
+			then
+				add_description{
+					name = {"more-descriptions-mod.car-immune-to-impacts"},value = immunities,
+					order = specific_order(0),
+				}
+			end
+		elseif entity.type == "constant-combinator"
+		then
+			-- used by pushbutton mod
+			if (entity.pulse_duration or 0) > 60
+			then
+				add_description{
+					name = {"more-descriptions-mod.constant-combinator-pulse-duration"},
+					value = seconds(entity.pulse_duration / 60.0),
+					order = specific_order(0),
+				}
+			elseif (entity.pulse_duration or 0) > 0
+			then
+				add_description{
+					name = {"more-descriptions-mod.constant-combinator-pulse-duration"},
+					value = {
+						"more-descriptions-mod.ticks",
+						tostring(entity.pulse_duration),
+					},
+					order = specific_order(0),
+				}
+			end
+		elseif (entity.type == "container" or entity.type == "logistic-container")
+		then
+			if entity.inventory_type == "with_filters_and_bar"
+			then
+				add_description{
+					name = {"more-descriptions-mod.container-filters"},
+					value = "",
+					order = specific_order(0),
+				}
+			end
+		elseif entity.type == "cargo-wagon"
+		then
+			-- all cargo wagons support filters
+			add_description{
+				name = {"more-descriptions-mod.container-filters"},
+				value = "",
+				order = specific_order(0),
+			}
+		elseif entity.type == "display-panel"
+		then
+			add_description{
+				name = {"more-descriptions-mod.display-panel-max-text-width"},
+				value = tostring(entity.max_text_width or 400),
+				order = specific_order(0),
+			}
+		elseif entity.type == "logistic-robot" or entity.type == "construction-robot"
+		then
+			if entity.speed_multiplier_when_out_of_energy > 0
+			then
+				add_description{
+					name = {"more-descriptions-mod.robot-speed-multiplier-when-out-of-energy"},
+					value = tostring(entity.speed_multiplier_when_out_of_energy * 100),
+					order = specific_order(0),
+				}
+			else
+				add_description{
+					name = {"more-descriptions-mod.robot-crashes-when-out-of-energy"},
+					value = "",
+					order = specific_order(0),
+				}
+			end
+		elseif entity.type == "inserter"
+		then
+			if entity.bulk
+			then
+				add_description{
+					name = {"more-descriptions-mod.inserter-bulk"},
+					value = "",
+					order = specific_order(0),
+				}
+			end
+			if entity.wait_for_full_hand
+			then
+				add_description{
+					name = {"more-descriptions-mod.inserter-wait-for-full-hand"},
+					value = "",
+					order = specific_order(1),
+				}
+			end
+			if entity.enter_drop_mode_if_held_stack_spoiled
+			then
+				add_description{
+					name = {"more-descriptions-mod.inserter-enters-drop-mode-if-held-stack-spoils"},
+					value = "",
+					order = specific_order(2),
+				}
+			end
+		elseif entity.type == "land-mine"
+		then
+			add_description{
+				name = {"more-descriptions-mod.land-mine-timeout"},
+				value = seconds((entity.timeout or 120) / 60.0),
+				order = specific_order(0),
+			}
+		elseif entity.type == "radar"
+		then
+			if entity.connects_to_other_radars ~= false
+			then
+				add_description{
+					name = {"more-descriptions-mod.radar-connection"},
+					value = "",
+					order = specific_order(0),
+				}
+			end
+		end
+		if entity.filter_count
+		then
+			add_description{
+				name = {"more-descriptions-mod.filter-count"},
+				value = tostring(entity.filter_count),
+				order = basic_order(5),
+			}
+		end
+		for _, flag in pairs(entity.flags or {})
+		do
+			if flag == "no-automated-item-insertion"
+			then
+				add_description{
+					name = {"more-descriptions-mod.no-automated-item-insertion"},
+					value = "",
+					order = basic_order(6),
 				}
 			end
 		end
@@ -720,6 +771,7 @@
 				add_description{
 					name = {"more-descriptions-mod.space-location-fly-condition"},
 					value = "",
+					order = specific_order(0),
 				}
 			end
 			if space_location.auto_save_on_first_trip == false -- (nil=true)
@@ -727,6 +779,7 @@
 				add_description{
 					name = {"more-descriptions-mod.space-location-no-autosave"},
 					value = "",
+					order = specific_order(1),
 				}
 			end
 		end

mercurial