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:
parent
564477e5e9
commit
32e00ede01
2 changed files with 11 additions and 11 deletions
|
@ -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
|
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue