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

90 lines
2.5 KiB
GDScript3
Raw Normal View History

2023-07-09 20:27:07 +00:00
extends Node
class_name SceneReference
2023-07-09 20:27:07 +00:00
# State tracking
2025-02-06 17:55:05 +00:00
var started_sequences: int = 0
var completed_sequences: int = 0
2025-12-02 20:32:30 +00:00
var enabled_sequences: int = 255:
set(stuff): pass
2025-02-06 17:55:05 +00:00
var current_sequence: int = -1
## Returns true if a scene is currently playing.
var is_playing: bool:
get: return current_sequence != -1
2025-02-06 17:55:05 +00:00
2023-07-13 14:14:53 +00:00
enum id {
2026-01-11 22:53:23 +00:00
NONE = -1,
YOUTH_DRAVEN,
2024-09-15 09:30:31 +00:00
YOUTH_CHILDHOOD,
YOUTH_VOICE_TRAINING,
YOUTH_JUI_JUTSU,
TRANSITION,
2024-09-15 09:30:31 +00:00
ADULT_DND,
2025-12-02 20:32:30 +00:00
ADULT_VOLUNTARY,
ADULT_CHRISTMAS,
2025-07-21 17:28:20 +00:00
ADULT_EATING,
ADULT_UNI,
ADULT_THERAPY,
2025-07-21 17:28:20 +00:00
ADULT_BURNOUT
2023-07-09 20:27:07 +00:00
}
2025-02-06 17:55:05 +00:00
signal scene_starting(scene_id: id, is_repeating: bool)
signal scene_finished(scene_id: id, is_repeating: bool)
2026-01-12 17:39:34 +00:00
signal player_enable(enabled: bool)
2025-02-06 17:55:05 +00:00
func _ready() -> void:
pass
2025-02-06 17:55:05 +00:00
# Called by CollectableUi when it starts playing a scene
func begin_sequence(scene_id: id) -> void:
print_debug(">>> Scenes.begin_sequence(%s)" % id.keys()[scene_id])
2026-01-12 17:39:34 +00:00
# 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, is_sequence_repeating(scene_id))
2025-02-06 17:55:05 +00:00
# Called by CollectableUi when it finishes playing a scene
func end_sequence(scene_id: id) -> void:
print_debug(">>> Scenes.end_sequence(%s)" % id.keys()[scene_id])
# Emit signal before clearing state
scene_finished.emit(scene_id, is_sequence_repeating(scene_id))
# Mark as completed
completed_sequences = completed_sequences | (1 << scene_id)
# Clear current sequence
if current_sequence == scene_id:
current_sequence = -1
2026-01-12 17:39:34 +00:00
# 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
2025-12-02 20:32:30 +00:00
func get_completed_total() -> int:
2026-01-12 17:39:34 +00:00
# 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;