1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00

Improve and cleanup Sampler and SamplerPriority

This commit is contained in:
Steffo 2024-04-19 01:26:02 +02:00
parent 564477e5e9
commit 32e00ede01
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 11 additions and 11 deletions

View file

@ -6,10 +6,7 @@ class_name Sampler
## Abstract base class for sampling a certain reference among multiple. ## Abstract base class for sampling a certain reference among multiple.
signal notify_selected(node: Node) ## [Array] of [Node]s that can be [func sample]d by this [Sampler].
signal notify_deselected(node: Node)
@export var possibilities: Array[Node] = [] @export var possibilities: Array[Node] = []
@ -18,12 +15,15 @@ func sample() -> Node:
Log.e(self, "Not implemented.") Log.e(self, "Not implemented.")
return null return null
## Get all possible nodes referenced by [field possibilities]. ## Set the [field enabled] property to true on a [method sample]d node, and to false on all others.
func get_refs() -> Array[Node]:
return possibilities
## Set the "enabled" property on
func enable() -> void: func enable() -> void:
var selected = sample() var selected = sample()
for possibility in get_refs(): for possibility in get_all_refs():
possibility.enabled = (selected == possibility) possibility.enabled = (selected == possibility)
## 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

View file

@ -23,7 +23,7 @@ func sample() -> Priority:
Log.p(self, "Sampled: %s (%d)" % [highest_possibility, highest_possibility.priority]) Log.p(self, "Sampled: %s (%d)" % [highest_possibility, highest_possibility.priority])
return highest_possibility.get_ref() return highest_possibility.get_ref()
func get_refs() -> Array[Node]: func get_all_refs() -> Array[Node]:
var refs: Array[Node] = [] var refs: Array[Node] = []
for possibility in possibilities: for possibility in possibilities:
refs.append(possibility.get_ref()) refs.append(possibility.get_ref())