2023-07-09 20:27:07 +00:00
|
|
|
extends Node
|
2025-12-16 22:21:54 +00:00
|
|
|
class_name SceneReference
|
2023-07-09 20:27:07 +00:00
|
|
|
|
2026-01-05 15:04:59 +00:00
|
|
|
# State tracking
|
2025-02-06 17:55:05 +00:00
|
|
|
var started_sequences: int = 0
|
2025-03-23 13:20:50 +00:00
|
|
|
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
|
|
|
|
2026-01-05 15:19:21 +00:00
|
|
|
## Returns true if a scene is currently playing.
|
2026-01-21 14:41:40 +00:00
|
|
|
var is_playing: bool = false
|
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,
|
2026-01-11 21:09:19 +00:00
|
|
|
YOUTH_DRAVEN,
|
2024-09-15 09:30:31 +00:00
|
|
|
YOUTH_CHILDHOOD,
|
|
|
|
|
YOUTH_VOICE_TRAINING,
|
|
|
|
|
YOUTH_JUI_JUTSU,
|
2025-03-23 13:20:50 +00:00
|
|
|
TRANSITION,
|
2024-09-15 09:30:31 +00:00
|
|
|
ADULT_DND,
|
2025-12-02 20:32:30 +00:00
|
|
|
ADULT_VOLUNTARY,
|
2026-01-19 13:46:46 +00:00
|
|
|
ADULT_AUTISM,
|
2025-07-21 17:28:20 +00:00
|
|
|
ADULT_EATING,
|
2026-01-19 13:46:46 +00:00
|
|
|
ADULT_SELF_ADVOCACY,
|
|
|
|
|
ADULT_THERAPY_VOLUNTEER,
|
2026-01-19 13:14:44 +00:00
|
|
|
ADULT_BURNOUT,
|
2026-01-19 13:46:46 +00:00
|
|
|
ADULT_THERAPY_UNI
|
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:
|
2026-01-05 15:04:59 +00:00
|
|
|
pass
|
2025-02-06 17:55:05 +00:00
|
|
|
|
2026-01-05 15:04:59 +00:00
|
|
|
# Called by CollectableUi when it starts playing a scene
|
2026-01-19 10:04:08 +00:00
|
|
|
func begin_sequence(scene_id: id, repeat: bool) -> void:
|
|
|
|
|
print_debug(">>> Scenes.begin_sequence(%s)" % str(id))
|
2026-01-21 14:41:40 +00:00
|
|
|
is_playing = true
|
2026-01-05 15:04:59 +00:00
|
|
|
|
2026-01-12 17:39:34 +00:00
|
|
|
# Disable player movement during cutscenes
|
|
|
|
|
player_enable.emit(false)
|
|
|
|
|
|
2026-01-05 15:04:59 +00:00
|
|
|
started_sequences = started_sequences | (1 << scene_id)
|
|
|
|
|
|
|
|
|
|
# Emit signal for other systems (music, animations, etc.)
|
2026-01-19 10:04:08 +00:00
|
|
|
scene_starting.emit(scene_id, repeat)
|
2025-02-06 17:55:05 +00:00
|
|
|
|
2026-01-05 15:04:59 +00:00
|
|
|
# Called by CollectableUi when it finishes playing a scene
|
2026-01-19 10:04:08 +00:00
|
|
|
func end_sequence(scene_id: id, repeat: bool) -> void:
|
|
|
|
|
print_debug(">>> Scenes.end_sequence(%s)" % str(id))
|
2026-01-05 15:04:59 +00:00
|
|
|
|
|
|
|
|
# Emit signal before clearing state
|
2026-01-19 10:04:08 +00:00
|
|
|
scene_finished.emit(scene_id, repeat)
|
2026-01-05 15:04:59 +00:00
|
|
|
|
|
|
|
|
# Mark as completed
|
|
|
|
|
completed_sequences = completed_sequences | (1 << scene_id)
|
2026-01-21 14:41:40 +00:00
|
|
|
|
|
|
|
|
is_playing = false
|
2026-01-12 17:39:34 +00:00
|
|
|
|
|
|
|
|
# Re-enable player movement after cutscene
|
|
|
|
|
player_enable.emit(true)
|
2026-01-05 15:04:59 +00:00
|
|
|
|
2026-01-19 13:46:46 +00:00
|
|
|
# TODO: put this in savegame into a "seen" array.
|
2026-01-05 15:04:59 +00:00
|
|
|
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
|
|
|
|
2025-03-23 13:20:50 +00:00
|
|
|
func get_completed_total() -> int:
|
2026-01-12 17:39:34 +00:00
|
|
|
# https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
2025-03-23 13:20:50 +00:00
|
|
|
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;
|