Fixes a lot of typing warning for the jellyfishes and crabs minigames

This commit is contained in:
Dylan Sarrazyn
2024-04-08 10:09:06 +02:00
committed by BimDav
parent 95146c7696
commit a905543351
19 changed files with 98 additions and 83 deletions
@@ -26,21 +26,21 @@ func _start() -> void:
# Find the stimuli and distractions of the minigame.
# For this type of minigame, only vowels and syllables are allowed
func _find_stimuli_and_distractions() -> void:
var current_lesson_stimuli = []
var previous_lesson_stimuli = []
var current_lesson_stimuli: Array[Dictionary] = []
var previous_lesson_stimuli: Array[Dictionary] = []
var all_GPs: = Database.get_GP_for_lesson(lesson_nb, false, 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:
for gp: Dictionary in all_GPs:
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:
for syllable: Dictionary in all_syllables:
if syllable.LessonNb == lesson_nb:
current_lesson_stimuli.append(syllable)
else:
@@ -68,8 +68,10 @@ func _find_stimuli_and_distractions() -> void:
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:
@warning_ignore("integer_division")
var minimal_stimuli : int = number_of_stimuli/2
if stimuli.size() < minimal_stimuli:
while stimuli.size() < minimal_stimuli:
stimuli.append(current_lesson_stimuli.pick_random())
@@ -96,7 +98,7 @@ func _find_stimuli_and_distractions() -> void:
print(stimuli)
# For each stimuli get the distractors
for stimulus in stimuli:
for stimulus: Dictionary in stimuli:
var stimulus_distractors := []
var GPs : Array
@@ -105,18 +107,18 @@ func _find_stimuli_and_distractions() -> void:
# Difficulty 1
# Any previously learned item w/ all letters different
for gp in all_GPs:
for gp: Dictionary in all_GPs:
if gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme and (not gp.OtherPhonemes or not gp.OtherPhonemes.has(stimulus.Phoneme)):
stimulus_distractors.append(gp)
if GPs:
for syllable in all_syllables:
for syllable: Dictionary in all_syllables:
if syllable.GPs[0] not in GPs and syllable.GPs[1] not in GPs:
stimulus_distractors.append(syllable)
# Higher difficulties only changes syllables distractors
if difficulty > 1 and GPs:
for syllable in all_syllables:
for syllable: Dictionary in all_syllables:
# Difficulty 2-3
# If the item has 2 GP ('cha'), distractors should have only a single letter change ('la' or 'che')
if (syllable.GPs[0] == stimulus.GPs[0] and syllable.GPs[1] != stimulus.GPs[1]) or (syllable.GPs[0] != stimulus.GPs[0] and syllable.GPs[1] == stimulus.GPs[1]):
@@ -177,7 +179,7 @@ func _await_for_future_or_stimulus_found(future : Signal) -> bool:
# ------------ Connections ------------
func _on_stimulus_pressed(stimulus : Dictionary, node) -> bool:
func _on_stimulus_pressed(stimulus : Dictionary, _node : Node) -> bool:
if not is_stimulus_heard:
return false
@@ -194,11 +196,11 @@ func _on_stimulus_pressed(stimulus : Dictionary, node) -> bool:
return true
func _on_stimulus_timer_timeout():
func _on_stimulus_timer_timeout() -> void:
_play_current_stimulus_phoneme()
func _on_stimulus_found():
func _on_stimulus_found() -> void:
pass
+6 -6
View File
@@ -5,12 +5,12 @@ class_name Crab
signal crab_hit(stimulus: Dictionary)
@onready var body: Control = $Body
@onready var animated_sprite: = %AnimatedSprite2D
@onready var label: = %AutoSizeLabel.get_node("Label")
@onready var button: = $Button
@onready var highlight_fx: = %HighlightFX
@onready var right_fx: = %RightFX
@onready var wrong_fx: = %WrongFX
@onready var animated_sprite: AnimatedSprite2D = %AnimatedSprite2D
@onready var label: Label = %AutoSizeLabel.get_node("Label")
@onready var button: Button = $Button
@onready var highlight_fx: HighlightFX = %HighlightFX
@onready var right_fx: RightFX = %RightFX
@onready var wrong_fx: WrongFX = %WrongFX
var stimulus: Dictionary:
+1 -1
View File
@@ -262,7 +262,7 @@ unique_name_in_owner = true
sprite_frames = SubResource("SpriteFrames_g5q5i")
animation = &"idle1"
autoplay = "idle1"
frame_progress = 0.441566
frame_progress = 0.277209
centered = false
offset = Vector2(-5, 0)
+17 -10
View File
@@ -19,7 +19,7 @@ var difficulty_settings: Array[DifficultySettings] = [
DifficultySettings.new(0.25, [4, 3, 4])
]
@onready var crab_zone: = $GameRoot/CrabZone
@onready var crab_zone: Control = $GameRoot/CrabZone
var holes: Array[Hole] = []
var is_highlighting : bool = false
@@ -36,11 +36,11 @@ func _setup_minigame() -> void:
# Spawns the good amount of holes and places them
var top_left: Vector2 = crab_zone.position
var bottom_right: Vector2 = top_left + crab_zone.size
for i in range(settings.rows.size()):
for i: int in range(settings.rows.size()):
var fi: = float(i + 1.0) / float(settings.rows.size() + 1.0)
var y: float = (1.0 - fi) * top_left.y + fi * bottom_right.y
for j in range(settings.rows[i]):
var fj: = float(j + 1.0) / float(settings.rows[i] + 1.0)
for j: int in range(settings.rows[i]):
var fj: = float(j + 1.0) / float(settings.rows[i] as int + 1.0)
var x: float = fj * top_left.x + (1.0 - fj) * bottom_right.x
var hole: Hole = hole_scene.instantiate()
@@ -66,15 +66,19 @@ func _get_difficulty_settings() -> DifficultySettings:
return difficulty_settings[difficulty]
func _highlight():
func _highlight() -> void:
is_highlighting = true
for hole in holes:
if hole.crab and hole.crab_visible and _is_stimulus_right(hole.crab.stimulus):
hole.highlight()
func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
if not super(stimulus, hole):
func _on_stimulus_pressed(stimulus: Dictionary, node: Node) -> bool:
if not super(stimulus, node):
return false
var hole: = node as Hole
if not hole:
return false
var is_right: = _is_stimulus_right(stimulus)
@@ -86,9 +90,12 @@ func _on_stimulus_pressed(stimulus: Dictionary, hole: Hole) -> bool:
hole.wrong()
current_lives -= 1
# Spawn another crab
_on_hole_crab_despawned()
# Play the pressed crab phoneme
if stimulus and stimulus.Phoneme:
await audio_player.play_phoneme(stimulus.Phoneme)
await audio_player.play_phoneme(stimulus.Phoneme as String)
return true
@@ -126,7 +133,7 @@ func _on_hole_timer_timeout() -> void:
var hole_found: = false
while not hole_found:
for i in holes_range:
for i: int in holes_range:
if not holes[i].crab:
# Define if the crab is a stimulus or a distraction
var is_stimulus: = randf() < _get_difficulty_settings().stimuli_ratio
@@ -143,7 +150,7 @@ func _on_hole_timer_timeout() -> void:
hole_found = true
func _on_stimulus_found():
func _on_stimulus_found() -> void:
# Despawn all the crabs
for hole in holes:
hole.stop.emit()
+7 -7
View File
@@ -12,11 +12,11 @@ const crab_middle_y: float = 20.
const crab_out_y: float = -130.
const crab_up_y: float = -180.
@onready var hole_back: = $HoleBack
@onready var hole_front: = $HoleFront
@onready var mask: = $Mask
@onready var hole_back: Sprite2D = $HoleBack
@onready var hole_front: Sprite2D = $HoleFront
@onready var mask: Sprite2D = $Mask
@onready var sand_vfx: SandVFX = $SandVFX
@onready var timer: = $Timer
@onready var timer: Timer = $Timer
@onready var crab_audio_stream_player: CrabAudioStreamPlayer = $CrabAudioStreamPlayer2D
var crab: Crab
@@ -31,7 +31,7 @@ var crab_visible: bool = false:
_set_crab_button_active(stimulus_heard and crab_visible)
func _process(_delta):
func _process(_delta : float) -> void:
if not crab:
if sand_vfx.is_playing:
sand_vfx.stop()
@@ -146,7 +146,7 @@ func wrong() -> void:
crab.wrong()
func _set_crab_button_active(is_active : bool):
func _set_crab_button_active(is_active : bool) -> void:
if crab:
crab.set_button_active(is_active)
@@ -174,7 +174,7 @@ func _on_crab_hit(stimulus: Dictionary) -> void:
crab = null
func on_stimulus_heard(is_heard : bool):
func on_stimulus_heard(is_heard : bool) -> void:
stimulus_heard = is_heard
@@ -17,19 +17,19 @@ const crab_sound_list: = [
preload("res://assets/minigames/crabs/audio/sfx/crab_random_1.mp3"),
]
var is_playing: = false
var _should_play: = false
func start_playing() -> void:
is_playing = true
_should_play = true
_on_finished()
func stop_playing() -> void:
is_playing = false
_should_play = false
func _on_finished() -> void:
if is_playing:
if _should_play:
stream = crab_sound_list[randi() % crab_sound_list.size()]
playing = true
+8 -8
View File
@@ -29,14 +29,14 @@ const scale_factor : float = 0.2
scale = scales[color] * (1. + randf() * scale_factor)
# Handles sprite size
$SpriteControl.resized.emit()
sprite_control.resized.emit()
@onready var animated_sprite: = %AnimatedSprite2D
@onready var label: = %AutoSizeLabel.get_node("Label")
@onready var highlight_fx: = %HighlightFX
@onready var right_fx: = %RightFX
@onready var wrong_fx: = %WrongFX
@onready var sprite_control: SpriteControl = $SpriteControl
@onready var animated_sprite: AnimatedSprite2D = %AnimatedSprite2D
@onready var label: Label = %AutoSizeLabel.get_node("Label")
@onready var highlight_fx: HighlightFX = %HighlightFX
@onready var right_fx: RightFX = %RightFX
@onready var wrong_fx: WrongFX = %WrongFX
var stimulus: Dictionary :
set(value):
@@ -51,7 +51,7 @@ var stimulus: Dictionary :
func _ready() -> void:
stimulus = stimulus
var f = randf()
var f: = randf()
color = Colors.Red if f < 0.7 else Colors.Green
animated_sprite.play("idle")
animated_sprite.frame = randi_range(0, animated_sprite.sprite_frames.get_frame_count("idle") - 1)
+2 -1
View File
@@ -15,7 +15,7 @@ layout_mode = 3
anchors_preset = 0
offset_right = 400.0
offset_bottom = 400.0
scale = Vector2(1.02031, 1.02031)
scale = Vector2(1.14493, 1.14493)
script = ExtResource("1_06uwq")
[node name="BackFX" type="Control" parent="."]
@@ -68,6 +68,7 @@ unique_name_in_owner = true
scale = Vector2(2.15054, 2.15054)
sprite_frames = ExtResource("5_bh1cr")
animation = &"idle"
frame_progress = 0.0795803
centered = false
offset = Vector2(-0.000205994, 0.00019455)
@@ -23,8 +23,8 @@ var difficulty_settings: Array[DifficultySettings] = [
var blocking_jellyfish: Array[Jellyfish] = []
@onready var spawning_space: Control = %SpawningSpace
@onready var spawn_timer: = $SpawnTimer
@onready var highlight_timer := $HighlightTimer
@onready var spawn_timer: Timer = $SpawnTimer
@onready var highlight_timer: Timer = $HighlightTimer
func _start() -> void:
@@ -47,14 +47,14 @@ func _process(delta: float) -> void:
jellyfish.queue_free()
func _highlight():
func _highlight() -> void:
for jellyfish: Jellyfish in spawning_space.get_children():
if jellyfish.stimulus and _is_stimulus_right(jellyfish.stimulus):
jellyfish.highlight()
highlight_timer.start()
func _stop_highlight():
func _stop_highlight() -> void:
for jellyfish: Jellyfish in spawning_space.get_children():
jellyfish.stop_highlight()
highlight_timer.stop()
@@ -69,8 +69,8 @@ func _spawn() -> void:
var jellyfish_width: = new_jellyfish.size.x * new_jellyfish.scale.x
# Check if there is enough space to spawn the jellyfish and find a spot
var permitted_range: = 0
var left_border: = 0
var permitted_range: = 0.
var left_border: = 0.
# Blocking jellyfish is supposed to be ordered
for blocking in blocking_jellyfish:
permitted_range += max(0, blocking.position.x - left_border - jellyfish_width)
@@ -89,11 +89,11 @@ func _spawn() -> void:
new_jellyfish.stimulus = current_distractors.pick_random()
# Randomize the spawn and adds the jellyfish into the scene
var random_spawn: = randi_range(0, permitted_range - 1)
var random_spawn: = randf_range(0, permitted_range - 1)
left_border = 0
# Blocking jellyfish is supposed to be ordered
for blocking in blocking_jellyfish:
var local_permitted_range = max(0, blocking.position.x - left_border - jellyfish_width)
var local_permitted_range: float = max(0, blocking.position.x - left_border - jellyfish_width)
if local_permitted_range <= random_spawn:
random_spawn -= local_permitted_range
else:
@@ -136,8 +136,12 @@ func _on_spawn_timer_timeout() -> void:
spawn_timer.wait_time = _get_difficulty_settings().spawn_time
func _on_stimulus_pressed(stimulus, jellyfish: Jellyfish) -> bool:
if not super(stimulus, jellyfish):
func _on_stimulus_pressed(stimulus: Dictionary, node: Node) -> bool:
if not super(stimulus, node):
return false
var jellyfish: = node as Jellyfish
if not jellyfish:
return false
# Disconnect the jellyfish
@@ -173,11 +177,11 @@ func _on_stimulus_pressed(stimulus, jellyfish: Jellyfish) -> bool:
return true
func _on_highlight_timer_timeout():
func _on_highlight_timer_timeout() -> void:
_highlight()
func _on_stimulus_found():
func _on_stimulus_found() -> void:
spawn_timer.stop()
# Clear all the jellyfishes
for jellyfish: Jellyfish in spawning_space.get_children():
+1 -1
View File
@@ -4,7 +4,7 @@ extends Container
@export_multiline var ref_size_text: = ""
var ref_size: Vector2
@onready var label: = $Label
@onready var label: Label = $Label
func _notification(what: int) -> void:
+3 -3
View File
@@ -104,7 +104,7 @@ func get_GP_for_lesson(lesson_nb: int, distinct: bool, only_new: bool = false, o
db.query_with_bindings(query, parameters)
var result = db.query_result
var result: = db.query_result
if with_other_phonemes:
for GP in result:
@@ -152,8 +152,8 @@ GROUP BY sID"
query += " GROUP BY sID"
db.query_with_bindings(query, [lesson_nb])
var result = db.query_result
for syllable in result:
var result: = db.query_result
for syllable: Dictionary in result:
syllable.GPs = syllable.GPs.split(".")
return result
+5 -5
View File
@@ -2,18 +2,18 @@ extends Node
@onready var music_player : AudioStreamPlayer = $MusicPlayer
const main_menu_music := preload("res://assets/menus/main/ui_title_card_music.mp3")
const main_menu_music: AudioStream = preload("res://assets/menus/main/ui_title_card_music.mp3")
func _ready():
func _ready() -> void:
play(main_menu_music)
func _on_music_player_finished():
func _on_music_player_finished() -> void:
music_player.stream_paused = false
music_player.play()
func play(music : AudioStream):
func play(music : AudioStream) -> void:
music_player.stream = music
music_player.play()
func stop():
func stop() -> void:
music_player.stop()
+3 -3
View File
@@ -20,7 +20,7 @@ var student_settings: UserSettings
var student_progression: UserProgression
func _ready():
func _ready() -> void:
if get_device_settings().teacher:
_load_teacher_settings()
@@ -146,7 +146,7 @@ func _load_teacher_settings() -> void:
_device_settings.device_id = 0
_save_device_settings()
func _save_teacher_settings():
func _save_teacher_settings() -> void:
ResourceSaver.save(teacher_settings, get_teacher_settings_path())
func add_device() -> bool:
@@ -331,7 +331,7 @@ func get_effects_volume() -> float:
return value
# Convert the volume from [-80, 6]db to [0, 100] and back
func normalize_slider(volume) -> float:
func normalize_slider(volume: float) -> float:
var value: = pow((volume + 80.0) / 86, 5.0) * 100.0
return value
+1 -1
View File
@@ -1,7 +1,7 @@
extends Control
class_name HighlightFX
@onready var animation_player: = $AnimationPlayer
@onready var animation_player: AnimationPlayer = $AnimationPlayer
var is_playing : bool = false
+1 -1
View File
@@ -3,7 +3,7 @@ class_name RightFX
signal finished()
@onready var animation_player: = $AnimationPlayer
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func play() -> void:
+5 -5
View File
@@ -17,26 +17,26 @@ const textures: Array[Resource] = [
var is_playing : bool = false
func _ready():
func _ready() -> void:
timer.wait_time = particles.lifetime
func play():
func play() -> void:
particles.texture = textures.pick_random()
particles.amount = randi_range(6, 18)
particles.restart()
func start():
func start() -> void:
is_playing = true
_on_timer_timeout()
func stop():
func stop() -> void:
is_playing = false
timer.stop()
func _on_timer_timeout():
func _on_timer_timeout() -> void:
play()
timer.start()
+1 -1
View File
@@ -3,7 +3,7 @@ class_name WrongFX
signal finished()
@onready var animation_player: = $AnimationPlayer
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func play() -> void: