1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 16:14:22 +00:00

Add autodetect_possibilities option to Sampler

This commit is contained in:
Steffo 2024-04-23 09:16:09 +02:00
parent 5a28feb2ca
commit 73c4cce99c
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 20 additions and 2 deletions

View file

@ -9,9 +9,17 @@ class_name Sampler
## [Array] of [Node]s that can be [func sample]d by this [Sampler]. ## [Array] of [Node]s that can be [func sample]d by this [Sampler].
@export var possibilities: Array[Node] = [] @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; var selected: Node = null;
## Update [field possibilities] with the most likely subset of nodes.
func autodetect_possibilities():
possibilities = get_children()
## Get a reference. ## Get a reference.
func sample() -> Node: func sample() -> Node:
Log.e(self, "Not implemented.") Log.e(self, "Not implemented.")
@ -37,3 +45,8 @@ func get_ref(node: Node) -> Node:
## Useful as it may be overridden by some other [Sampler]s, such as [SamplerPriority]. ## Useful as it may be overridden by some other [Sampler]s, such as [SamplerPriority].
func get_all_refs() -> Array[Node]: func get_all_refs() -> Array[Node]:
return possibilities return possibilities
func _ready() -> void:
if autodetect_possibilities_on_ready:
autodetect_possibilities()

View file

@ -9,6 +9,11 @@ func _ready():
for possibility in possibilities: for possibility in possibilities:
possibility.link(self) 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. ## Get a reference.
func sample() -> Priority: func sample() -> Priority:
if len(possibilities) == 0: if len(possibilities) == 0: