Kaynağa Gözat

added saving and loading for dynamically created inlets

Jonathan Higgins 3 ay önce
ebeveyn
işleme
21a39734c1

+ 13 - 0
scenes/Nodes/addremoveinlets.gd

@@ -16,12 +16,14 @@ func _ready() -> void:
 func _on_add_inlet_button_button_down() -> void:
 func _on_add_inlet_button_button_down() -> void:
 	add_inlet.emit()
 	add_inlet.emit()
 	current_inlet_count += 1
 	current_inlet_count += 1
+	set_meta("inlet_count", current_inlet_count)
 	check_buttons()
 	check_buttons()
 
 
 
 
 func _on_remove_inlet_button_button_down() -> void:
 func _on_remove_inlet_button_button_down() -> void:
 	remove_inlet.emit()
 	remove_inlet.emit()
 	current_inlet_count -= 1
 	current_inlet_count -= 1
+	set_meta("inlet_count", current_inlet_count)
 	check_buttons()
 	check_buttons()
 
 
 func check_buttons():
 func check_buttons():
@@ -34,3 +36,14 @@ func check_buttons():
 		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = true
 		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = true
 	else:
 	else:
 		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = false
 		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = false
+		
+func restore_inlets():
+	print("current meta for inlet count is " + str(get_meta("inlet_count")))
+	var restore_inlet_count = get_meta("inlet_count")
+	while restore_inlet_count > current_inlet_count:
+		_on_add_inlet_button_button_down()
+	
+	while restore_inlet_count < current_inlet_count:
+		_on_remove_inlet_button_button_down()
+		
+	print("current inlet count is " + str(current_inlet_count))

+ 1 - 1
scenes/Nodes/node_logic.gd

@@ -18,7 +18,7 @@ func _ready() -> void:
 	btn.connect("pressed", Callable(self, "_open_help")) #pass key (process name) when button is pressed
 	btn.connect("pressed", Callable(self, "_open_help")) #pass key (process name) when button is pressed
 	titlebar.add_child(btn)
 	titlebar.add_child(btn)
 	await get_tree().process_frame
 	await get_tree().process_frame
-	reset_size()
+	#reset_size()
 	
 	
 	if self.has_node("addremoveinlets"):
 	if self.has_node("addremoveinlets"):
 		var addremove = self.get_node("addremoveinlets")
 		var addremove = self.get_node("addremoveinlets")

+ 15 - 0
scenes/main/scripts/save_load.gd

@@ -44,6 +44,7 @@ func save_graph_edit(path: String):
 				"command": node.get_meta("command"),
 				"command": node.get_meta("command"),
 				"offset": { "x": offset.x, "y": offset.y },
 				"offset": { "x": offset.x, "y": offset.y },
 				"slider_values": {},
 				"slider_values": {},
+				"addremoveinlets":{},
 				"notes": {},
 				"notes": {},
 				"checkbutton_states": {},
 				"checkbutton_states": {},
 				"optionbutton_values": {}
 				"optionbutton_values": {}
@@ -62,6 +63,11 @@ func save_graph_edit(path: String):
 				for key in child.get_meta_list():
 				for key in child.get_meta_list():
 					node_data["slider_values"][path_str]["meta"][str(key)] = child.get_meta(key)
 					node_data["slider_values"][path_str]["meta"][str(key)] = child.get_meta(key)
 				
 				
+			#save add remove inlet meta data
+			if node.has_node("addremoveinlets"):
+				if node.get_node("addremoveinlets").has_meta("inlet_count"):
+					node_data["addremoveinlets"]["inlet_count"] = node.get_node("addremoveinlets").get_meta("inlet_count")
+					
 			# Save notes from CodeEdit children
 			# Save notes from CodeEdit children
 			for child in node.find_children("*", "CodeEdit", true, false):
 			for child in node.find_children("*", "CodeEdit", true, false):
 				node_data["notes"][child.name] = child.text
 				node_data["notes"][child.name] = child.text
@@ -191,6 +197,15 @@ func load_graph_edit(path: String):
 				if optionbutton and (optionbutton is OptionButton):
 				if optionbutton and (optionbutton is OptionButton):
 					optionbutton.selected = node_data["optionbutton_values"][optionbutton_name]
 					optionbutton.selected = node_data["optionbutton_values"][optionbutton_name]
 
 
+		#restore dynamic inlets
+		if node_data.has("addremoveinlets") and new_node.has_node("addremoveinlets"):
+			print("restoring inlets")
+			var addremoveinlets = new_node.get_node("addremoveinlets")
+			addremoveinlets.set_meta("inlet_count", node_data["addremoveinlets"]["inlet_count"])
+			await get_tree().process_frame
+			addremoveinlets.restore_inlets()
+		
+		
 		register_input.call(new_node)
 		register_input.call(new_node)
 
 
 	# Recreate connections
 	# Recreate connections