mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-25 01:24:23 +00:00
Add autodetect_possibilities
option to Sampler
This commit is contained in:
parent
5a28feb2ca
commit
73c4cce99c
2 changed files with 20 additions and 2 deletions
|
@ -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.")
|
||||||
|
@ -36,4 +44,9 @@ 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()
|
||||||
|
|
|
@ -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:
|
||||||
|
@ -44,4 +49,4 @@ func get_all_refs() -> Array[Node]:
|
||||||
return refs
|
return refs
|
||||||
|
|
||||||
func get_ref(node: Node) -> Node:
|
func get_ref(node: Node) -> Node:
|
||||||
return node.get_ref()
|
return node.get_ref()
|
||||||
|
|
Loading…
Reference in a new issue