frame-of-mind/src/logic-scenes/playable.gd

52 lines
1.5 KiB
GDScript

extends Control
## An interactive sequence (mostly in UI space) that can be play()ed.
class_name Playable
func _ready() -> void:
prints("playable.gd", "_ready()", self)
visibility_changed.connect(_visibility_change)
hide()
# HACK: Lets us debug playables more easily
if get_parent() == get_tree().root: _debug_mode()
## Awaitable that encapsulates the core interaction with this Playable
func play() -> void:
push_warning("Playeable[base].play() not overridden")
await get_tree().process_frame # Dummy wait so this is a coroutine
func handle_hover(_area: Draggable):
#prints("Playable[base].handle_hover", _area, _area.name)
pass
const TRANSPARENT_BLACK := Color(0,0,0,0)
func appear():
self.modulate = TRANSPARENT_BLACK
show()
var tween := create_tween().set_ease(Tween.EASE_IN)
tween.tween_property(self, "modulate", Color.WHITE, 0.3)
await tween.finished
func vanish():
var tween := create_tween().set_ease(Tween.EASE_OUT)
tween.tween_property(self, "modulate", TRANSPARENT_BLACK, 0.3)
await tween.finished
hide()
## Override this (and call super._debug_mode()) if you want to initialize some data
## for running this playable standalone ("play current scene")
func _debug_mode():
push_warning("playable.gd: DEBUG MODE - ", self)
await get_tree().create_timer(1).timeout
appear()
play()
func _visibility_change():
prints(name, "NOTIFICATION_VISIBILITY_CHANGED", is_visible_in_tree())
self.set_process_input(is_visible_in_tree())
self.set_process_unhandled_input(is_visible_in_tree())