Automatically pauses minigames when kalulu is speaking. Repeat the stimulus when found in the caterpillar minigame

This commit is contained in:
Dylan Sarrazyn
2024-04-10 12:42:00 +02:00
committed by BimDav
parent d7a2393f9f
commit 32d45278b3
4 changed files with 18 additions and 26 deletions
-2
View File
@@ -224,10 +224,8 @@ func _pause_game() -> void:
func _play_kalulu() -> void:
get_tree().paused = true
minigame_ui.play_kalulu_speech(help_kalulu_speech)
await minigame_ui.kalulu_speech_ended
get_tree().paused = false
func _highlight() -> void:
+2
View File
@@ -211,11 +211,13 @@ func _on_effects_volume_slider_value_changed(volume: float) -> void:
func play_kalulu_speech(speech: AudioStream) -> void:
get_tree().paused = true
kalulu.play_kalulu_speech(speech)
func _on_kalulu_speech_ended() -> void:
kalulu_speech_ended.emit()
get_tree().paused = false
func _on_back_to_menu_button_pressed() -> void:
@@ -94,6 +94,13 @@ func _set_current_word_progression(p_current_word_progression: int) -> void:
await _on_current_word_progression_changed()
# Gets the previous stimulus which is already found
func _get_previous_stimulus() -> Dictionary:
if stimuli.size() == 0 or current_progression == 0:
return {}
return stimuli[(current_progression-1) % stimuli.size()]
# Get the current stimulus which needs to be found to increase progression
func _get_current_stimulus() -> Dictionary:
if stimuli.size() == 0:
@@ -119,14 +126,6 @@ func _is_GP_right(gp: Dictionary) -> bool:
return gp == _get_GP()
# TODO Revoir après merge
func _play_current_GP() -> void:
audio_player.stream = Database.get_audio_stream_for_phoneme(_get_GP().Phoneme)
audio_player.play()
if audio_player.playing:
await audio_player.finished
# ------------- UI Callbacks ------------- #
@@ -57,7 +57,7 @@ func _setup_minigame() -> void:
if not Engine.is_editor_hint():
branch.branch_pressed.connect(_on_branch_pressed.bind(branch))
branch.berry_pressed.connect(_play_phoneme)
branch.berry_pressed.connect(_play_berry_phoneme)
branches.append(branch)
branches_spawn_indexes.append(i)
@@ -88,13 +88,9 @@ func _clear_berries() -> void:
branch.clear_berries()
# TODO Remove after merge, use the global function instead
func _play_phoneme(gp: Dictionary) -> void:
func _play_berry_phoneme(gp: Dictionary) -> void:
if gp and gp.has("Phoneme"):
audio_player.stream = Database.get_audio_stream_for_phoneme(gp.Phoneme)
audio_player.play()
if audio_player.playing:
await audio_player.finished
await audio_player.play_phoneme(gp.Phoneme)
# -------------- CONNECTIONS -------------- #
@@ -130,11 +126,11 @@ func _on_berry_eaten(berry: Berry) -> void:
if _is_GP_right(berry.gp):
_clear_berries()
await caterpillar.eat_berry(berry)
await _play_current_GP()
await audio_player.play_phoneme(_get_GP().Phoneme)
current_word_progression += 1
else:
await caterpillar.spit_berry(berry)
await _play_phoneme(berry.gp)
await audio_player.play_phoneme(berry.gp.Phoneme)
current_lives -= 1
# Unpause timer
@@ -145,13 +141,10 @@ func _on_current_progression_changed() -> void:
# Stops the berries
berry_timer.stop()
# Clean old berries
_clear_berries()
# TODO Play the stimulus just found
# Show the word for some time
await get_tree().create_timer(time_between_words).timeout
# Show the word for some time and play the stimulus again
await get_tree().create_timer(time_between_words/2).timeout
await audio_player.play_word(_get_previous_stimulus().Word)
await get_tree().create_timer(time_between_words/2).timeout
# Reset the caterpillar
await caterpillar.reset()