stick-the-quick/util/StateReentrometer.gd

32 lines
473 B
GDScript3
Raw Permalink Normal View History

class_name StateReentrometer extends RefCounted
signal entered
signal descended
signal ascended
signal exited
var _depth: int = 0
func descend() -> void:
assert(_depth >= 0)
if _depth <= 0:
entered.emit()
descended.emit()
_depth += 1
func ascend() -> void:
assert(_depth > 0)
_depth -= 1
ascended.emit()
if _depth <= 0:
exited.emit()
func active() -> bool:
return _depth > 0
func depth() -> int:
return _depth
func valid() -> bool:
return _depth >= 0