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

62 lines
1.7 KiB
GDScript3
Raw Normal View History

@icon("res://behaviours/priority.svg")
extends Node
class_name Priority
## Keeps track of the object's priority for [SamplerPriority] purposes.
## Emitted when the priority is changed.
signal priority_changed(new: int, old: int)
@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)
## Set [field priority] to [field default_priority].
2024-04-18 23:30:03 +00:00
func priority_default() -> void:
priority = default_priority
## Set [field priority] to [field alternative_priority]
2024-04-18 23:30:03 +00:00
func priority_alternative() -> void:
priority = alternative_priority
## Toggle [field priority] between [field default_priority] and [field alternative_priority].
2024-04-18 23:30:03 +00:00
func priority_toggle() -> void:
if priority == default_priority:
2024-04-18 23:30:03 +00:00
priority = alternative_priority
else:
2024-04-18 23:30:03 +00:00
priority = default_priority
## Set the [field priority] to a specific value.
2024-04-18 23:30:03 +00:00
func priority_set(value: int):
priority = value
## 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):
if variant:
2024-04-18 23:30:03 +00:00
priority = truthy
else:
2024-04-18 23:30:03 +00:00
priority = falsy
## Get the node to which the [field priority] of this one applies to.
func get_ref() -> Node:
return get_parent()
## Log the current [field priority] value.
func log_priority() -> void:
Log.p(self, "Priority: %d" % priority)
func _ready() -> void:
priority = default_priority