Skip to content

Commit a9bcb2c

Browse files
committed
Add a graph property to GaeaNodeResource and remove the old reference passed around in the methods.
1 parent b69a28f commit a9bcb2c

File tree

35 files changed

+163
-175
lines changed

35 files changed

+163
-175
lines changed

addons/gaea/graph/components/preview_texture.gd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ func update() -> void:
8787
generation_settings.seed = graph.preview_seed
8888

8989
var pouch: GaeaGenerationPouch = GaeaGenerationPouch.new(generation_settings, AABB(Vector3.ZERO, sim_size))
90-
var data: GaeaValue.GridType = node.resource.traverse(
91-
selected_output,
92-
node.graph_edit.graph,
93-
pouch
94-
).get("value")
90+
var data: GaeaValue.GridType = node.resource.traverse(selected_output, pouch).get("value")
9591
pouch.clear_all_cache()
9692

9793

addons/gaea/graph/graph_nodes/generic_classes/constant.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ func _get_overridden_output_port_idx(_output_name: StringName) -> int:
3131
return 0
3232

3333

34-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
35-
return _get_arg(&"value", graph, pouch)
34+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> Variant:
35+
return _get_arg(&"value", pouch)

addons/gaea/graph/graph_nodes/generic_classes/number_operation.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ func _get_output_port_display_name(_output_name: StringName) -> String:
130130
return operation_definitions[get_enum_selection(0)].output
131131

132132

133-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
133+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> Variant:
134134
var operation: Operation = get_enum_selection(0) as Operation
135135
var args: Array
136136
for arg_name: StringName in operation_definitions[operation].args:
137-
args.append(_get_arg(arg_name, graph, pouch))
137+
args.append(_get_arg(arg_name, pouch))
138138
return _get_new_value(operation, args)
139139

140140

addons/gaea/graph/graph_nodes/generic_classes/parameter.gd

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var hint_string: String:
1919
get = _get_property_hint_string
2020

2121

22-
func _on_added_to_graph(graph: GaeaGraph) -> void:
22+
func _on_added_to_graph() -> void:
2323
var name := _get_available_name(graph.get_node_argument(id, &"name", _get_title()))
2424
graph.set_node_argument(
2525
id, &"name", name
@@ -35,7 +35,7 @@ func _on_added_to_graph(graph: GaeaGraph) -> void:
3535
})
3636

3737

38-
func _on_removed_from_graph(graph: GaeaGraph) -> void:
38+
func _on_removed_from_graph() -> void:
3939
graph.remove_parameter(graph.get_node_argument(id, &"name"))
4040
graph.notify_property_list_changed()
4141

@@ -69,10 +69,6 @@ func _get_argument_default_value(_arg_name: StringName) -> Variant:
6969

7070

7171
func _get_available_name(from: String) -> String:
72-
if not is_instance_valid(node) or not node is GaeaGraphNode:
73-
return from
74-
var graph: GaeaGraph = (node as GaeaGraphNode).graph_edit.graph
75-
7672
from = from.rstrip("1234567890")
7773
var available_name: String = from
7874
var suffix: int = 1
@@ -96,8 +92,8 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type:
9692
)
9793

9894

99-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
100-
return graph.get_parameter(_get_arg(&"name", graph, pouch))
95+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> Variant:
96+
return graph.get_parameter(_get_arg(&"name", pouch))
10197

10298

10399
func _is_available() -> bool:

addons/gaea/graph/graph_nodes/generic_classes/set_operation.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void:
9090

9191

9292
# The generic Dictionary type here is expected, and the type will be updated in child classes.
93-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> GaeaValue.GridType:
93+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> GaeaValue.GridType:
9494
var grids: Array[GaeaValue.GridType] = []
9595
for arg in _get_arguments_list():
96-
var arg_grid: GaeaValue.GridType = _get_arg(arg, graph, pouch)
96+
var arg_grid: GaeaValue.GridType = _get_arg(arg, pouch)
9797
if not arg_grid.is_empty():
9898
grids.append(arg_grid)
9999

addons/gaea/graph/graph_nodes/node_resource.gd

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ var connections: Array[Dictionary]
6060
## The related [GaeaGraphNode] for editing in the Gaea graph editor.
6161
## This is null during runtime.
6262
var node: GaeaGraphNode
63+
## The related [GaeaGraph] that holds this node.
64+
var graph: GaeaGraph
6365
## A Dictionary holding the values of the arguments
6466
## where the keys are their names.
6567
var arguments: Dictionary
@@ -107,22 +109,22 @@ static func is_valid_node_resource(uid_path: String) -> String:
107109

108110

109111
## Public version of [method _on_added_to_graph].
110-
func on_added_to_graph(graph: GaeaGraph) -> void:
111-
_on_added_to_graph(graph)
112+
func on_added_to_graph() -> void:
113+
_on_added_to_graph()
112114

113115

114-
## Called when the node is added to [param graph], by [method GaeaGraph.add_node].
115-
func _on_added_to_graph(_graph: GaeaGraph) -> void:
116+
## Called when the node is added to [member graph], by [method GaeaGraph.add_node].
117+
func _on_added_to_graph() -> void:
116118
pass
117119

118120

119121
## Public version of [method _on_removed_from_graph].
120-
func on_removed_from_graph(graph: GaeaGraph) -> void:
121-
_on_removed_from_graph(graph)
122+
func on_removed_from_graph() -> void:
123+
_on_removed_from_graph()
122124

123125

124-
## Called when the node is removed from [param graph], by [method GaeaGraph.remove_node].
125-
func _on_removed_from_graph(_graph: GaeaGraph) -> void:
126+
## Called when the node is removed from [member graph], by [method GaeaGraph.remove_node].
127+
func _on_removed_from_graph() -> void:
126128
pass
127129

128130

@@ -501,15 +503,15 @@ func _on_argument_value_changed(_arg_name: StringName, _new_value: Variant) -> v
501503
#region Args
502504
## Returns the value of the argument of [param name]. Pass in [param graph] to allow overriding with input slots.[br]
503505
## [param settings] is used for values of the type Data or Map. (See [enum GaeaValue.Type]).
504-
func _get_arg(arg_name: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
505-
_log_arg(arg_name, graph)
506+
func _get_arg(arg_name: StringName, pouch: GaeaGenerationPouch) -> Variant:
507+
_log_arg(arg_name)
506508

507509
var connection := _get_argument_connection(arg_name)
508510
if not connection.is_empty():
509511
var connected_id = connection.from_node
510512
var connected_node = graph.get_node(connected_id)
511513
var connected_output = connected_node.connection_idx_to_output(connection.from_port)
512-
var connected_data = connected_node.traverse(connected_output, graph, pouch)
514+
var connected_data = connected_node.traverse(connected_output, pouch)
513515
if connected_data.has("value"):
514516
var connected_value = connected_data.get("value")
515517
var connected_type: GaeaValue.Type = connected_node.get_output_port_type(
@@ -527,7 +529,6 @@ func _get_arg(arg_name: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch
527529

528530
_log_error(
529531
"Could not get data from previous node, using default value instead.",
530-
graph,
531532
connected_id
532533
)
533534
return get_argument_default_value(arg_name)
@@ -538,26 +539,26 @@ func _get_arg(arg_name: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch
538539

539540
#region Execution
540541
## Traverses the graph using this node's connections, and returns the result for [param output_port].
541-
func traverse(output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
542-
_log_traverse(graph)
542+
func traverse(output_port: StringName, pouch: GaeaGenerationPouch) -> Variant:
543+
_log_traverse()
543544

544545
# Cancellation
545546
if pouch.cancelled:
546547
return {}
547548

548549
# Validation
549-
if not _has_inputs_connected(_get_required_arguments(), graph):
550+
if not _has_inputs_connected(_get_required_arguments()):
550551
return {}
551552

552553
# Get Data with caching
553554
var data: Variant
554-
var use_caching = _use_caching(output_port, graph)
555+
var use_caching = _use_caching(output_port)
555556
if use_caching and pouch.has_cache(self, output_port):
556557
data = pouch.get_cache(self, output_port)
557558
else:
558559
_define_rng(pouch)
559-
_log_data(output_port, graph)
560-
data = _get_data(output_port, graph, pouch)
560+
_log_data(output_port)
561+
data = _get_data(output_port, pouch)
561562
if use_caching:
562563
pouch.set_cache(self, output_port, data)
563564

@@ -571,13 +572,13 @@ func traverse(output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPo
571572
## Returns the data corresponding to [param output_port]. Should be overridden to create custom
572573
## behavior for each node.
573574
@abstract
574-
func _get_data(output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant
575+
func _get_data(output_port: StringName, pouch: GaeaGenerationPouch) -> Variant
575576
#endregion
576577

577578

578579
#region Caching
579580
## Checks if this node should use caching or not. Can be overridden to disable it.
580-
func _use_caching(_output_port: StringName, _graph: GaeaGraph) -> bool:
581+
func _use_caching(_output_port: StringName) -> bool:
581582
return true
582583
#endregion
583584

@@ -590,15 +591,15 @@ func _get_required_arguments() -> Array[StringName]:
590591

591592

592593
# Returns [code]true[/code] if all [param required] inputs are connected.
593-
func _has_inputs_connected(required: Array[StringName], graph: GaeaGraph) -> bool:
594+
func _has_inputs_connected(required: Array[StringName]) -> bool:
594595
for idx in required:
595-
if _get_input_resource(idx, graph) == null:
596+
if _get_input_resource(idx) == null:
596597
return false
597598
return true
598599

599600

600601
# Gets the [GaeaNodeResource] connected to the input of name [param arg_name].
601-
func _get_input_resource(arg_name: StringName, graph: GaeaGraph) -> GaeaNodeResource:
602+
func _get_input_resource(arg_name: StringName) -> GaeaNodeResource:
602603
var connection = _get_argument_connection(arg_name)
603604
if connection.is_empty() or connection.from_node == -1:
604605
return null
@@ -659,45 +660,45 @@ func connection_idx_to_output(output_idx: int) -> StringName:
659660

660661
#region Logging
661662
# If enabled in [member GaeaGraph.logging], log the execution information. (See [enum GaeaGraph.Log]).
662-
func _log_execute(message: String, area: AABB, graph: GaeaGraph) -> void:
663+
func _log_execute(message: String, area: AABB) -> void:
663664
message = message.strip_edges()
664665
message = message if message == "" else message + " "
665666
graph.log(GaeaGraph.Log.EXECUTE, "%sArea %s on %s" % [message, area, _get_title()])
666667

667668
# If enabled in [member GaeaGraph.logging], log the time it took to generate. (See [enum GaeaGraph.Log]).
668-
func _log_time(message: String, time: int, graph: GaeaGraph) -> void:
669+
func _log_time(message: String, time: int) -> void:
669670
message = message.strip_edges()
670671
message = message if message == "" else message + " "
671672
graph.log(GaeaGraph.Log.EXECUTE, "%stook %sms. on %s" % [message, time, _get_title()])
672673

673674

674675
# If enabled in [member GaeaGraph.logging], log the layer information. (See [enum GaeaGraph.Log]).
675-
func _log_layer(message: String, layer: int, graph: GaeaGraph) -> void:
676+
func _log_layer(message: String, layer: int) -> void:
676677
message = message.strip_edges()
677678
message = message if message == "" else message + " "
678679
graph.log(GaeaGraph.Log.EXECUTE, "%sLayer %d on %s" % [message, layer, _get_title()])
679680

680681

681682
# If enabled in [member GaeaGraph.logging], log the traverse information. (See [enum GaeaGraph.Log]).
682-
func _log_traverse(graph: GaeaGraph) -> void:
683+
func _log_traverse() -> void:
683684
graph.log(GaeaGraph.Log.TRAVERSE, _get_title())
684685

685686

686687
## If enabled in [member GaeaGraph.logging], log the data information. (See [enum GaeaGraph.Log]).
687-
func _log_data(output_port: StringName, graph: GaeaGraph) -> void:
688+
func _log_data(output_port: StringName) -> void:
688689
graph.log(GaeaGraph.Log.DATA, "%s from port %s" % [_get_title(), output_port])
689690

690691

691692
# If enabled in [member GaeaGraph.logging], log the argument information. (See [enum GaeaGraph.Log]).
692-
func _log_arg(arg: String, graph: GaeaGraph) -> void:
693+
func _log_arg(arg: String) -> void:
693694
graph.log(GaeaGraph.Log.ARGUMENTS, "%s on %s" % [arg, _get_title()])
694695

695696

696697
## Display a error message in the Output log panel.
697698
## If a [param node_idx] is provided, it will display the path and position of the node.
698699
## Otherwise, it will display the path of the resource.
699700
## The [param node_idx] is the index of the node in the graph.resources array.
700-
func _log_error(message: String, graph: GaeaGraph, node_idx: int = -1) -> void:
701+
func _log_error(message: String, node_idx: int = -1) -> void:
701702
if node_idx >= 0:
702703
printerr("%s:%s in node '%s' - %s" % [
703704
graph.get_node(node_idx).resource_path,

addons/gaea/graph/graph_nodes/root/input/input.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func _get_type_of_input(input: InputVar) -> GaeaValue.Type:
8080
return GaeaValue.Type.NULL
8181

8282

83-
func _get_data(_output_port: StringName, _graph: GaeaGraph, pouch: GaeaGenerationPouch) -> Variant:
83+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> Variant:
8484
match get_enum_selection(0):
8585
InputVar.WORLD_SIZE:
8686
return pouch.settings.world_size

addons/gaea/graph/graph_nodes/root/map/mappers/mapper.gd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ func _get_required_arguments() -> Array[StringName]:
2525
return [&"reference", &"material"]
2626

2727

28-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
28+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
2929
var result: GaeaValue.Map = GaeaValue.Map.new()
30-
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", graph, pouch)
31-
var material := _get_arg(&"material", graph, pouch) as GaeaMaterial
30+
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", pouch)
31+
var material := _get_arg(&"material", pouch) as GaeaMaterial
3232

3333
if not is_instance_valid(material):
34-
_log_error("Invalid material provided", graph, graph.resources.find(self))
34+
_log_error("Invalid material provided", graph.resources.find(self))
3535
return result
3636

3737
var rng: RandomNumberGenerator = _get_rng(pouch)
3838

3939
material = material.prepare_sample(rng)
4040
if not is_instance_valid(material):
41-
material = _get_arg(&"material", graph, pouch)
41+
material = _get_arg(&"material", pouch)
4242
var error := (
4343
"Recursive limit reached (%d): Invalid material provided at %s"
4444
% [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path]
4545
)
46-
_log_error(error, graph, graph.resources.find(self))
46+
_log_error(error, graph.resources.find(self))
4747
return result
4848

4949
var args: Dictionary[StringName, Variant]
5050
for arg in get_arguments_list():
5151
if arg == &"reference" or arg == &"material":
5252
continue
53-
args.set(arg, _get_arg(arg, graph, pouch))
53+
args.set(arg, _get_arg(arg, pouch))
5454

5555
for cell in reference_sample.get_cells():
5656
if _passes_mapping(reference_sample, cell, args):

addons/gaea/graph/graph_nodes/root/map/placing/random_scatter.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ func _get_required_arguments() -> Array[StringName]:
3939
return [&"reference", &"material"]
4040

4141

42-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
43-
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", graph, pouch)
44-
var material: GaeaMaterial = _get_arg(&"material", graph, pouch)
42+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
43+
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", pouch)
44+
var material: GaeaMaterial = _get_arg(&"material", pouch)
4545

4646
var result: GaeaValue.Map = GaeaValue.Map.new()
4747
var cells_to_place_on: Array = reference_sample.get_cells()
4848
cells_to_place_on.shuffle()
49-
cells_to_place_on.resize(mini(_get_arg(&"amount", graph, pouch), cells_to_place_on.size()))
49+
cells_to_place_on.resize(mini(_get_arg(&"amount", pouch), cells_to_place_on.size()))
5050

5151
var rng: RandomNumberGenerator = _get_rng(pouch)
5252

5353
material = material.prepare_sample(rng)
5454
if not is_instance_valid(material):
55-
material = _get_arg(&"material", graph, pouch)
55+
material = _get_arg(&"material", pouch)
5656
var error := (
5757
"Recursive limit reached (%d): Invalid material provided at %s"
5858
% [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path]
5959
)
60-
_log_error(error, graph, graph.resources.find(self))
60+
_log_error(error, graph.resources.find(self))
6161
return result
6262

6363
for cell: Vector3i in cells_to_place_on:

addons/gaea/graph/graph_nodes/root/map/placing/rules_placer.gd

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,20 @@ func _get_required_arguments() -> Array[StringName]:
103103
return [&"reference", &"material"]
104104

105105

106-
func _get_data(_output_port: StringName, graph: GaeaGraph, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
107-
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", graph, pouch)
108-
var material: GaeaMaterial = _get_arg(&"material", graph, pouch)
106+
func _get_data(_output_port: StringName, pouch: GaeaGenerationPouch) -> GaeaValue.Map:
107+
var reference_sample: GaeaValue.Sample = _get_arg(&"reference", pouch)
108+
var material: GaeaMaterial = _get_arg(&"material", pouch)
109109
var result: GaeaValue.Map = GaeaValue.Map.new()
110110

111-
var rules: Dictionary = _get_arg(&"rules", graph, pouch)
111+
var rules: Dictionary = _get_arg(&"rules", pouch)
112112

113113
var rng: RandomNumberGenerator = _get_rng(pouch)
114114

115115
material = material.prepare_sample(rng)
116116
if not is_instance_valid(material):
117-
material = _get_arg(&"material", graph, pouch)
117+
material = _get_arg(&"material", pouch)
118118
_log_error(
119119
"Recursive limit reached (%d): Invalid material provided at %s" % [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path],
120-
graph,
121120
id
122121
)
123122
return result

0 commit comments

Comments
 (0)