Add audio stimuli
This commit is contained in:
@@ -22,6 +22,7 @@ class_name Minigame
|
||||
|
||||
@onready var minigame_ui: = $MinigameUI
|
||||
@onready var opening_curtain: = $OpeningCurtain
|
||||
@onready var audio_player: = $AudioStreamPlayer
|
||||
|
||||
# Game root shall contain all the game tree.
|
||||
# This node is pausable unlike the others, so the pause button can stop the game but not other essential processes.
|
||||
@@ -210,4 +211,10 @@ func set_current_progression(p_current_progression: int) -> void:
|
||||
if minigame_ui:
|
||||
minigame_ui.set_current_progression(p_current_progression)
|
||||
if p_current_progression == max_progression and previous_progression != max_progression:
|
||||
_win()
|
||||
await _win()
|
||||
else:
|
||||
await _on_current_progression_changed()
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
pass
|
||||
|
||||
@@ -14,6 +14,8 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_jdfsm")
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="MinigameUI" parent="." instance=ExtResource("2_a3tib")]
|
||||
|
||||
[node name="OpeningCurtain" parent="." instance=ExtResource("3_p5ryr")]
|
||||
|
||||
@@ -18,7 +18,7 @@ max_progression = 5
|
||||
help_kalulu_speech = ExtResource("3_ki5ek")
|
||||
win_kalulu_speech = ExtResource("4_cikjm")
|
||||
|
||||
[node name="MinigameUI" parent="." index="0"]
|
||||
[node name="MinigameUI" parent="." index="1"]
|
||||
empty_progression_icon = ExtResource("5_7vlrm")
|
||||
full_progression_icon = ExtResource("6_1r44u")
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ const difficulty_settings: = {
|
||||
|
||||
@export var difficulty: = 1
|
||||
@export var lesson_nb: = 4
|
||||
@export var words_count: = 3
|
||||
@export var throw_to_king_duration: = 1.2
|
||||
@export var throw_to_monkey_duration: = 0.4
|
||||
|
||||
@@ -59,14 +58,25 @@ func _setup_minigame() -> void:
|
||||
|
||||
|
||||
|
||||
func set_current_progression(p_current_progression: int) -> void:
|
||||
super(p_current_progression)
|
||||
func _on_current_progression_changed() -> void:
|
||||
word_label.text = "_".repeat(stimuli[current_progression].Word.length())
|
||||
_current_letter = 0
|
||||
await _set_current_letter(0)
|
||||
|
||||
|
||||
func _set_current_letter(p_current_letter: int) -> void:
|
||||
_current_letter = p_current_letter
|
||||
if _current_letter >= stimuli[current_progression].GPs.size():
|
||||
var coroutine: = Coroutine.new()
|
||||
for monkey in monkeys:
|
||||
coroutine.add_future(monkey.talk)
|
||||
audio_player.stream = Database.get_audio_stream_for_word(stimuli[current_progression].Word)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
await coroutine.join()
|
||||
await set_current_progression(current_progression + 1)
|
||||
return
|
||||
|
||||
var ind_good: = randi_range(0, monkeys.size() - 1)
|
||||
var grapheme_distractions: Array = distractions[current_progression][_current_letter]
|
||||
grapheme_distractions.shuffle()
|
||||
@@ -79,8 +89,7 @@ func _set_current_letter(p_current_letter: int) -> void:
|
||||
else:
|
||||
monkey.stimulus = grapheme_distractions[min(i - 1, grapheme_distractions.size() - 1)]
|
||||
monkey.stunned = false
|
||||
if _current_letter >= stimuli[current_progression].GPs.size() - 1:
|
||||
current_progression += 1
|
||||
|
||||
|
||||
|
||||
# Find the stimuli and distractions of the minigame.
|
||||
@@ -89,7 +98,7 @@ func _find_stimuli_and_distractions() -> void:
|
||||
words_list.shuffle()
|
||||
stimuli = []
|
||||
distractions = []
|
||||
for i in words_count:
|
||||
for i in max_progression:
|
||||
var word = words_list[i].Word
|
||||
var GPs: = Database.get_GP_from_word(word)
|
||||
stimuli.append({
|
||||
@@ -98,17 +107,24 @@ func _find_stimuli_and_distractions() -> void:
|
||||
})
|
||||
var grapheme_distractions: = []
|
||||
for GP in GPs:
|
||||
grapheme_distractions.append(Database.get_grapheme_distrators_for_grapheme(GP.Grapheme, lesson_nb))
|
||||
grapheme_distractions.append(Database.get_distractors_for_grapheme(GP.Grapheme, lesson_nb))
|
||||
distractions.append(grapheme_distractions)
|
||||
|
||||
|
||||
func _start() -> void:
|
||||
await monkeys_grab_coconut()
|
||||
await say_word_and_grab_coconuts()
|
||||
lock(false)
|
||||
|
||||
|
||||
func monkeys_grab_coconut() -> void:
|
||||
func say_word_and_grab_coconuts() -> void:
|
||||
if current_progression >= stimuli.size():
|
||||
return
|
||||
|
||||
var coroutine: = Coroutine.new()
|
||||
audio_player.stream = Database.get_audio_stream_for_word(stimuli[current_progression].Word)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
for monkey in monkeys:
|
||||
coroutine.add_future(monkey.grab)
|
||||
await coroutine.join()
|
||||
@@ -146,7 +162,11 @@ func monkey_throw_to_king(monkey: Monkey) -> void:
|
||||
tween.tween_property(coconut, "global_position:y", king.catch_position.global_position.y, throw_to_king_duration / 2).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN)
|
||||
await tween.finished
|
||||
await king.catch(coconut)
|
||||
await king.read()
|
||||
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(king.read)
|
||||
coroutine.add_future(monkey_talk.bind(monkey))
|
||||
await coroutine.join()
|
||||
|
||||
if monkey.stimulus == stimuli[current_progression].GPs[_current_letter]:
|
||||
await king.start_right()
|
||||
@@ -159,10 +179,10 @@ func monkey_throw_to_king(monkey: Monkey) -> void:
|
||||
coconut.queue_free()
|
||||
word_label.text = ""
|
||||
for i in _current_letter + 1:
|
||||
word_label.text += stimuli[current_progression].Word[i]
|
||||
word_label.text += "_".repeat(stimuli[current_progression].Word.length() - _current_letter + 1)
|
||||
_current_letter += 1
|
||||
monkeys_grab_coconut()
|
||||
word_label.text += stimuli[current_progression].GPs[i].Grapheme
|
||||
word_label.text += "_".repeat(stimuli[current_progression].Word.length() - word_label.text.length())
|
||||
await _set_current_letter(_current_letter + 1)
|
||||
await say_word_and_grab_coconuts()
|
||||
else:
|
||||
await king.start_wrong()
|
||||
king.finish_wrong()
|
||||
@@ -182,5 +202,15 @@ func lock(p_value: = true) -> void:
|
||||
|
||||
func _on_monkey_pressed(monkey: Monkey) -> void:
|
||||
lock()
|
||||
await monkey.talk()
|
||||
monkey_talk(monkey)
|
||||
lock(false)
|
||||
|
||||
|
||||
func monkey_talk(monkey: Monkey) -> void:
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(monkey.talk)
|
||||
audio_player.stream = Database.get_audio_stream_for_phoneme(monkey.stimulus.Phoneme)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
await coroutine.join()
|
||||
|
||||
@@ -20,11 +20,10 @@ spacing_glyph = 20
|
||||
script = ExtResource("2_12lw5")
|
||||
difficulty = 0
|
||||
lesson_nb = 10
|
||||
words_count = 3
|
||||
throw_to_king_duration = 1.2
|
||||
throw_to_monkey_duration = 0.7
|
||||
max_number_of_lives = 5
|
||||
max_progression = 3
|
||||
max_progression = 1
|
||||
help_kalulu_speech = ExtResource("3_hhwrg")
|
||||
win_kalulu_speech = ExtResource("4_oe2vh")
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ const audio_streams: = [
|
||||
$GameRoot/TreeTrunk/Branches/TreeBranch5/TreeNestBack/TreeNestFront/Position2.global_position
|
||||
]
|
||||
@onready var fly_away_positions: Array[Vector2] = [$GameRoot/FlyAway/Position1.global_position, $GameRoot/FlyAway/Position2.global_position]
|
||||
@onready var audio_player: = $AudioStreamPlayer
|
||||
|
||||
var possible_branch_positions: Array[Vector2]
|
||||
var parakeets: Array[Parakeet]
|
||||
|
||||
@@ -15,12 +15,12 @@ script = ExtResource("2_x6xn5")
|
||||
difficulty = 4
|
||||
lesson_nb = 4
|
||||
fly_duration = 3.0
|
||||
minigame_name = null
|
||||
max_number_of_lives = 5
|
||||
max_progression = null
|
||||
help_kalulu_speech = ExtResource("3_ofxb4")
|
||||
win_kalulu_speech = ExtResource("4_01e28")
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="." index="3"]
|
||||
|
||||
[node name="Background" type="TextureRect" parent="GameRoot" index="0"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
|
||||
@@ -2,6 +2,16 @@ extends Node
|
||||
|
||||
|
||||
const db_path: = "res://language_resources/fr/fr.db"
|
||||
const words_path: = "res://language_resources/fr/words/"
|
||||
const _symbols_to_string = {
|
||||
"#" : "sharp",
|
||||
"@" : "at",
|
||||
"*" : "star",
|
||||
"$" : "usd",
|
||||
"%" : "pcent",
|
||||
"§" : "para"
|
||||
}
|
||||
|
||||
@onready var db: = SQLite.new()
|
||||
|
||||
|
||||
@@ -40,8 +50,8 @@ func get_words_for_lesson(lesson_nb: int) -> Array:
|
||||
return db.query_result
|
||||
|
||||
|
||||
func get_grapheme_distrators_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
|
||||
db.query_with_bindings("SELECT DISTINCT distractor.Grapheme From GPs stimuli INNER JOIN GPs distractor INNER JOIN Lessons ON stimuli.Grapheme=? AND distractor.type = stimuli.type AND distractor.Grapheme != stimuli.Grapheme AND Lessons.GPID = distractor.ID AND Lessons.LessonNb <= ?", [grapheme, lesson_nb])
|
||||
func get_distractors_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
|
||||
db.query_with_bindings("SELECT DISTINCT distractor.Grapheme, distractor.Phoneme From GPs stimuli INNER JOIN GPs distractor INNER JOIN Lessons ON stimuli.Grapheme=? AND distractor.type = stimuli.type AND distractor.Grapheme != stimuli.Grapheme AND Lessons.GPID = distractor.ID AND Lessons.LessonNb <= ?", [grapheme, lesson_nb])
|
||||
return db.query_result
|
||||
|
||||
|
||||
@@ -55,6 +65,31 @@ func copy_without_double_graphemes(input: Array) -> Array:
|
||||
return output
|
||||
|
||||
|
||||
func get_audio_stream_for_word(word: String) -> AudioStream:
|
||||
var GPs: = get_GP_from_word(word)
|
||||
var file_name: = _phoneme_to_string(GPs[0].Phoneme)
|
||||
for i in range(1, GPs.size()):
|
||||
var GP = GPs[i]
|
||||
file_name += "-" + _phoneme_to_string(GP.Phoneme)
|
||||
file_name += ".mp3"
|
||||
return load(words_path + file_name)
|
||||
|
||||
|
||||
func get_audio_stream_for_phoneme(phoneme: String) -> AudioStream:
|
||||
var file_name: = _phoneme_to_string(phoneme)
|
||||
file_name += ".mp3"
|
||||
return load(words_path + file_name)
|
||||
|
||||
|
||||
func _phoneme_to_string(phoneme: String) -> String:
|
||||
if _symbols_to_string.has(phoneme):
|
||||
return _symbols_to_string[phoneme]
|
||||
elif phoneme == phoneme.to_lower():
|
||||
return phoneme
|
||||
else:
|
||||
return "cap." + phoneme.to_lower()
|
||||
|
||||
|
||||
# Import data from previous Kalulu version
|
||||
|
||||
func _import_gps() -> void:
|
||||
|
||||
Reference in New Issue
Block a user