Updates the stimuli for the hear and find minigames. Makes old jellyfishes disappear before going to the next stimulus in the Jellyfish minigame.

This commit is contained in:
Dylan Sarrazyn
2024-03-13 17:00:28 +01:00
committed by BimDav
parent 34333e2a8c
commit b6b23375fa
10 changed files with 133 additions and 56 deletions
+1 -1
View File
@@ -12,8 +12,8 @@
[node name="AntsMinigame" instance=ExtResource("1_jqkff")]
script = ExtResource("2_05d1y")
difficulty = 3
lesson_nb = 100
difficulty = 3
max_number_of_lives = 5
max_progression = 3
intro_kalulu_speech = ExtResource("3_tm6c3")
@@ -15,6 +15,7 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jdfsm")
stimuli_ratio = 0.6
minigame_number = null
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
@@ -28,17 +28,15 @@ func _find_stimuli_and_distractions() -> void:
var current_lesson_stimuli = []
var previous_lesson_stimuli = []
var all_GPs = Database.get_GP_before_and_for_lesson(lesson_nb, false)
var all_GPs = Database.get_GP_before_and_for_lesson(lesson_nb, false, true, true)
var all_syllables = Database.get_syllables_for_lesson(lesson_nb, false)
# Find the GPs for current lesson
for gp in all_GPs:
# Adds the vowels (Type = 1)
if gp.Type == 1:
if gp.LessonNb == lesson_nb:
current_lesson_stimuli.append(gp)
else:
previous_lesson_stimuli.append(gp)
if gp.LessonNb == lesson_nb:
current_lesson_stimuli.append(gp)
else:
previous_lesson_stimuli.append(gp)
# Find the syllables for current lesson
for syllable in all_syllables:
@@ -47,25 +45,58 @@ func _find_stimuli_and_distractions() -> void:
else:
previous_lesson_stimuli.append(syllable)
# Shuffle everything
current_lesson_stimuli.shuffle()
previous_lesson_stimuli.shuffle()
# Calculate the number of stimuli to add from this lesson
@warning_ignore("narrowing_conversion")
var number_of_stimuli: int = max_progression * stimuli_ratio
# If there is no previous stimuli, only adds from current lesson
if previous_lesson_stimuli.is_empty():
while stimuli.size() < max_progression:
stimuli.append(current_lesson_stimuli.pick_random())
else:
# Calculate the number of stimuli to add from this lesson (70% of the maximum progression)
@warning_ignore("narrowing_conversion")
var number_of_stimuli: int = max_progression * stimuli_ratio
while stimuli.size() < number_of_stimuli:
stimuli.append(current_lesson_stimuli.pick_random())
# If there are more stimuli in current lesson than needed
if current_lesson_stimuli.size() >= number_of_stimuli:
for i in number_of_stimuli:
stimuli.append(current_lesson_stimuli[i])
else:
stimuli.append_array(current_lesson_stimuli)
# We if there are not enough stimuli from current lesson, we want at least half the target number of stimuli
if stimuli.size() < number_of_stimuli/2:
while stimuli.size() < number_of_stimuli/2:
stimuli.append(current_lesson_stimuli.pick_random())
print("--------------- CURRENT LESSON STIMULI :")
print(stimuli)
# Gets other stimuli from previous errors or lessons
# TODO Handle previous errors
var spaces_left : int = max_progression - stimuli.size()
if previous_lesson_stimuli.size() >= spaces_left:
for i in max_progression - stimuli.size():
stimuli.append(previous_lesson_stimuli[i])
else:
stimuli.append_array(previous_lesson_stimuli)
print("--------------- WITH PREVIOUS LESSON STIMULI :")
print(stimuli)
# If there are not enough stimuli, fill the rest with current lesson
while stimuli.size() < max_progression:
stimuli.append(previous_lesson_stimuli.pick_random())
stimuli.append(current_lesson_stimuli.pick_random())
# Shuffle the stimuli
stimuli.shuffle()
print("--------------- COMPLETE SHUFFLED STIMULI :")
print(stimuli)
# For each stimuli get the distractors
for stimulus in stimuli:
var stimulus_distractors := []
@@ -77,7 +108,7 @@ func _find_stimuli_and_distractions() -> void:
# Difficulty 1
# Any previously learned item w/ all letters different
for gp in all_GPs:
if gp.Type == 1 and gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme:
if gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme and (not gp.OtherPhoneme or not gp.OtherPhoneme.has(stimulus.Phoneme)):
stimulus_distractors.append(gp)
if GPs:
for syllable in all_syllables:
@@ -103,6 +134,7 @@ func _find_stimuli_and_distractions() -> void:
stimulus_distractors.append({})
distractions.append(stimulus_distractors)
# Get the current stimulus which needs to be found to increase progression
@@ -112,16 +144,9 @@ func _get_current_stimulus() -> Dictionary:
return stimuli[current_progression % stimuli.size()]
# Verify if the provided stimulus is right, if it has the same grapheme as the current stimulus
func _is_stimulus_right(stimulus : Dictionary) -> bool:
if not stimulus or not stimulus.has("Grapheme"):
return false
var current_stimulus := _get_current_stimulus()
if not current_stimulus or not current_stimulus.has("Grapheme"):
return false
return stimulus.Grapheme == current_stimulus.Grapheme
return stimulus == current_stimulus
# Play the phoneme of the current stimulus
@@ -129,21 +154,24 @@ func _play_current_stimulus_phoneme() -> void:
var current_stimulus: = _get_current_stimulus()
if not current_stimulus or not current_stimulus.has("Phoneme"):
return
await audio_player.play_phoneme(current_stimulus.Phoneme)
is_stimulus_heard = true
await audio_player.play_phoneme(current_stimulus.Phoneme)
stimulus_timer.start()
# ------------ Connections ------------
func _on_stimulus_pressed(_node) -> bool:
func _on_stimulus_pressed(stimulus : Dictionary, _node) -> bool:
if not is_stimulus_heard:
return false
stimulus_timer.stop()
# Log the answer
_log_new_response(stimulus, _get_current_stimulus())
return true
@@ -7,6 +7,7 @@
script = ExtResource("2_v8ldm")
between_stimuli_time = 2.0
stimulus_repeat_time = 15.0
lesson_nb = 9
max_number_of_lives = 3
max_progression = 10
+30 -14
View File
@@ -21,6 +21,7 @@ var difficulty_settings: Array[DifficultySettings] = [
@onready var crab_zone: = $GameRoot/CrabZone
var stopped : bool = true
var holes: Array[Hole] = []
@@ -48,7 +49,7 @@ func _setup_minigame() -> void:
hole.position = Vector2(x, y)
if not Engine.is_editor_hint():
hole.stimulus_hit.connect(_on_hole_stimulus_hit.bind(hole))
hole.stimulus_hit.connect(_on_stimulus_pressed.bind(hole))
hole.crab_despawned.connect(_on_hole_crab_despawned)
stimulus_heard.connect(hole.on_stimulus_heard)
@@ -58,25 +59,16 @@ func _setup_minigame() -> void:
# Launch the minigame
func _start() -> void:
super()
# Spawn a set amount of crabs in random holes
for i in range(int(3.0 * holes.size() / 4.0)):
_on_hole_crab_despawned()
await get_tree().create_timer(0.1).timeout
_spawn_crabs()
func _get_difficulty_settings() -> DifficultySettings:
return difficulty_settings[difficulty]
# ------------ Crabs ------------
func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Hole) -> void:
if not is_stimulus_heard:
return
# Logs the response
_log_new_response(stimulus, _get_current_stimulus())
func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
if not super(stimulus, hole):
return false
var is_right: = _is_stimulus_right(stimulus)
if is_right:
@@ -89,9 +81,33 @@ func _on_hole_stimulus_hit(stimulus: Dictionary, hole: Hole) -> void:
# Play the pressed crab phoneme
if stimulus and stimulus.Phoneme:
await audio_player.play_phoneme(stimulus.Phoneme)
return true
func _on_current_progression_changed() -> void:
# TODO Stop the spawning of new crabs
stopped = true
# TODO Make all crabs despawn
# Play the new stimulus
await super()
# TODO Restarts the spawning of crabs
_spawn_crabs()
# ------------ Crabs ------------
# Spawn a set amount of crabs in random holes
func _spawn_crabs() -> void:
stopped = false
for i in range(int(3.0 * holes.size() / 4.0)):
_on_hole_crab_despawned()
await get_tree().create_timer(0.1).timeout
func _on_hole_crab_despawned() -> void:
if stopped:
return
await get_tree().create_timer(randf_range(0.1, 2.0)).timeout
_on_hole_timer_timeout()
+3
View File
@@ -76,6 +76,9 @@ func spawn_crab(stimulus: Dictionary) -> void:
func despawn_crab() -> void:
if not crab:
return
var crab_x : float = -crab.size.x / 2
crab_visible = false
+2 -2
View File
@@ -2,7 +2,7 @@
extends Control
class_name Jellyfish
signal pressed()
signal pressed(stimulus: Dictionary)
enum Colors {
Red,
@@ -93,7 +93,7 @@ func wrong() -> void:
func _on_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("left_click"):
pressed.emit()
pressed.emit(stimulus)
func delete() -> void:
@@ -121,6 +121,14 @@ func _get_difficulty_settings() -> DifficultySettings:
return difficulty_settings[difficulty]
func _on_current_progression_changed() -> void:
spawn_timer.stop()
for jellyfish: Jellyfish in spawning_space.get_children():
jellyfish.delete()
super()
spawn_timer.start()
# ------------ Connections ------------
@@ -129,16 +137,13 @@ func _on_spawn_timer_timeout() -> void:
spawn_timer.wait_time = _get_difficulty_settings().spawn_time
func _on_stimulus_pressed(jellyfish: Jellyfish) -> bool:
if not super(jellyfish):
func _on_stimulus_pressed(stimulus, jellyfish: Jellyfish) -> bool:
if not super(stimulus, jellyfish):
return false
# Disconnect the jellyfish
jellyfish.pressed.disconnect(_on_stimulus_pressed)
# Log the answer
_log_new_response(jellyfish.stimulus, _get_current_stimulus())
# Check if the stimulus is right
var is_right: = _is_stimulus_right(jellyfish.stimulus)
if is_right:
@@ -11,9 +11,7 @@
[node name="JellyfishMinigame" instance=ExtResource("1_hauef")]
script = ExtResource("2_gnjlp")
lesson_nb = 12
difficulty = 4
stimuli_ratio = 0.6
intro_kalulu_speech = ExtResource("3_6sswr")
help_kalulu_speech = ExtResource("2_7li38")
win_kalulu_speech = ExtResource("3_ar7nu")
+32 -7
View File
@@ -74,7 +74,6 @@ func load_additional_word_list() -> void:
func _exit_tree() -> void:
db.close_db()
func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
@@ -95,14 +94,40 @@ func get_GP_before_lesson(lesson_nb: int, distinct: bool) -> Array:
return db.query_result
func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool, only_vowels: bool = false, with_other_phonemes: bool = false) -> Array:
var parameters := []
var query: = "SELECT Grapheme, Phoneme, "
if with_other_phonemes:
query += "(SELECT group_concat(Phoneme) FROM GPs g2
INNER JOIN GPsInLessons ON GPsInLessons.GPID = g2.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?
WHERE g.Grapheme = g2.Grapheme AND g.Phoneme != g2.Phoneme)
AS OtherPhoneme, "
parameters.append(lesson_nb)
query += "Type, LessonNb FROM GPs g
INNER JOIN GPsInLessons ON GPsInLessons.GPID = g.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?"
parameters.append(lesson_nb)
if only_vowels:
query += " WHERE Type = 1"
if distinct:
query += "GROUP BY Grapheme"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
query += " GROUP BY Grapheme"
db.query_with_bindings(query, parameters)
var result = db.query_result
if with_other_phonemes:
for GP in result:
if GP.OtherPhoneme:
GP.OtherPhoneme = GP.OtherPhoneme.split(",")
return result
func get_GP_from_word(word: String) -> Array: