Browse Source

changed loading to use the node generation instead of templates

Jonathan Higgins 6 months ago
parent
commit
44e8115e24
2 changed files with 29 additions and 28 deletions
  1. 21 14
      scenes/main/scripts/graph_edit.gd
  2. 8 14
      scenes/main/scripts/save_load.gd

+ 21 - 14
scenes/main/scripts/graph_edit.gd

@@ -31,7 +31,7 @@ func init(main_node: Node, graphedit: GraphEdit, openhelp: Callable, multiplecon
 	open_help = openhelp
 	multiple_connections = multipleconnections
 
-func _make_node(command: String):
+func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 	if node_data.has(command):
 		var node_info = node_data[command]
 		
@@ -48,12 +48,15 @@ func _make_node(command: String):
 
 			control_script.changesmade = true
 
-			# Remove node with UndoRedo
-			control_script.undo_redo.create_action("Add Node")
-			control_script.undo_redo.add_undo_method(Callable(graph_edit, "remove_child").bind(effect))
-			control_script.undo_redo.add_undo_method(Callable(effect, "queue_free"))
-			control_script.undo_redo.add_undo_method(Callable(self, "_track_changes"))
-			control_script.undo_redo.commit_action()
+			if not skip_undo_redo:
+				# Remove node with UndoRedo
+				control_script.undo_redo.create_action("Add Node")
+				control_script.undo_redo.add_undo_method(Callable(graph_edit, "remove_child").bind(effect))
+				control_script.undo_redo.add_undo_method(Callable(effect, "queue_free"))
+				control_script.undo_redo.add_undo_method(Callable(self, "_track_changes"))
+				control_script.undo_redo.commit_action()
+			
+			return effect
 		else: #auto generate node from json
 			#get the title to display at the top of the node
 			var title 
@@ -102,7 +105,7 @@ func _make_node(command: String):
 					pass
 			#set meta data for the process
 			graphnode.set_meta("command", command)
-			graphnode.set_meta("stereo", stereo)
+			graphnode.set_meta("stereo_input", stereo)
 			
 			#adjust size, position and title of the node
 			graphnode.title = title
@@ -167,13 +170,17 @@ func _make_node(command: String):
 			_register_inputs_in_node(graphnode) #link sliders for changes tracking
 			_register_node_movement() #link nodes for tracking position changes for changes tracking
 			
-			# Remove node with UndoRedo
-			control_script.undo_redo.create_action("Add Node")
-			control_script.undo_redo.add_undo_method(Callable(graph_edit, "remove_child").bind(graphnode))
-			control_script.undo_redo.add_undo_method(Callable(graphnode, "queue_free"))
-			control_script.undo_redo.add_undo_method(Callable(self, "_track_changes"))
-			control_script.undo_redo.commit_action()
+			if not skip_undo_redo:
+				# Remove node with UndoRedo
+				control_script.undo_redo.create_action("Add Node")
+				control_script.undo_redo.add_undo_method(Callable(graph_edit, "remove_child").bind(graphnode))
+				control_script.undo_redo.add_undo_method(Callable(graphnode, "queue_free"))
+				control_script.undo_redo.add_undo_method(Callable(self, "_track_changes"))
+				control_script.undo_redo.commit_action()
+			
+			return graphnode
 			
+	return null
 	
 
 func _on_connection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void:

+ 8 - 14
scenes/main/scripts/save_load.gd

@@ -99,7 +99,6 @@ func save_graph_edit(path: String):
 	print("thread saved, changes made =")
 	print(control_script.changesmade)
 
-
 func load_graph_edit(path: String):
 	var file = FileAccess.open(path, FileAccess.READ)
 	if file == null:
@@ -124,24 +123,18 @@ func load_graph_edit(path: String):
 
 	await get_tree().process_frame  # Ensure nodes are freed before adding new ones
 
-	var id_to_node = {}  # Map node IDs to new node instances
+	var id_to_node = {}
 
-	# Recreate nodes and store them by ID
+	# Create nodes
 	for node_data in graph_data["nodes"]:
 		var command_name = node_data.get("command", "")
-		var template = Nodes.get_node_or_null(command_name)
-		if not template:
-			print("Template not found for command:", command_name)
+		var new_node = graph_edit._make_node(command_name, true)
+		if new_node == null:
+			print("Failed to create node for command:", command_name)
 			continue
 
-		var new_node: GraphNode = template.duplicate()
 		new_node.name = node_data["name"]
 		new_node.position_offset = Vector2(node_data["offset"]["x"], node_data["offset"]["y"])
-		new_node.set_meta("command", command_name)
-		graph_edit.add_child(new_node)
-		new_node.connect("open_help", open_help)
-		register_movement.call()  # Track node movement changes
-
 		id_to_node[node_data["id"]] = new_node
 
 		# Restore sliders
@@ -176,9 +169,9 @@ func load_graph_edit(path: String):
 			if codeedit and (codeedit is CodeEdit):
 				codeedit.text = node_data["notes"][codeedit_name]
 
-		register_input.call(new_node)  # Track slider changes
+		register_input.call(new_node)
 
-	# Recreate connections by looking up nodes by ID
+	# Recreate connections
 	for conn in graph_data["connections"]:
 		var from_node = id_to_node.get(conn["from_node_id"], null)
 		var to_node = id_to_node.get(conn["to_node_id"], null)
@@ -195,3 +188,4 @@ func load_graph_edit(path: String):
 	print("Graph loaded.")
 	get_window().title = "SoundThread - " + path.get_file().trim_suffix(".thd")
 	
+