Skip to content

Commit 2dc1ae6

Browse files
BenjaTKZehir
andauthored
Rework GaeaNodes to be configured from their script instead of .tres files (#344)
* Add new virtual methods * Separate old nodes * Start of moving SimplexSmooth to new sstem * it's working but i'ts not working * Output node working * Fix description * Add enums * Remove invalid connections * Fix loading connections * More stuff is working!! * Add Noise2D and Noise3D * Add variable nodes * Add class descriptions to variable nodes * Fix some of the reviewed stuff * Change `data` to `arguments` in `GaeaNodeResource` * Add enum overrides * Fix some calls and make tooltips change * Fix all editors * Add ability to merge outputs with arguments * Rename Variable to Parameter * Replace naming of params/parameters to arguments where appropiate * Change descriptions of parameter nodes * Vector nodes * Fix argument select * Fix bitmask editor * Add most data nodes back * Smooshed vector argument editor together * Update from_variant_type method * Add SetOp nodes * Update set_operation.gd * Fix some stuff with vector nodes * Fix ComposeVector and remove old set op nodes * Move FloorWalker to new system * Add `Data/Generation` nodes * Re-add hints to arguments * Add `GaeaNodeVectorBase` * Change how to override the slot idx for outputs * Fix typo * Add Input node * Allow adding icons to enums * Remove old nodes that have been replaced * Make the old_roots folder red as a reminder that it should be deleted * Add constant nodes * Remove all constant `.tres` files * Delete random_filter.tres * Add mappers * Add RulesPlacer * Add RandomScatter * Add FloatOp and IntOp Co-Authored-By: Zehir <845225+Zehir@users.noreply.github.com> * Update reroute node (#4) * Update reroute node * Cleanup * Fix reroute node * Organize scripts outside of `root/` * Rename `graph/nodes` to `graph/graph_nodes` for clarity * Add DataOp node * Add DatasOp * Remove old operation nodes * Add descriptions to all operation nodes * Add doc comment to NumOp and DatasOp * Add ComposeRange * Move output and reroute into `special/` * Add script templates * Add vector operation node (#11) * Add vector operation node * Add requested changes * Remove old scripts and rename a folder * Add migration from beta 3 (#10) * Add migration * Moved migration to an other file * Update migration for Vector operation node * Update migration for compose range * Migrate FloorWalker demo * Add warning when migrating * Clean up * Clean-up vector nodes * Cleanup resources (#12) --------- Co-authored-by: Zehir <zehir@zorim.fr> Co-authored-by: Zehir <845225+Zehir@users.noreply.github.com>
1 parent 29294d5 commit 2dc1ae6

File tree

310 files changed

+4509
-4594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+4509
-4594
lines changed

addons/gaea/assets/parameter_editor.svg.import renamed to addons/gaea/assets/argument_editor.svg.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
importer="texture"
44
type="CompressedTexture2D"
55
uid="uid://dox5e4tnafwet"
6-
path="res://.godot/imported/parameter_editor.svg-8a5814218dcd6dff896188e64ebe9abb.ctex"
6+
path="res://.godot/imported/argument_editor.svg-133fa3c24b8951fdee65446f91ec95b9.ctex"
77
metadata={
88
"has_editor_variant": true,
99
"vram_texture": false
1010
}
1111

1212
[deps]
1313

14-
source_file="res://addons/gaea/assets/parameter_editor.svg"
15-
dest_files=["res://.godot/imported/parameter_editor.svg-8a5814218dcd6dff896188e64ebe9abb.ctex"]
14+
source_file="res://addons/gaea/assets/argument_editor.svg"
15+
dest_files=["res://.godot/imported/argument_editor.svg-133fa3c24b8951fdee65446f91ec95b9.ctex"]
1616

1717
[params]
1818

addons/gaea/editor/create_node_tree.gd

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extends Tree
55
signal node_selected_for_creation(resource: GaeaNodeResource)
66
signal special_node_selected_for_creation(id: StringName)
77

8-
const NODES_FOLDER_PATH: String = "res://addons/gaea/graph/nodes/root/"
8+
const NODES_FOLDER_PATH: String = "res://addons/gaea/graph/graph_nodes/root/"
99

1010
@export var description_label: RichTextLabel
1111
var tree_dictionary: Dictionary
@@ -53,7 +53,7 @@ func _populate_from_dictionary(dictionary: Dictionary, parent_item: TreeItem) ->
5353
var value: Variant = dictionary.get(key)
5454
tree_item.set_metadata(0, value)
5555
if value is GaeaNodeResource:
56-
tree_item.set_text(0, value.title)
56+
tree_item.set_text(0, value.get_tree_name())
5757
tree_item.set_icon(0, GaeaValue.get_display_icon(value.get_type()))
5858
tree_item.set_icon_max_width(0, 16)
5959

@@ -67,24 +67,32 @@ func _populate_dict_with_files(folder_path: String, dict: Dictionary) -> Diction
6767

6868
dir.list_dir_begin()
6969
var file_name := dir.get_next()
70+
var idx: int = 0
7071
while file_name != "":
71-
if not dir.current_is_dir() and not file_name.ends_with(".tres"):
72+
if not dir.current_is_dir() and not file_name.ends_with(".gd"):
7273
file_name = dir.get_next()
7374
continue
7475

76+
idx += 1
77+
7578
var tree_name: String = file_name.get_basename().capitalize()
7679

7780
var file_path = folder_path + file_name
7881
if dir.current_is_dir():
7982
_populate_dict_with_files(file_path + "/", dict.get_or_add(tree_name, {}))
8083

81-
if file_name.ends_with(".tres"):
82-
var resource: Resource = load(file_path)
84+
85+
if file_name.ends_with(".gd"):
86+
var resource: GaeaNodeResource = load(file_path).new()
8387
if resource is GaeaNodeResource:
84-
tree_name = resource.title
85-
dict.get_or_add(file_name, resource)
88+
if resource.is_available():
89+
var sub_idx: int = 0
90+
for item in resource.get_tree_items():
91+
sub_idx += 1
92+
dict.get_or_add(item.get_tree_name() + str(idx) + str(sub_idx), item)
8693
file_name = dir.get_next()
8794

95+
dict.sort()
8896
return dict
8997

9098

@@ -105,7 +113,7 @@ func _on_create_button_pressed() -> void:
105113
func _on_item_selected() -> void:
106114
var item: TreeItem = get_selected()
107115
if item.get_metadata(0) is GaeaNodeResource:
108-
description_label.set_text(GaeaNodeResource.get_formatted_text(item.get_metadata(0).description))
116+
description_label.set_text(GaeaNodeResource.get_formatted_text(item.get_metadata(0).get_description()))
109117
elif item.get_metadata(0) is StringName:
110118
match item.get_metadata(0):
111119
&"frame": description_label.set_text("A rectangular area for better organziation.")

addons/gaea/editor/editor_settings.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const CONFIGURABLE_SLOT_COLORS := {
1515
GaeaValue.Type.INT: "int",
1616
GaeaValue.Type.FLOAT: "float",
1717
GaeaValue.Type.VECTOR2: "vector_2",
18+
GaeaValue.Type.VECTOR2I: "vector_2i",
1819
GaeaValue.Type.VECTOR3: "vector_3",
20+
GaeaValue.Type.VECTOR3I: "vector_3i",
1921
GaeaValue.Type.RANGE: "range",
2022
GaeaValue.Type.MATERIAL: "material",
2123
GaeaValue.Type.GRADIENT: "gradient",

addons/gaea/editor/graph_edit.gd

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func delete_nodes(nodes: Array[StringName]) -> void:
2626
for node_name in nodes:
2727
var node: GraphElement = get_node(NodePath(node_name))
2828
if node is GaeaGraphNode:
29-
if node.resource.is_output():
29+
if node.resource is GaeaNodeOutput:
3030
continue
3131
for connection in node.connections:
3232
disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port)
@@ -38,7 +38,7 @@ func delete_nodes(nodes: Array[StringName]) -> void:
3838
await node.tree_exited
3939

4040
connection_update_requested.emit()
41-
save_requested.emit()
41+
save_requested.emit.call_deferred()
4242

4343

4444
func _on_connection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void:
@@ -69,24 +69,31 @@ func _on_connection_request(from_node: StringName, from_port: int, to_node: Stri
6969
connect_node(from_node, from_port, to_node, to_port)
7070
connection_update_requested.emit()
7171

72-
get_node(NodePath(from_node)).notify_connections_updated.call_deferred()
73-
target_node.notify_connections_updated.call_deferred()
72+
if get_node(NodePath(from_node)).has_finished_loading():
73+
get_node(NodePath(from_node)).notify_connections_updated.call_deferred()
74+
75+
if target_node.has_finished_loading():
76+
target_node.notify_connections_updated.call_deferred()
7477

7578
save_requested.emit()
7679

80+
7781
func _on_disconnection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void:
7882
disconnect_node(from_node, from_port, to_node, to_port)
7983
connection_update_requested.emit()
8084

81-
get_node(NodePath(from_node)).notify_connections_updated.call_deferred()
82-
get_node(NodePath(to_node)).notify_connections_updated.call_deferred()
85+
if get_node(NodePath(from_node)).has_finished_loading():
86+
get_node(NodePath(from_node)).notify_connections_updated.call_deferred()
87+
if get_node(NodePath(to_node)).has_finished_loading():
88+
get_node(NodePath(to_node)).notify_connections_updated.call_deferred()
8389

8490
save_requested.emit()
8591

8692
func remove_invalid_connections() -> void:
8793
for connection in get_connection_list():
88-
var to_node: GraphNode = get_node(NodePath(connection.to_node))
89-
var from_node: GraphNode = get_node(NodePath(connection.from_node))
94+
var to_node: GaeaGraphNode = get_node(NodePath(connection.to_node))
95+
var from_node: GaeaGraphNode = get_node(NodePath(connection.from_node))
96+
9097

9198
if not is_instance_valid(from_node) or not is_instance_valid(to_node):
9299
disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port)
@@ -100,8 +107,17 @@ func remove_invalid_connections() -> void:
100107
disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port)
101108
continue
102109

110+
var from_type: GaeaValue.Type = from_node.get_output_port_type(connection.from_port)
111+
var to_type: GaeaValue.Type = to_node.get_input_port_type(connection.to_port)
112+
if not is_valid_connection_type(from_type, to_type) and from_type != to_type:
113+
disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port)
114+
to_node.notify_connections_updated.call_deferred()
115+
from_node.notify_connections_updated.call_deferred()
116+
continue
117+
103118
save_requested.emit()
104119

120+
105121
func is_nodes_connected_relatively(from_node: StringName, to_node: StringName) -> bool:
106122
var nodes_to_check: Array[StringName] = [from_node]
107123
while nodes_to_check.size() > 0:

addons/gaea/editor/node_popup.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func populate(selected: Array) -> void:
4848
if selected.front() is GaeaGraphNode and selected.size() == 1:
4949
var node: GaeaGraphNode = selected.front()
5050
var resource: GaeaNodeResource = node.resource
51-
if resource is GaeaNodeVariable:
51+
if resource is GaeaNodeParameter:
5252
var data: GaeaData = panel.get_selected_generator().data
5353
var parameter: Dictionary = data.parameters.get(node.get_arg_value("name"), {})
5454
if parameter.get("value") is Resource:
@@ -125,7 +125,7 @@ func _on_id_pressed(id: int) -> void:
125125
Action.OPEN_IN_INSPECTOR:
126126
var node: GaeaGraphNode = graph_edit.get_selected().front()
127127
var resource: GaeaNodeResource = node.resource
128-
if resource is GaeaNodeVariable:
128+
if resource is GaeaNodeParameter:
129129
var data: GaeaData = panel.get_selected_generator().data
130130
var parameter: Dictionary = data.parameters.get(node.get_arg_value("name"), {})
131131
var value: Variant = parameter.get("value")

addons/gaea/editor/panel.gd

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
extends Control
33

44
const _LinkPopup = preload("uid://btt4eqjkp5pyf")
5-
const _RerouteNode = preload("uid://bs40iof8ipbkq")
65

76
var _selected_generator: GaeaGenerator = null: get = get_selected_generator
87
var _output_node: GaeaGraphNode
@@ -154,11 +153,16 @@ func _save_data() -> void:
154153
var node_data: Array[Dictionary]
155154
var other: Dictionary
156155

156+
other.set(&"save_version", GaeaData.CURRENT_SAVE_VERSION)
157+
157158
var children = _graph_edit.get_children()
158159
children.sort_custom(func(a: Node, b: Node): return a.name.naturalcasecmp_to(b.name) < 0)
159160
for child in children:
160-
if child is GraphNode:
161-
resource_uids.append(child.resource.resource_uid)
161+
if child is GaeaGraphNode:
162+
163+
resource_uids.append(ResourceUID.id_to_text(
164+
ResourceLoader.get_resource_uid(child.resource.get_script().get_path())
165+
))
162166
resources.append(child.resource)
163167
elif child is GraphFrame:
164168
other.get_or_add(&"frames", []).append(_get_frame_save_data(child))
@@ -172,7 +176,7 @@ func _save_data() -> void:
172176

173177
for resource in resources:
174178
var save_data = resource.node.get_save_data()
175-
resource.data = save_data.get("data", {})
179+
resource.arguments = save_data.get("arguments", {})
176180
node_data.append(save_data)
177181

178182
_selected_generator.data.connections = connections
@@ -206,17 +210,13 @@ func _load_data() -> void:
206210
var saved_data = _selected_generator.data.node_data[idx]
207211
var node: GaeaGraphNode = _load_node(_selected_generator.data.resources[idx], saved_data)
208212

209-
if node.resource.is_output():
213+
if node.resource is GaeaNodeOutput:
210214
has_output_node = true
211215
_output_node = node
212216

213-
for child in _graph_edit.get_children():
214-
if child is GaeaGraphNode and child.resource.is_output():
215-
_output_node = child
216-
has_output_node = true
217217

218218
if not has_output_node:
219-
_output_node = _add_node_from_resource(preload("uid://bbkdvyxkj2slo"))
219+
_output_node = _add_node_from_resource(GaeaNodeOutput.new())
220220
_save_data.call_deferred()
221221

222222
# If scroll offset is saved, set it to that. Else, center the output node.
@@ -228,7 +228,14 @@ func _load_data() -> void:
228228
_load_attached_elements.bind(frame_data).call_deferred()
229229

230230
# from_node and to_node are indexes in the resources array
231-
for connection in _selected_generator.data.connections:
231+
_load_connections.call_deferred(_selected_generator.data.connections)
232+
233+
update_connections()
234+
is_loading = false
235+
236+
237+
func _load_connections(connections: Array[Dictionary]) -> void:
238+
for connection in connections:
232239
var from_node: GraphNode = _selected_generator.data.resources[connection.from_node].node
233240
var to_node: GraphNode = _selected_generator.data.resources[connection.to_node].node
234241
if not is_instance_valid(from_node) or not is_instance_valid(to_node):
@@ -237,9 +244,6 @@ func _load_data() -> void:
237244
continue
238245
_graph_edit.connection_request.emit(from_node.name, connection.from_port, to_node.name, connection.to_port)
239246

240-
update_connections()
241-
is_loading = false
242-
243247

244248
func _load_frame(frame_data: Dictionary) -> void:
245249
var new_frame: GraphFrame = GraphFrame.new()
@@ -314,10 +318,13 @@ func _clamp_popup_in_window(popup: Window, main_window: Window) -> void:
314318

315319
func _add_node_from_resource(resource: GaeaNodeResource, p_is_loading: bool = false) -> GraphNode:
316320
if not p_is_loading:
317-
resource = resource._instantiate_duplicate()
321+
resource = resource.duplicate()
318322
var node: GaeaGraphNode = resource.get_scene().instantiate()
323+
if resource.get_scene_script() != null:
324+
node.set_script(resource.get_scene_script())
319325
node.resource = resource
320326
node.generator = get_selected_generator()
327+
node.remove_invalid_connections_requested.connect(_graph_edit.remove_invalid_connections)
321328
_graph_edit.add_child(node)
322329
node.save_requested.connect(_save_data)
323330
node.name = node.name.replace("@", "_")
@@ -352,15 +359,14 @@ func _on_tree_special_node_selected_for_creation(id: StringName) -> void:
352359

353360

354361
func _on_new_reroute_requested(connection: Dictionary) -> void:
355-
var reroute: _RerouteNode = _add_node_from_resource(preload("uid://kdn03ei2yp6e"))
362+
var reroute: GaeaGraphNode = _add_node_from_resource(GaeaNodeReroute.new())
356363

357364
var offset = - reroute.get_output_port_position(0)
358365
offset.y -= reroute.get_slot_custom_icon_right(0).get_size().y * 0.5
359366
reroute.set_position_offset(_graph_edit.local_to_grid(_node_creation_target, offset))
360367

361368
var from_node: GraphNode = _graph_edit.get_node(NodePath(connection.from_node))
362-
var link_type := from_node.get_output_port_type(connection.from_port) as GaeaValue.Type
363-
reroute.type = link_type
369+
reroute.resource.type = from_node.get_output_port_type(connection.from_port) as GaeaValue.Type
364370

365371
_graph_edit.disconnection_request.emit.call_deferred(
366372
connection.from_node, connection.from_port,
@@ -457,7 +463,7 @@ func _on_reload_parameters_list_button_pressed() -> void:
457463
if node is not GaeaGraphNode:
458464
continue
459465

460-
if node.resource is GaeaNodeVariable:
466+
if node.resource is GaeaNodeParameter:
461467
existing_parameters.append(node.get_arg_value("name"))
462468

463469

addons/gaea/editor/panel.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ flat = true
148148
[node name="ReloadParametersListButton" type="Button" parent="Editor/VBoxContainer/HBoxContainer"]
149149
unique_name_in_owner = true
150150
layout_mode = 2
151-
tooltip_text = "Reload variables list.
152-
(Sometimes some variables aren't deleted properly, this helps remove those)"
151+
tooltip_text = "Reload parameters list.
152+
(Sometimes some parameters aren't deleted properly, this helps remove those)"
153153
icon = ExtResource("3_dhpru")
154154
flat = true
155155

addons/gaea/gaea.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func _enter_tree() -> void:
3434

3535

3636
func _exit_tree() -> void:
37-
await _panel.unpopulate()
37+
_panel.unpopulate()
3838
remove_inspector_plugin(_inspector_plugin)
3939
remove_control_from_bottom_panel(_container)
4040
_container.queue_free()

0 commit comments

Comments
 (0)