stick-the-quick/vfx/UIAutoloadGrabber.gd

26 lines
597 B
GDScript

class_name UIAutoloadGrabber extends Control
static var _lock: NonReentrantCoroutineMutex
static func _static_init() -> void:
_lock = NonReentrantCoroutineMutex.new()
var acquired := false
@onready var _root := get_tree().root
func acquire() -> void:
if not acquired:
await _lock.acquire()
_root.remove_child(UI)
add_child(UI)
acquired = true
func relinquish() -> void:
if acquired:
if UI.get_parent() == self:
child_exiting_tree.disconnect(relinquish)
remove_child(UI)
child_exiting_tree.connect(relinquish)
_root.add_child(UI)
acquired = false
_lock.relinquish()