show-buildable/data-updates.lua

changeset 14
c26d4dd2af9b
child 19
adbc5c74f279
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/show-buildable/data-updates.lua	Sat Jul 05 00:35:41 2025 +0300
@@ -0,0 +1,89 @@
+require("sb-util")
+
+---@param fluid_box data.FluidBox?
+local function mangle_fluid_box(fluid_box)
+	if fluid_box
+	then
+		for _, pipe_connection in pairs (fluid_box.pipe_connections)
+		do
+			pipe_connection.position = {0, 0}
+		end
+	end
+end
+
+local function supported(entity_type)
+	if (entity_type == "rail-support" or entity_type == "rail-ramp")
+		and not feature_flags.rail_bridges
+	then
+		return false
+	else
+		return true
+	end
+end
+
+-- Make a bunch of dummy entities for collision testing purposes
+local new_entities = {}
+for _, entity_type in pairs (entity_categories)
+do
+	for _, base_entity in pairs (supported(entity_type) and data.raw[entity_type] or {})
+	do
+		if has_flag(base_entity, "player-creation")
+		then
+			local new_entity = table.deepcopy (base_entity)
+			new_entity.name = "collision-tester-"..base_entity.name
+			new_entity.circuit_connector = nil
+			new_entity.next_upgrade = nil
+			new_entity.fast_replaceable_group = nil
+			mangle_fluid_box(new_entity.fluid_box)
+			for _, fluid_box in pairs (new_entity.fluid_boxes or {})
+			do
+				mangle_fluid_box(fluid_box)
+			end
+			mangle_fluid_box(new_entity.input_fluid_box)
+			mangle_fluid_box(new_entity.output_fluid_box)
+			mangle_fluid_box(new_entity.fuel_fluid_box)
+			mangle_fluid_box(new_entity.oxidizer_fluid_box)
+			if new_entity.type == "mining-drill"
+				or new_entity.type == "assembling-machine"
+				or new_entity.type == "fusion-generator"
+				or new_entity.type == "fusion-reactor"
+				or new_entity.type == "inserter"
+				or new_entity.type == "thruster"
+				or new_entity.type == "cargo-bay"
+				or new_entity.type == "cargo-landing-pad"
+				or new_entity.type == "transport-belt"
+				or new_entity.type == "splitter"
+				or new_entity.type == "container"
+				or new_entity.type == "loader"
+				or new_entity.type == "pump"
+				or new_entity.type == "rocket-silo"
+				or new_entity.type == "solar-panel"
+			then
+				-- I'd use simple entities here, but they need to be rotatable
+				new_entity.type = "assembling-machine"
+				new_entity.input_fluid_box = nil
+				new_entity.output_fluid_box = nil
+				new_entity.fluid_boxes = {}
+				new_entity.energy_usage = "1W"
+				new_entity.energy_source = {type="void"}
+				new_entity.crafting_speed = 1
+				new_entity.crafting_categories = {"crafting"}
+				new_entity.fixed_recipe = nil
+				new_entity.module_slots = 0
+			end
+			if (new_entity.type == "cargo-landing-pad" or new_entity.type == "cargo-bay")
+				and new_entity.graphics_set
+			then
+				new_entity.graphics_set.connections = nil
+			end
+			if (new_entity.type == "cargo-bay")
+				and new_entity.platform_graphics_set
+			then
+				new_entity.platform_graphics_set.connections = nil
+			end
+			table.insert (new_entities, new_entity)
+		end
+	end
+end
+
+data:extend (new_entities)
\ No newline at end of file

mercurial