Repository: BenjaTK/gaea
Pull request #4: Update reroute node
Author: login: Zehir
Created: 2025-04-24T18:55:52Z | Merged: 2025-04-25T23:28:35Z



Diff:
diff --git a/addons/gaea/editor/panel.gd b/addons/gaea/editor/panel.gd
index 202dec9f6..c9b14577a 100644
--- a/addons/gaea/editor/panel.gd
+++ b/addons/gaea/editor/panel.gd
@@ -2,7 +2,6 @@
 extends Control
 
 const _LinkPopup = preload("uid://btt4eqjkp5pyf")
-const _RerouteNode = preload("uid://bs40iof8ipbkq")
 
 var _selected_generator: GaeaGenerator = null: get = get_selected_generator
 var _output_node: GaeaGraphNode
@@ -360,15 +359,14 @@ func _on_tree_special_node_selected_for_creation(id: StringName) -> void:
 
 
 func _on_new_reroute_requested(connection: Dictionary) -> void:
-	var reroute: _RerouteNode = _add_node_from_resource(preload("uid://kdn03ei2yp6e"))
+	var reroute: GaeaGraphNode = _add_node_from_resource(GaeaNodeReroute.new())
 
 	var offset = - reroute.get_output_port_position(0)
 	offset.y -= reroute.get_slot_custom_icon_right(0).get_size().y * 0.5
 	reroute.set_position_offset(_graph_edit.local_to_grid(_node_creation_target, offset))
 
 	var from_node: GraphNode = _graph_edit.get_node(NodePath(connection.from_node))
-	var link_type := from_node.get_output_port_type(connection.from_port) as GaeaValue.Type
-	reroute.type = link_type
+	reroute.resource.type = from_node.get_output_port_type(connection.from_port) as GaeaValue.Type
 
 	_graph_edit.disconnection_request.emit.call_deferred(
 		connection.from_node, connection.from_port,
diff --git a/addons/gaea/graph/nodes/reroute_node.gd b/addons/gaea/graph/nodes/reroute_node.gd
index be123e03e..a48564f83 100644
--- a/addons/gaea/graph/nodes/reroute_node.gd
+++ b/addons/gaea/graph/nodes/reroute_node.gd
@@ -1,16 +1,8 @@
 @tool
 extends GaeaGraphNode
 
-const _RerouteResource = preload("uid://bgqqucap4kua4")
 
 var tween: Tween
-var type: GaeaValue.Type = GaeaValue.Type.FLOAT:
-	set(new_value):
-		if type != new_value:
-			type = new_value
-			if not is_part_of_edited_scene():
-				resource.title = "Reroute (%s)" % GaeaValue.Type.find_key(new_value).capitalize()
-			_update_slots()
 
 var icon_opacity: float = 0.0:
 	set(new_value):
@@ -28,6 +20,7 @@ func _on_added() -> void:
 		return
 
 	resource.node = self
+	resource.argument_list_changed.connect(on_type_changed)
 
 	connections_updated.connect(_validate_connections)
 
@@ -40,20 +33,30 @@ func _on_added() -> void:
 	titlebar_hbox.mouse_entered.connect(_set_icon_opacity.bind(1.0))
 	titlebar_hbox.mouse_exited.connect(_set_icon_opacity.bind(0.0))
 
-	_update_slots()
 	_validate_connections()
+	
+	on_type_changed()
+
+
+func get_save_data() -> Dictionary:
+	var data = super()
+	data.set("type", resource.get_type())
+	return data
+
+
+func load_save_data(saved_data: Dictionary) -> void:
+	if saved_data.has("type"):
+		resource.type = saved_data.get("type")
+	super(saved_data)
 
 
-func _update_slots():
+func on_type_changed():
+	var type = resource.get_type()
 	var color = GaeaValue.get_color(type)
 	set_slot(0, true, type, color, true, type, color)
 	set_slot_type_left(0, type)
 	set_slot_type_right(0, type)
 	set_slot_custom_icon_right(0, GaeaValue.get_slot_icon(type))
-	if not is_part_of_edited_scene():
-		resource.params[0].type = type
-		resource.outputs[0].type = type
-		resource.title = "Reroute (%s)" % GaeaValue.Type.find_key(type).capitalize()
 #endregion
 
 
@@ -89,25 +92,6 @@ func _on_removed() -> void:
 #endregion
 
 
-#region Save/Load
-func get_save_data() -> Dictionary:
-	var data = super()
-	if data.has("salt"):
-		data.erase("salt")
-	data.type = type
-	return data
-
-
-func load_save_data(data: Dictionary) -> void:
-	# Data migration from 2.0 beta. See PR #310. Remove before releasing 2.X.
-	if data.has(&"salt"):
-		data.set(&"type", GaeaValue.from_old_slot_type(data.get(&"type")))
-	if data.has(&"type"):
-		type = data.type
-	super(data)
-#endregion
-
-
 #region Display
 func _draw_port(slot_index: int, pos: Vector2i, left: bool, color: Color) -> void:
 	if left:
diff --git a/addons/gaea/graph/nodes/reroute_node_resource.gd b/addons/gaea/graph/nodes/reroute_node_resource.gd
index 245ea2a7e..5260330dc 100644
--- a/addons/gaea/graph/nodes/reroute_node_resource.gd
+++ b/addons/gaea/graph/nodes/reroute_node_resource.gd
@@ -6,22 +6,54 @@ class_name GaeaNodeReroute
 ## Can be placed by pressing [kbd]Right Click[/kbd] in a connection wire and selecting the option,
 ## and it'll automatically adapt to the type of the selected wire.
 
+var type: GaeaValue.Type = GaeaValue.Type.NULL:
+	set(new_value):
+		type = new_value
+		notify_argument_list_changed()
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
 
+func _get_title() -> String:
+	return "Reroute"
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Arguments
+func _get_arguments_list() -> Array[StringName]:
+	return [&"value"]
+
+
+@warning_ignore("unused_parameter")
+func _get_argument_type(arg_name: StringName) -> GaeaValue.Type:
+	return type
+#endregion
+
+
+#region Outputs
+func _get_output_ports_list() -> Array[StringName]:
+	return _get_arguments_list()
+
+
+@warning_ignore("unused_parameter")
+func _get_output_port_type(output_name: StringName) -> GaeaValue.Type:
+	return type
+#endregion
 
 
 func _get_scene() -> PackedScene:
 	return preload("uid://b2rceqo8rtr88")
 
 
-func _instantiate_duplicate() -> GaeaNodeResource:
-	var new_resource = super()
-	for input_slot_idx in new_resource.params.size():
-		new_resource.params[input_slot_idx] = new_resource.params[input_slot_idx].duplicate()
-		new_resource.outputs[input_slot_idx] = new_resource.outputs[input_slot_idx].duplicate()
-	return new_resource
+func _get_data(output_port: StringName, area: AABB, generator_data: GaeaData) -> Variant:
+	return _get_arg(output_port, area, generator_data)
+
+
+func _use_caching(_output_port: StringName, _generator_data:GaeaData) -> bool:
+	return false
+
+
+func _load_save_data(saved_data: Dictionary) -> void:
+	type = saved_data.get("type", GaeaValue.Type.NULL)
+	super(saved_data)
diff --git a/addons/gaea/graph/nodes/reroute_node_resource.tres b/addons/gaea/graph/nodes/reroute_node_resource.tres
deleted file mode 100644
index 76d43a86a..000000000
--- a/addons/gaea/graph/nodes/reroute_node_resource.tres
+++ /dev/null
@@ -1,28 +0,0 @@
-[gd_resource type="Resource" script_class="GaeaNodeReroute" load_steps=6 format=3 uid="uid://kdn03ei2yp6e"]
-
-[ext_resource type="Script" uid="uid://dil6xg31ctqdu" path="res://addons/gaea/graph/nodes/node_slot_output.gd" id="3_i7rb4"]
-[ext_resource type="Script" uid="uid://bgqqucap4kua4" path="res://addons/gaea/graph/nodes/reroute_node_resource.gd" id="3_ufwtk"]
-[ext_resource type="Script" uid="uid://b5mukn8hdt8ww" path="res://addons/gaea/graph/nodes/node_slot_param.gd" id="4_ff6uq"]
-
-[sub_resource type="Resource" id="Resource_63img"]
-resource_name = "Value (Float)"
-script = ExtResource("3_i7rb4")
-name = &"value"
-type = 3
-metadata/_custom_type_script = "uid://dil6xg31ctqdu"
-
-[sub_resource type="Resource" id="Resource_1jyr0"]
-resource_name = "Value (Float)"
-script = ExtResource("4_ff6uq")
-name = &"value"
-type = 3
-hint = Dictionary[String, Variant]({})
-default_value = 0.0
-metadata/_custom_type_script = "uid://b5mukn8hdt8ww"
-
-[resource]
-script = ExtResource("3_ufwtk")
-params = [SubResource("Resource_1jyr0")]
-outputs = [SubResource("Resource_63img")]
-title = "New Reroute"
-description = ""


Reviews:
user: login: BenjaTK
body: On `load_save_data` in `GaeaNodeResource` add a check when doing:
```
for enum_idx: int in saved_data.get("enums").size():
			_enum_editors[enum_idx].select(saved_data.get("enums")[enum_idx])
```
because the reroute node doesn't have any enum editors. Or alternatively, override that function in the reroute node script
state: CHANGES_REQUESTED
author_association: OWNER
submitted_at: 2025-04-24T20:52:10Z
user: login: Zehir
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-25T06:20:37Z
user: login: Zehir
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-25T06:21:03Z
user: login: Zehir
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-25T06:21:10Z
user: login: BenjaTK
body: LGTM, will merge
state: APPROVED
author_association: OWNER
submitted_at: 2025-04-25T23:27:55Z

Review comments:
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
+	return super(enum_idx, option_value).replace(" ", "")
+
+
+func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void:
+	prints("_on_enum_value_changed", _enum_idx, _option_value)
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: BenjaTK
body: This print should be removed
created_at: 2025-04-24T20:47:38Z
author_association: OWNER
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
+	return super(enum_idx, option_value).replace(" ", "")
+
+
+func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void:
+	prints("_on_enum_value_changed", _enum_idx, _option_value)
+	notify_argument_list_changed()
+	notify_property_list_changed()
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: BenjaTK
body: This method call also
created_at: 2025-04-24T20:47:45Z
author_association: OWNER
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: BenjaTK
body: Do we need this if the enum doesn't show up?
created_at: 2025-04-24T20:47:57Z
author_association: OWNER
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: Zehir
body: No we dont, I removed it
created_at: 2025-04-25T06:20:37Z
author_association: NONE
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
+	return super(enum_idx, option_value).replace(" ", "")
+
+
+func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void:
+	prints("_on_enum_value_changed", _enum_idx, _option_value)
+	notify_argument_list_changed()
+	notify_property_list_changed()
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: Zehir
body: Updated
created_at: 2025-04-25T06:21:03Z
author_association: NONE
diff_hunk: @@ -7,21 +7,87 @@ class_name GaeaNodeReroute
 ## and it'll automatically adapt to the type of the selected wire.
 
 
-func _get_data(output_port: GaeaNodeSlotOutput, area: AABB, generator_data: GaeaData) -> Dictionary:
-	return output_port.return_value(_get_arg(&"value", area, generator_data))
+enum EnumList {
+	RerouteType
+}
 
 
-func _use_caching(_output_port: GaeaNodeSlotOutput, _generator_data:GaeaData) -> bool:
-	return false
+func _get_title() -> String:
+	return "Reroute"
+
+
+func _get_description() -> String:
+	return "Allows rerouting a connection within the Gaea graph."
+
+
+#region Enum
+func _get_enums_count() -> int:
+	return EnumList.size()
+
+
+func _get_enum_options(enum_idx: int) -> Dictionary:
+	match enum_idx:
+		EnumList.RerouteType:
+			var list = {}
+			for type_name in GaeaValue.Type:
+				if GaeaValue.is_wireable(GaeaValue.Type[type_name]):
+					list.set(type_name, GaeaValue.Type[type_name])
+			return list
+	return {}
+
+
+func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String:
+	return super(enum_idx, option_value).replace(" ", "")
+
+
+func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void:
+	prints("_on_enum_value_changed", _enum_idx, _option_value)
path: addons/gaea/graph/nodes/reroute_node_resource.gd
user: login: Zehir
body: Removed
created_at: 2025-04-25T06:21:10Z
author_association: NONE

PR comments:
user: login: Zehir
created_at: 2025-04-25T06:31:14Z
body: Just need to fix the loading but don't have time rn, will handle it later today (like in 10h not before)
author_association: NONE
user: login: Zehir
created_at: 2025-04-25T11:28:11Z
body: I removed the enum and just made a type property, ready for review
author_association: NONE