1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +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].
@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
return possibilities
func _ready() -> void:
if autodetect_possibilities_on_ready:
autodetect_possibilities()

View file

@ -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()
return node.get_ref()