diff --git a/behaviours/sampler.gd b/behaviours/sampler.gd index bf26ace..5ce7ce7 100644 --- a/behaviours/sampler.gd +++ b/behaviours/sampler.gd @@ -9,9 +9,17 @@ 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 + + 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.") @@ -36,4 +44,9 @@ func get_ref(node: Node) -> Node: ## ## Useful as it may be overridden by some other [Sampler]s, such as [SamplerPriority]. func get_all_refs() -> Array[Node]: - return possibilities \ No newline at end of file + return possibilities + + +func _ready() -> void: + if autodetect_possibilities_on_ready: + autodetect_possibilities() diff --git a/behaviours/sampler_priority.gd b/behaviours/sampler_priority.gd index b5a9487..5221fa3 100644 --- a/behaviours/sampler_priority.gd +++ b/behaviours/sampler_priority.gd @@ -9,6 +9,11 @@ func _ready(): for possibility in possibilities: possibility.link(self) + +## Update [field possibilities] with the most likely subset of nodes. +func autodetect_possibilities(): + possibilities = find_children("*", "Priority", true, false) + ## Get a reference. func sample() -> Priority: if len(possibilities) == 0: @@ -44,4 +49,4 @@ func get_all_refs() -> Array[Node]: return refs func get_ref(node: Node) -> Node: - return node.get_ref() \ No newline at end of file + return node.get_ref()