frame-of-mind/src/singletons/scene_reference.gd

91 lines
2.5 KiB
GDScript

extends Node
class_name SceneReference
# State tracking
var started_sequences: int = 0
var completed_sequences: int = 0
var enabled_sequences: int = 255:
set(stuff): pass
var current_sequence: int = -1
## Returns true if a scene is currently playing.
var is_playing: bool:
get: return current_sequence != -1
enum id {
NONE = -1,
YOUTH_DRAVEN,
YOUTH_CHILDHOOD,
YOUTH_VOICE_TRAINING,
YOUTH_JUI_JUTSU,
TRANSITION,
ADULT_DND,
ADULT_VOLUNTARY,
ADULT_CHRISTMAS,
ADULT_EATING,
ADULT_UNI,
ADULT_THERAPY,
ADULT_BURNOUT,
ADULT_UNKNOWN
}
signal scene_starting(scene_id: id, is_repeating: bool)
signal scene_finished(scene_id: id, is_repeating: bool)
signal player_enable(enabled: bool)
func _ready() -> void:
pass
# Called by CollectableUi when it starts playing a scene
func begin_sequence(scene_id: id, repeat: bool) -> void:
print_debug(">>> Scenes.begin_sequence(%s)" % str(id))
# Disable player movement during cutscenes
player_enable.emit(false)
current_sequence = scene_id
started_sequences = started_sequences | (1 << scene_id)
# Emit signal for other systems (music, animations, etc.)
scene_starting.emit(scene_id, repeat)
# Called by CollectableUi when it finishes playing a scene
func end_sequence(scene_id: id, repeat: bool) -> void:
print_debug(">>> Scenes.end_sequence(%s)" % str(id))
# Emit signal before clearing state
scene_finished.emit(scene_id, repeat)
# Mark as completed
completed_sequences = completed_sequences | (1 << scene_id)
# Clear current sequence
if current_sequence == scene_id:
current_sequence = -1
# Re-enable player movement after cutscene
player_enable.emit(true)
# Legacy support - no longer needed
func continue_sequence(_former_actor: Object) -> void:
push_warning("continue_sequence is deprecated and does nothing.")
# Legacy support - no longer needed
func sign_up_for_sequence(_callable: Callable, _sequence_id: id, _index: int = 0) -> void:
push_warning("sign_up_for_sequence is deprecated. CollectableUi now manages playback directly.")
func is_sequence_repeating(index: int) -> bool:
return completed_sequences & (1 << index) > 0
func is_sequence_unlocked(index: id) -> bool:
return (1 << int(index)) & enabled_sequences > 0
func get_completed_total() -> int:
# https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
var i: int = completed_sequences - ((completed_sequences >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0F0F0F0F;
i *= 0x01010101;
return i >> 24;