103 lines
3.1 KiB
GDScript
103 lines
3.1 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
|
|
}
|
|
|
|
signal player_enable(enabled: bool);
|
|
|
|
signal scene_starting(scene_id: id, is_repeating: bool)
|
|
signal scene_finished(scene_id: id, is_repeating: bool)
|
|
|
|
func _ready() -> void:
|
|
pass
|
|
|
|
# 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])
|
|
|
|
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))
|
|
|
|
# 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
|
|
|
|
# Legacy support - redirects to begin_sequence
|
|
func start_sequence(scene_id: id) -> void:
|
|
push_warning("start_sequence is deprecated. CollectableUi should call begin_sequence directly.")
|
|
begin_sequence(scene_id)
|
|
|
|
# Legacy support - redirects to end_sequence
|
|
func finish_sequence(_actor: Object) -> void:
|
|
push_warning("finish_sequence is deprecated. CollectableUi should call end_sequence directly.")
|
|
if current_sequence != -1 and current_sequence < id.size():
|
|
end_sequence(id.values()[current_sequence])
|
|
|
|
# Legacy alias
|
|
func end_current_sequence() -> void:
|
|
if current_sequence != -1 and current_sequence < id.size():
|
|
end_sequence(id.values()[current_sequence])
|
|
|
|
# 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.")
|
|
|
|
# Legacy support - no longer needed
|
|
func register_scene_actor(_scene_id: id, _callable: Callable) -> void:
|
|
push_warning("register_scene_actor 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:
|
|
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;
|