2024-04-16 22:55:17 +00:00
|
|
|
@icon("res://behaviours/priority.svg")
|
|
|
|
extends Node
|
|
|
|
class_name Priority
|
|
|
|
|
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Keeps track of the object's priority for [SamplerPriority] purposes.
|
2024-04-17 02:52:11 +00:00
|
|
|
|
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Emitted when the priority is changed.
|
2024-04-17 02:52:11 +00:00
|
|
|
signal priority_changed(new: int, old: int)
|
2024-04-18 23:22:03 +00:00
|
|
|
|
|
|
|
## Emitted when the priority is changed. No args are provided to work around a Godot bug.
|
2024-04-17 02:52:11 +00:00
|
|
|
signal priority_changed_no_args
|
|
|
|
|
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
@export var default_priority: int = 0
|
|
|
|
@export var alternative_priority: int = 1
|
|
|
|
|
2024-04-18 23:30:03 +00:00
|
|
|
var priority: int = 0:
|
|
|
|
get:
|
|
|
|
return priority
|
|
|
|
set(value):
|
|
|
|
var old = priority
|
|
|
|
priority = value
|
|
|
|
priority_changed.emit(priority, old)
|
2024-04-18 23:22:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Set [field priority] to [field default_priority].
|
2024-04-18 23:30:03 +00:00
|
|
|
func priority_default() -> void:
|
|
|
|
priority = default_priority
|
2024-04-16 22:55:17 +00:00
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Set [field priority] to [field alternative_priority]
|
2024-04-18 23:30:03 +00:00
|
|
|
func priority_alternative() -> void:
|
|
|
|
priority = alternative_priority
|
2024-04-16 22:55:17 +00:00
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Toggle [field priority] between [field default_priority] and [field alternative_priority].
|
2024-04-18 23:30:03 +00:00
|
|
|
func priority_toggle() -> void:
|
2024-04-18 23:22:03 +00:00
|
|
|
if priority == default_priority:
|
2024-04-18 23:30:03 +00:00
|
|
|
priority = alternative_priority
|
2024-04-18 23:22:03 +00:00
|
|
|
else:
|
2024-04-18 23:30:03 +00:00
|
|
|
priority = default_priority
|
2024-04-18 23:22:03 +00:00
|
|
|
|
|
|
|
## Set the [field priority] to a specific value.
|
2024-04-18 23:30:03 +00:00
|
|
|
func priority_set(value: int):
|
2024-04-17 02:52:11 +00:00
|
|
|
priority = value
|
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Set the [field priority] to a specific value if the [param variant] is truthy, otherwise set it to a different value.
|
2024-04-18 23:30:03 +00:00
|
|
|
##
|
|
|
|
## Defaults to using [field alternative_priority] for truthy, and [field default_priority] for falsy
|
|
|
|
func priority_conditional(variant: Variant, truthy: int = alternative_priority, falsy: int = default_priority):
|
2024-04-17 02:52:11 +00:00
|
|
|
if variant:
|
2024-04-18 23:30:03 +00:00
|
|
|
priority = truthy
|
2024-04-17 02:52:11 +00:00
|
|
|
else:
|
2024-04-18 23:30:03 +00:00
|
|
|
priority = falsy
|
2024-04-17 02:52:11 +00:00
|
|
|
|
2024-04-18 23:22:03 +00:00
|
|
|
## Get the node to which the [field priority] of this one applies to.
|
2024-04-16 22:55:17 +00:00
|
|
|
func get_ref() -> Node:
|
|
|
|
return get_parent()
|
2024-04-17 02:52:11 +00:00
|
|
|
|
2024-04-18 23:50:53 +00:00
|
|
|
## Log the current [field priority] value.
|
|
|
|
func log_priority() -> void:
|
|
|
|
Log.p(self, "Priority: %d" % priority)
|
|
|
|
|
2024-04-17 02:52:11 +00:00
|
|
|
|
2024-04-18 23:49:49 +00:00
|
|
|
func _on_priority_changed(_new: int, _old: int) -> void:
|
2024-04-17 02:52:11 +00:00
|
|
|
priority_changed_no_args.emit()
|
2024-04-18 23:22:03 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
priority = default_priority
|