2024-04-16 22:55:17 +00:00
|
|
|
@icon("res://behaviours/sampler.svg")
|
2024-04-16 03:08:25 +00:00
|
|
|
extends Node
|
|
|
|
class_name Sampler
|
|
|
|
|
|
|
|
|
|
|
|
## Abstract base class for sampling a certain reference among multiple.
|
|
|
|
|
|
|
|
|
2024-04-18 23:26:02 +00:00
|
|
|
## [Array] of [Node]s that can be [func sample]d by this [Sampler].
|
2024-04-17 02:52:11 +00:00
|
|
|
@export var possibilities: Array[Node] = []
|
|
|
|
|
|
|
|
|
2024-04-16 03:08:25 +00:00
|
|
|
## Get a reference.
|
2024-04-17 02:52:11 +00:00
|
|
|
func sample() -> Node:
|
2024-04-16 03:08:25 +00:00
|
|
|
Log.e(self, "Not implemented.")
|
|
|
|
return null
|
2024-04-17 02:52:11 +00:00
|
|
|
|
2024-04-18 23:26:02 +00:00
|
|
|
## Set the [field enabled] property to true on a [method sample]d node, and to false on all others.
|
2024-04-17 02:52:11 +00:00
|
|
|
func enable() -> void:
|
|
|
|
var selected = sample()
|
2024-04-18 23:26:02 +00:00
|
|
|
for possibility in get_all_refs():
|
2024-04-17 02:52:11 +00:00
|
|
|
possibility.enabled = (selected == possibility)
|
2024-04-18 23:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Get all possible nodes referenced by [field possibilities].
|
|
|
|
##
|
|
|
|
## Useful as it may be overridden by some other [Sampler]s, such as [SamplerPriority].
|
|
|
|
func get_all_refs() -> Array[Node]:
|
|
|
|
return possibilities
|