diff --git a/behaviours/sampler.gd b/behaviours/sampler.gd index 5ce7ce7..fb9ba27 100644 --- a/behaviours/sampler.gd +++ b/behaviours/sampler.gd @@ -9,17 +9,13 @@ class_name Sampler ## [Array] of [Node]s that can be [func sample]d by this [Sampler]. @export var possibilities: Array[Node] = [] -## If true, the [Sampler] will attempt to automatically detect the [field possibilities] on NOTIFICATION_READY. -@export var autodetect_possibilities_on_ready: bool = true +## If true, the [Sampler] will attempt to automatically [method sample_and_enable] on NOTIFICATION_READY. +@export var autoenable_on_ready: bool = true var selected: Node = null; -## Update [field possibilities] with the most likely subset of nodes. -func autodetect_possibilities(): - possibilities = get_children() - ## Get a reference. func sample() -> Node: Log.e(self, "Not implemented.") @@ -48,5 +44,5 @@ func get_all_refs() -> Array[Node]: func _ready() -> void: - if autodetect_possibilities_on_ready: - autodetect_possibilities() + if autoenable_on_ready: + sample_and_enable.call_deferred() diff --git a/behaviours/sampler_priority.gd b/behaviours/sampler_priority.gd index 5ea3e95..1f32196 100644 --- a/behaviours/sampler_priority.gd +++ b/behaviours/sampler_priority.gd @@ -2,13 +2,16 @@ extends Sampler class_name SamplerPriority +## If true, the [Sampler] will attempt to automatically detect the [field possibilities] on NOTIFICATION_READY. +@export var autodetect_possibilities_on_ready: bool = true + ## If true, the [SamplerPriority] will attempt to automatically setup the recommended signals for all the [field possibilities] on NOTIFICATION_READY. @export var autosetup_signals_on_ready: bool = true ## Update [field possibilities] with the most likely subset of nodes. func autodetect_possibilities() -> void: - possibilities = find_children("*", "Priority", true, false) + possibilities = get_parent().find_children("*", "Priority", true, false) ## Setup the recommended signals for each node in [field possibilities]. func autosetup_signals() -> void: @@ -41,11 +44,14 @@ func get_ref(node: Node) -> Node: return node.get_ref() -func _ready(): +func _ready() -> void: + super._ready() + if autodetect_possibilities_on_ready: + autodetect_possibilities() if autosetup_signals_on_ready: autosetup_signals() -func _autosetup_on_possibility_priority_changed(node: Priority, new: int, old: int): +func _autosetup_on_possibility_priority_changed(new: int, old: int, node: Priority): if node == selected: if new < old: sample_and_enable() diff --git a/entities/imp.tscn b/entities/imp.tscn index d761f73..161275e 100644 --- a/entities/imp.tscn +++ b/entities/imp.tscn @@ -120,7 +120,6 @@ debug_color = Color(1, 0, 0, 0) stream = ExtResource("19_7la6c") [connection signal="timeout" from="GoldSpawner/TimerStddev" to="GoldSpawner" method="spawn"] -[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"] [connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="priority_conditional"] [connection signal="move" from="MovementWander" to="." method="_on_move"] [connection signal="timeout" from="MovementWander/ChangeDirectionTimer" to="MovementWander" method="randomize_direction"] diff --git a/entities/sheep.tscn b/entities/sheep.tscn index c0cb53c..e4795f2 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -183,7 +183,6 @@ stream = ExtResource("16_nswfl") [node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag"] stream = ExtResource("17_8kst2") -[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"] [connection signal="move" from="MovementIdle" to="." method="_on_move"] [connection signal="move_disabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="stop"] [connection signal="move_enabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="start"]