Better handle of await for lilypad tracks
This commit is contained in:
@@ -48,45 +48,59 @@ func _reset_frog() -> void:
|
||||
#region Tracks management
|
||||
|
||||
func _free_tracks() -> void:
|
||||
var last_track: LilypadTrack
|
||||
for track: LilypadTrack in lilypad_tracks_container.get_children():
|
||||
last_track = track
|
||||
var tracks: Array = lilypad_tracks_container.get_children()
|
||||
var tracks_count: int = tracks.size()
|
||||
for index: int in tracks_count:
|
||||
var track: LilypadTrack = tracks[index]
|
||||
if index == tracks_count - 1:
|
||||
await track.reset()
|
||||
else:
|
||||
track.reset()
|
||||
await last_track.reset()
|
||||
|
||||
for track: LilypadTrack in lilypad_tracks_container.get_children():
|
||||
track.queue_free()
|
||||
# Waits for the track to be properly freed
|
||||
await track.tree_exited
|
||||
|
||||
|
||||
func _create_tracks() -> void:
|
||||
var current_word: Dictionary = _get_current_stimulus()
|
||||
var current_distractors: Array = _get_current_distractors()
|
||||
|
||||
for index: int in range((current_word.GPs as Array).size()):
|
||||
var track: LilypadTrack = LILYPAD_TRACK_SCENE.instantiate()
|
||||
lilypad_tracks_container.add_child(track)
|
||||
|
||||
track.difficulty_settings = difficulty_settings[difficulty]
|
||||
track.gp = current_word.GPs[index]
|
||||
track.distractors = current_distractors[index]
|
||||
track.distractors_queue_size = distractors_queue_size
|
||||
|
||||
track.lilypad_in_center.connect(_on_track_lilypad_in_center.bind(track))
|
||||
|
||||
|
||||
func _start_tracks() -> void:
|
||||
var is_first_track_enabled: bool = false
|
||||
var index: int = 0
|
||||
for track: LilypadTrack in lilypad_tracks_container.get_children():
|
||||
var tracks: Array[Node] = lilypad_tracks_container.get_children()
|
||||
var last_valid_index: int = -1
|
||||
for index: int in tracks.size():
|
||||
if index >= current_word_progression:
|
||||
last_valid_index = index
|
||||
if last_valid_index == -1:
|
||||
return
|
||||
for index: int in tracks.size():
|
||||
if index < current_word_progression:
|
||||
continue
|
||||
var track: LilypadTrack = tracks[index]
|
||||
if index == last_valid_index:
|
||||
await track.reset()
|
||||
else:
|
||||
track.reset()
|
||||
var is_first_track_enabled: bool = false
|
||||
for index: int in tracks.size():
|
||||
if index < current_word_progression:
|
||||
continue
|
||||
if not is_first_track_enabled:
|
||||
track.is_enabled = true
|
||||
(tracks[index] as LilypadTrack).is_enabled = true
|
||||
is_first_track_enabled = true
|
||||
track.start()
|
||||
index += 1
|
||||
for index: int in tracks.size():
|
||||
if index < current_word_progression:
|
||||
continue
|
||||
(tracks[index] as LilypadTrack).start()
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -47,10 +47,8 @@ func _get_velocity() -> float:
|
||||
func reset() -> void:
|
||||
is_enabled = false
|
||||
is_stopped = true
|
||||
|
||||
for lilypad: Lilypad in lilypads:
|
||||
lilypad.disappear()
|
||||
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
|
||||
|
||||
@@ -73,10 +71,8 @@ func pick_distractor() -> Dictionary:
|
||||
distractors_queue.shuffle()
|
||||
while distractors_queue.size() > distractors_queue_size:
|
||||
distractors_queue.pop_front()
|
||||
|
||||
if distractors_queue:
|
||||
return distractors_queue.pop_front()
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
@@ -172,7 +168,6 @@ func _on_center_tween_finished(lilypad: Lilypad, center_tween: Tween) -> void:
|
||||
func _on_spawn_timer_timeout() -> void:
|
||||
if not is_stopped:
|
||||
_spawn_lilypad()
|
||||
|
||||
# Makes sure the lilypads don't overlap
|
||||
if lilypad_size:
|
||||
spawn_timer.start(randf_range(lilypad_size.y / _get_velocity(), lilypad_size.y * 2 / _get_velocity()))
|
||||
|
||||
Reference in New Issue
Block a user