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 ## Returns true if a scene is currently playing. var is_playing: bool = false enum id { NONE = -1, YOUTH_DRAVEN, YOUTH_CHILDHOOD, YOUTH_VOICE_TRAINING, YOUTH_JUI_JUTSU, TRANSITION, ADULT_DND, ADULT_VOLUNTARY, ADULT_AUTISM, ADULT_EATING, ADULT_SELF_ADVOCACY, ADULT_THERAPY_VOLUNTEER, ADULT_BURNOUT, ADULT_THERAPY_UNI } 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)) is_playing = true # Disable player movement during cutscenes player_enable.emit(false) 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) is_playing = false # Re-enable player movement after cutscene player_enable.emit(true) # TODO: put this in savegame into a "seen" array. 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;