2024-04-16 03:08:25 +00:00
|
|
|
extends Sampler
|
|
|
|
class_name SamplerPriority
|
|
|
|
|
|
|
|
|
|
|
|
## Always sample the object with the highest priority in the queue.
|
2024-04-22 22:13:54 +00:00
|
|
|
var selected_priority = 0;
|
2024-04-16 03:08:25 +00:00
|
|
|
|
2024-04-22 22:13:54 +00:00
|
|
|
func _ready():
|
|
|
|
for possibility in possibilities:
|
|
|
|
possibility.link(self)
|
2024-04-16 03:08:25 +00:00
|
|
|
|
2024-04-16 22:55:17 +00:00
|
|
|
## Get a reference.
|
|
|
|
func sample() -> Priority:
|
|
|
|
if len(possibilities) == 0:
|
|
|
|
return null
|
|
|
|
|
|
|
|
# FIXME: Change this to something more efficient when needed
|
|
|
|
var highest_possibility: Priority = null
|
|
|
|
for possibility in possibilities:
|
2024-04-17 02:52:11 +00:00
|
|
|
if highest_possibility == null or possibility.priority > highest_possibility.priority:
|
2024-04-16 22:55:17 +00:00
|
|
|
highest_possibility = possibility
|
|
|
|
|
|
|
|
if highest_possibility == null:
|
|
|
|
return null
|
|
|
|
|
2024-04-22 22:13:54 +00:00
|
|
|
selected_priority = highest_possibility.priority
|
|
|
|
|
|
|
|
return highest_possibility
|
|
|
|
|
|
|
|
func on_priority_changed(node: Node):
|
|
|
|
if node == selected:
|
|
|
|
if node.priority > selected_priority:
|
|
|
|
selected_priority = node.priority
|
|
|
|
else:
|
|
|
|
sample_and_enable()
|
|
|
|
else:
|
|
|
|
if selected == null or node.priority > selected.priority:
|
|
|
|
set_enabled(node)
|
2024-04-17 02:52:11 +00:00
|
|
|
|
2024-04-18 23:26:02 +00:00
|
|
|
func get_all_refs() -> Array[Node]:
|
2024-04-17 02:52:11 +00:00
|
|
|
var refs: Array[Node] = []
|
|
|
|
for possibility in possibilities:
|
|
|
|
refs.append(possibility.get_ref())
|
|
|
|
return refs
|
2024-04-22 22:13:54 +00:00
|
|
|
|
|
|
|
func get_ref(node: Node) -> Node:
|
|
|
|
return node.get_ref()
|