87 lines
3.0 KiB
GDScript
87 lines
3.0 KiB
GDScript
extends Node
|
|
class_name SceneReference
|
|
|
|
var sequence_actors:Array[Array] = []
|
|
var started_sequences: int = 0
|
|
var completed_sequences: int = 0
|
|
var enabled_sequences: int = 255:
|
|
set(stuff): pass
|
|
var current_sequence: int = -1
|
|
var current_sequence_index: int = 0
|
|
|
|
enum id {
|
|
YOUTH_DRAEVEN,
|
|
YOUTH_CHILDHOOD,
|
|
YOUTH_VOICE_TRAINING,
|
|
YOUTH_JUI_JUTSU,
|
|
TRANSITION,
|
|
ADULT_DND,
|
|
ADULT_VOLUNTARY,
|
|
ADULT_CHRISTMAS,
|
|
ADULT_EATING,
|
|
ADULT_UNI,
|
|
ADULT_THERAPY,
|
|
ADULT_BURNOUT
|
|
}
|
|
|
|
signal scene_starting(scene_id: id, is_repeating: bool)
|
|
signal scene_continuing(scene_id: id, scene_index: int, is_repeating: bool)
|
|
signal scene_finished(scene_id: id, is_repeating: bool)
|
|
|
|
func _ready() -> void:
|
|
for i in range(id.keys().size()):
|
|
sequence_actors.append([null, null])
|
|
|
|
func sign_up_for_sequence(callable: Callable, sequence_id: id, index: int):
|
|
if sequence_actors[sequence_id].size() <= index:
|
|
sequence_actors[sequence_id].resize(index+1)
|
|
# if this assertion fails, two objects tried to sign up for the same sequence.
|
|
assert(sequence_actors[sequence_id][index] == null)
|
|
sequence_actors[sequence_id][index] = callable
|
|
|
|
func start_sequence(index: id):
|
|
if State.pass_stage_to(sequence_actors[index][0].get_object()):
|
|
sequence_actors[index][0].call(index)
|
|
current_sequence = index
|
|
started_sequences = started_sequences | (1 << index)
|
|
scene_starting.emit(current_sequence, is_sequence_repeating(index))
|
|
else:
|
|
push_error("Sequence could not be started.")
|
|
|
|
# Leaves stage to pass it to the next element wanting to catch focus.
|
|
func continue_sequence(former_actor: Object):
|
|
# if this fails, pass next was called without a sequencce having been started.
|
|
assert(current_sequence != -1)
|
|
|
|
if former_actor == State.stage_list[0] and former_actor == sequence_actors[current_sequence][current_sequence_index].get_object():
|
|
former_actor.has_stage = false
|
|
|
|
current_sequence_index += 1
|
|
|
|
State.stage_list[0] = sequence_actors[current_sequence][current_sequence_index].get_object()
|
|
print_debug(sequence_actors[current_sequence][current_sequence_index].get_object().name)
|
|
|
|
State.stage_list[0].has_stage = true
|
|
|
|
sequence_actors[current_sequence][current_sequence_index].call(current_sequence, is_sequence_repeating(current_sequence))
|
|
|
|
scene_continuing.emit(current_sequence, current_sequence_index, is_sequence_repeating(current_sequence))
|
|
|
|
func end_current_sequence():
|
|
State.leave_stage(State.stage_list[0])
|
|
scene_finished.emit(current_sequence, is_sequence_repeating(current_sequence))
|
|
completed_sequences = completed_sequences | (1 << current_sequence)
|
|
current_sequence = -1
|
|
current_sequence_index = 0
|
|
|
|
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;
|