Clean and hard-typing

This commit is contained in:
Adrien Ufferte
2025-04-28 15:28:36 +02:00
parent 13f6fc3b2b
commit e334d85b67
20 changed files with 108 additions and 106 deletions
+9 -9
View File
@@ -26,34 +26,34 @@ const supported_locales: Array[String] = [
@export var device_id : int
@export var language_versions: Dictionary # locale : datetime
@export var master_volume: = 0.0 :
@export var master_volume: float = 0.0 :
set(volume):
master_volume = volume
var ind: = AudioServer.get_bus_index("Master")
var ind: int = AudioServer.get_bus_index("Master")
AudioServer.set_bus_volume_db(ind, volume)
@export var music_volume: = 0.0 :
@export var music_volume: float = 0.0 :
set(volume):
music_volume = volume
var ind: = AudioServer.get_bus_index("Music")
var ind: int = AudioServer.get_bus_index("Music")
AudioServer.set_bus_volume_db(ind, volume)
@export var voice_volume: = 0.0 :
@export var voice_volume: float = 0.0 :
set(volume):
voice_volume = volume
var ind: = AudioServer.get_bus_index("Voice")
var ind: int = AudioServer.get_bus_index("Voice")
AudioServer.set_bus_volume_db(ind, volume)
@export var effects_volume: = 0.0 :
@export var effects_volume: float = 0.0 :
set(volume):
effects_volume = volume
var ind: = AudioServer.get_bus_index("Effects")
var ind: int = AudioServer.get_bus_index("Effects")
AudioServer.set_bus_volume_db(ind, volume)
func init_OS_language() -> void:
# Gets the OS language and checks if it is supported
var osLanguage: = OS.get_locale();
var osLanguage: String = OS.get_locale();
if osLanguage and osLanguage in supported_locales:
language = osLanguage
+15 -15
View File
@@ -1,7 +1,7 @@
extends Resource
class_name TeacherSettings
const available_codes: = ["123", "124", "125", "126", "132", "134", "135", "136", "142", "143", "145", "146", "152", "153", "154", "213", "214", "215", "216", "231", "234", "235", "236", "241", "243", "245", "246", "251", "253", "254", "321", "324", "325", "326", "312", "314", "315", "316", "342", "341", "345", "346", "352", "351", "354", "423", "421", "425", "426", "432", "431", "435", "436", "412", "413", "415", "416", "452", "453", "451", "523", "524", "521", "526", "532", "534", "531", "536", "542", "543", "541", "546", "512", "513", "514", "623", "624", "625", "621", "632", "634", "635", "631", "642", "643", "645", "641", "652", "653", "654"]
const available_codes: Array[String] = ["123", "124", "125", "126", "132", "134", "135", "136", "142", "143", "145", "146", "152", "153", "154", "213", "214", "215", "216", "231", "234", "235", "236", "241", "243", "245", "246", "251", "253", "254", "321", "324", "325", "326", "312", "314", "315", "316", "342", "341", "345", "346", "352", "351", "354", "423", "421", "425", "426", "432", "431", "435", "436", "412", "413", "415", "416", "452", "453", "451", "523", "524", "521", "526", "532", "534", "531", "536", "542", "543", "541", "546", "512", "513", "514", "623", "624", "625", "621", "632", "634", "635", "631", "642", "643", "645", "641", "652", "653", "654"]
enum AccountType {
Teacher,
@@ -13,12 +13,12 @@ enum EducationMethod {
Complete
}
@export var account_type : AccountType
@export var education_method : EducationMethod
var devices_count : int
@export var students : Dictionary # int : Array[StudentData]
@export var email : String
var password : String
@export var account_type: AccountType
@export var education_method: EducationMethod
var devices_count: int
@export var students: Dictionary # int : Array[StudentData]
@export var email: String
var password: String
@export var token: String
@export var last_modified: String
@@ -39,7 +39,7 @@ func update_from_dict(dict: Dictionary) -> void:
for device: String in d_students.keys():
var device_students: Array[StudentData] = []
for student_dico: Dictionary in dict.students[device]:
var student: = StudentData.new()
var student: StudentData = StudentData.new()
student.code = student_dico.code
student.name = student_dico.name
student.age = student_dico.age
@@ -49,19 +49,19 @@ func update_from_dict(dict: Dictionary) -> void:
students[int(device)] = device_students
func get_new_code() -> String :
var used_codes: = []
var used_codes: PackedStringArray
for student_array: Array[StudentData] in students.values():
for student: StudentData in student_array:
used_codes.append(student.code)
used_codes.append(str(student.code))
if used_codes.size() == available_codes.size():
return ""
var codes: = available_codes.duplicate()
var codes: Array[String] = available_codes.duplicate()
for c: String in used_codes:
codes.erase(c)
var code : String = codes.pick_random()
var code: String = codes.pick_random()
return code
@@ -69,16 +69,16 @@ func get_students_count() -> int :
if not students:
return 0
var count: = 0
var count: int = 0
for device: int in students.keys():
var students_array: = students[device] as Array
var students_array: Array = students[device] as Array
if students_array:
count += students_array.size()
return count
func to_dict() -> Dictionary:
var dict: = {
var dict: Dictionary = {
"account_type": account_type,
"email": email,
"password": password,
+5 -5
View File
@@ -1,10 +1,10 @@
extends Resource
class_name UserMinigameHistory
const min_difficulty: = 0
const max_difficulty: = 4
const consecutive_wins_to_promote: = 2
const consecutive_losses_to_demote: = 2
const min_difficulty: int = 0
const max_difficulty: int = 4
const consecutive_wins_to_promote: int = 2
const consecutive_losses_to_demote: int = 2
@export
var difficulty: int = 0
@@ -13,7 +13,7 @@ var consecutives_losses: int = 0
@export
var consecutives_wins: int = 0
@export
var history : Array[bool] = []
var history: Array[bool]
func add_game(is_won: bool) -> void:
history.append(is_won)
+4 -4
View File
@@ -9,8 +9,8 @@ enum Status{
Completed,
}
@export var version: = 1.0
@export var unlocks: = {}
@export var version: float = 1.0
@export var unlocks: Dictionary = {}
func _init() -> void:
@@ -24,7 +24,7 @@ func init_unlocks() -> bool:
unlocks = {}
# Verifiy the lessons
var number_of_lessons: = Database.get_lessons_count()
var number_of_lessons: int = Database.get_lessons_count()
if unlocks.size() != number_of_lessons:
for index: int in number_of_lessons:
if not unlocks.has(index+1):
@@ -87,7 +87,7 @@ func game_completed(lesson_number: int, game_number: int) -> bool:
unlocks[lesson_number]["games"][game_number] = Status.Completed
var all_completed: = true
var all_completed: bool = true
for index: int in range(3):
all_completed = all_completed and unlocks[lesson_number]["games"][index] == Status.Completed
+1 -1
View File
@@ -29,7 +29,7 @@ func update_scores(minigame_scores: Dictionary) -> void:
return
for ID: int in minigame_scores.keys():
var new_score: = 0
var new_score: int = 0
if gps_scores.has(ID):
new_score += gps_scores[ID]
new_score += minigame_scores[ID]
+1 -1
View File
@@ -4,7 +4,7 @@ class_name UserSpeeches
signal speeches_changed
# Contains the list of speeches already played
@export var speeches_played: = []
@export var speeches_played: Array[String]
func add_speech(speech: String) -> void:
if not speeches_played.has(speech):
+7 -7
View File
@@ -5,30 +5,30 @@ func _on_animation_finished() -> void:
if animation in ["Hide", "Show"]:
return
var r: = randf()
var rand: float = randf()
match animation:
"Idle1", "Idle2":
if r < 0.5 :
if rand < 0.5 :
play("Idle1")
else :
play("Idle2")
"Talk1", "Talk2", "Talk3":
if r < 1.0 / 3.0:
if rand < 1.0 / 3.0:
play("Talk1")
elif r < 2.0 / 3.0:
elif rand < 2.0 / 3.0:
play("Talk2")
else:
play("Talk3")
"Tc_Idle1", "Tc_Idle2":
if r < 0.5 :
if rand < 0.5 :
play("Tc_Idle1")
else :
play("Tc_Idle2")
"Tc_Talk1", "Tc_Talk2", "Tc_Talk3":
if r < 1.0 / 3.0:
if rand < 1.0 / 3.0:
play("Tc_Talk1")
elif r < 2.0 / 3.0:
elif rand < 2.0 / 3.0:
play("Tc_Talk2")
else:
play("Tc_Talk3")
+8 -8
View File
@@ -1,14 +1,14 @@
extends Control
const element_scene: = preload("res://sources/language_tool/fish_word_list_element.tscn")
const element_scene: PackedScene = preload("res://sources/language_tool/fish_word_list_element.tscn")
@onready var elements_container: = %ElementsContainer
@onready var elements_container: VBoxContainer = %ElementsContainer
var word_list: Array
func _ready() -> void:
var query: = "SELECT name FROM sqlite_master WHERE type='table' AND name='Pseudowords'"
var query: String = "SELECT name FROM sqlite_master WHERE type='table' AND name='Pseudowords'"
Database.db.query(query)
if Database.db.query_result.is_empty():
Database.db.query("CREATE TABLE 'Pseudowords' (
@@ -69,15 +69,15 @@ func _on_list_title_new_search(new_text: String) -> void:
func _on_list_title_save_pressed() -> void:
var query: = "SELECT Pseudowords.ID, Pseudowords.Pseudoword, Pseudowords.WordID, Words.Word FROM Pseudowords
var query: String = "SELECT Pseudowords.ID, Pseudowords.Pseudoword, Pseudowords.WordID, Words.Word FROM Pseudowords
INNER JOIN Words ON Words.ID = Pseudowords.WordID"
Database.db.query(query)
var db_word_list: = Database.db.query_result.duplicate()
var db_word_list: Array[Dictionary] = Database.db.query_result.duplicate()
# delete elements that are in the DB but not in the list
for word: Dictionary in db_word_list:
var found: = false
var found: bool = false
for element: FishWordListElement in elements_container.get_children():
if element.pseudoword_id == word.ID:
found = true
@@ -86,9 +86,9 @@ func _on_list_title_save_pressed() -> void:
Database.db.delete_rows("Pseudowords", "ID=%s" % word.ID)
for element: FishWordListElement in elements_container.get_children():
var found: = false
var found: bool = false
if element.pseudoword_id >= 0:
var query_with_id: = query + " WHERE Pseudowords.ID = ?"
var query_with_id: String = query + " WHERE Pseudowords.ID = ?"
Database.db.query_with_bindings(query_with_id, [element.pseudoword_id])
if not Database.db.query_result.is_empty():
var word: Dictionary = Database.db.query_result[0]
+4 -4
View File
@@ -1,7 +1,7 @@
extends Control
const main_menu_scene_path: = "res://sources/menus/main/main_menu.tscn"
const register_scene_path := "res://sources/menus/register/register.tscn"
const main_menu_scene_path: String = "res://sources/menus/main/main_menu.tscn"
const register_scene_path: String = "res://sources/menus/register/register.tscn"
const symbols_names: Dictionary[String, String] = {
"1" : "STAR",
"2" : "BAR",
@@ -14,7 +14,7 @@ const symbols_names: Dictionary[String, String] = {
@onready var code_keyboard : CodeKeyboard = %CodeKeyboard
@onready var password_label : Label = %PasswordLabel
var password : String = ""
var password: String = ""
func _ready() -> void:
_reset_password()
@@ -24,7 +24,7 @@ func _ready() -> void:
func _reset_password() -> void:
password = TeacherSettings.available_codes.pick_random()
var password_array: = password.split("")
var password_array: PackedStringArray = password.split("")
password_label.text = tr("ADULT_CHECK_PROMPT").format(
{
"1" : tr(symbols_names[password_array[0]]),
+3 -3
View File
@@ -4,7 +4,7 @@ class_name CodeKeyboard
signal button_pressed(key : String, password : Array[String])
signal password_entered(password : String)
const button_sound := preload("res://assets/menus/login/ui_play_button.mp3")
const button_sound: AudioStreamMP3 = preload("res://assets/menus/login/ui_play_button.mp3")
@onready var password_visualizer : PasswordVisualizer = %PasswordVisualizer
@onready var buttons: GridContainer = %Buttons
@@ -40,8 +40,8 @@ func _on_button_pressed(button : TextureButton) -> void:
# Emit the password entered signal
if password.size() == 3:
var code: = ""
for char_ in password:
var code: String = ""
for char_: String in password:
code += char_
password_entered.emit(code)
@@ -2,7 +2,7 @@
extends HBoxContainer
class_name PasswordVisualizer
const icons_textures = {
const icons_textures: Dictionary = {
"1" : preload("res://assets/menus/login/symbol01.png"),
"2" : preload("res://assets/menus/login/symbol02.png"),
"3" : preload("res://assets/menus/login/symbol03.png"),
@@ -11,22 +11,22 @@ const icons_textures = {
"6" : preload("res://assets/menus/login/symbol06.png")
}
@export var key_size : int = 200:
@export var key_size: int = 200:
set(value):
key_size = value
for icon in icons:
for icon: TextureRect in icons:
icon.custom_minimum_size.x = key_size
icon.custom_minimum_size.y = key_size
@export var password : String:
@export var password: String:
set(value):
password = value
_draw_password()
@onready var icons : Array[TextureRect]
@onready var icons: Array[TextureRect]
func _ready() -> void:
_draw_password()
for icon in icons:
for icon: TextureRect in icons:
icon.custom_minimum_size.x = key_size
icon.custom_minimum_size.y = key_size
@@ -35,14 +35,14 @@ func _draw_password() -> void:
if not icons:
icons = [%Icon1, %Icon2, %Icon3]
for icon in icons:
for icon: TextureRect in icons:
icon.texture = null
if not password:
return
var i: = 0
for value in password.split(""):
var i: int = 0
for value: String in password.split(""):
if i >= 3:
Logger.error("PasswordVisualizer: A password cannot be more than 3 characters long")
return
+2 -2
View File
@@ -5,7 +5,7 @@ var items : Array[String]
func _ready() -> void:
# Adds the supported locales to the field
var idx: int = 0
for language_locale in DeviceSettings.supported_locales:
for language_locale: String in DeviceSettings.supported_locales:
if not language_locale:
continue
@@ -22,7 +22,7 @@ func _ready() -> void:
func get_selected_language() -> String:
var id: = get_selected_id()
var id: int = get_selected_id()
return items[id]
+2 -2
View File
@@ -23,7 +23,7 @@ func _hide_login_error(_value: Variant) -> void:
func _on_login_form_validator_control_validated(control: Control, passed: Variant, messages: PackedStringArray) -> void:
var label: = find_child(control.name + "Error", true, false) as Label
var label: Label = find_child(control.name + "Error", true, false) as Label
if not label:
return
if passed:
@@ -39,7 +39,7 @@ func _on_validate_button_pressed() -> void:
return
# Request server for login
var res: = await ServerManager.login(email_field.text, password_field.text)
var res: Dictionary = await ServerManager.login(email_field.text, password_field.text)
if res.code == 200:
# Login
if UserDataManager.login(res.body as Dictionary):
+2 -2
View File
@@ -3,8 +3,8 @@ extends Control
const Kalulu: = preload("res://sources/menus/main/kalulu.gd")
const LoginForm: = preload("res://sources/menus/main/login.gd")
const adult_check_scene_path := "res://sources/menus/adult_check/adult_check.tscn"
const package_loader_scene_path: = "res://sources/menus/language_selection/package_downloader.tscn"
const adult_check_scene_path: String = "res://sources/menus/adult_check/adult_check.tscn"
const package_loader_scene_path: String = "res://sources/menus/language_selection/package_downloader.tscn"
@onready var version_label : Label = $Informations/BuildVersionValue
@onready var teacher_label : Label = $Informations/TeacherValue
+3 -3
View File
@@ -1,7 +1,7 @@
extends Area2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var anchor: = $Anchor
@onready var anchor: Node2D = $Anchor
func idle() -> void:
@@ -14,7 +14,7 @@ func walk() -> void:
func _on_animation_player_animation_finished(animation_name: StringName) -> void:
if animation_name == "idle_1":
var r: = randf()
var r: float = randf()
if r <= 0.5:
animation_player.play("idle_2")
else:
@@ -24,7 +24,7 @@ func _on_animation_player_animation_finished(animation_name: StringName) -> void
animation_player.play("idle_1")
if animation_name == "walk_1":
var r: = randf()
var r: float = randf()
if r <= 0.5:
animation_player.play("walk_2")
else:
+1 -1
View File
@@ -106,7 +106,7 @@ shape = SubResource("RectangleShape2D_100ls")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_4dc5i")
&"": SubResource("AnimationLibrary_4dc5i")
}
[node name="Sprite" type="Sprite2D" parent="."]
+22 -22
View File
@@ -4,11 +4,11 @@ extends Minigame
# Namespace
const Ant: = preload("res://sources/minigames/ants/ant.gd")
const blank_class: = preload("res://sources/minigames/ants/blank.tscn")
const ant_class: = preload("res://sources/minigames/ants/ant.tscn")
const word_class: = preload("res://sources/minigames/ants/word.tscn")
const blank_class: PackedScene = preload("res://sources/minigames/ants/blank.tscn")
const ant_class: PackedScene = preload("res://sources/minigames/ants/ant.tscn")
const word_class: PackedScene = preload("res://sources/minigames/ants/word.tscn")
const label_settings: = preload("res://resources/themes/minigames_label_settings.tres")
const label_settings: LabelSettings = preload("res://resources/themes/minigames_label_settings.tres")
@onready var sentence_container: HFlowContainer = %Sentence
@onready var ants_spawn: Node2D = %AntsSpawn
@@ -19,8 +19,8 @@ const label_settings: = preload("res://resources/themes/minigames_label_settings
@onready var words: Node2D = %Words
var current_sentence: Dictionary
var answered: = []
var answers: = []
var answered: Array[bool]
var answers: Array[bool]
func _find_stimuli_and_distractions() -> void:
@@ -28,8 +28,8 @@ func _find_stimuli_and_distractions() -> void:
if sentences_list.is_empty():
return
var current_lesson_sentences: = []
var previous_lesson_sentences: = []
var current_lesson_sentences: Array[Dictionary]
var previous_lesson_sentences: Array[Dictionary]
for sentence_in_list: Dictionary in sentences_list:
if sentence_in_list.LessonNb == lesson_nb:
@@ -98,7 +98,7 @@ func _get_new_sentence() -> void:
func _next_sentence() -> void:
var nodes: = []
var nodes: Array[Node]
nodes.append_array(sentence_container.get_children())
nodes.append_array(words.get_children())
for node: Node in nodes:
@@ -106,7 +106,7 @@ func _next_sentence() -> void:
for ant: Ant in ants.get_children():
ant.walk()
var tween: = create_tween()
var tween: Tween = create_tween()
tween.tween_property(ant, "global_position", ants_despawn.global_position, 1.0)
await tween.finished
ant.queue_free()
@@ -118,9 +118,9 @@ func _next_sentence() -> void:
var current_words: PackedStringArray = (current_sentence.Sentence as String).replace("'", " ' ").replace("-", " - ").split(" ")
var inds_to_remove: = []
for index in range(1, current_words.size()):
var word: = current_words[index]
var inds_to_remove: Array[int]
for index: int in range(1, current_words.size()):
var word: String = current_words[index]
if word in ["?", "!", ":"]:
current_words[index - 1] += " " + word
inds_to_remove.append(index)
@@ -134,7 +134,7 @@ func _next_sentence() -> void:
current_words.remove_at(index)
var number_of_blanks: int = maxi(2, mini(difficulty, current_words.size()))
var blanks: = range(current_words.size())
var blanks: Array = range(current_words.size())
blanks.shuffle()
while blanks.size() > number_of_blanks:
blanks.pop_back()
@@ -142,7 +142,7 @@ func _next_sentence() -> void:
answers = []
answered = []
for index: int in range(current_words.size()):
var current_word: = current_words[index]
var current_word: String = current_words[index]
if index in blanks:
var blank: Blank = blank_class.instantiate()
blank.stimulus = current_word
@@ -166,7 +166,7 @@ func _next_sentence() -> void:
word.answer.connect(_on_word_answer.bind(word))
word.no_answer.connect(_on_word_no_answer.bind(word))
else:
var label: = Label.new()
var label: Label = Label.new()
sentence_container.add_child(label)
label.text = current_word + " "
@@ -176,14 +176,14 @@ func _next_sentence() -> void:
func _start_ants() -> void:
var number_of_ants: = ants.get_child_count()
var number_of_ants: int = ants.get_child_count()
for index: int in range(number_of_ants):
var ant: Ant = ants.get_child(index)
ant.walk()
var tween: = create_tween()
var k: = float(index) / float(number_of_ants - 1)
var tween: Tween = create_tween()
var k: float = float(index) / float(number_of_ants - 1)
tween.tween_property(ant, "global_position", k * ants_start.global_position + (1.0 - k) * ants_end.global_position, 1.0)
await tween.finished
@@ -210,14 +210,14 @@ func _on_word_answer(stimulus: String, expected_stimulus: String, word: TextureB
answers[word.get_index()] = stimulus == expected_stimulus
answered[word.get_index()] = true
var all_answered: = true
var all_answered: bool = true
for a: bool in answered:
if not a:
all_answered = false
break
if all_answered:
var is_right: = true
var is_right: bool = true
for a: bool in answers:
if not a:
is_right = false
@@ -254,7 +254,7 @@ func _on_word_answer(stimulus: String, expected_stimulus: String, word: TextureB
@warning_ignore("UNSAFE_METHOD_ACCESS")
ants.get_child(index).set_monitorable(false)
for word_i in words.get_children():
for word_i: Node in words.get_children():
@warning_ignore("UNSAFE_PROPERTY_ACCESS")
word_i.disabled = false
+8 -6
View File
@@ -4,7 +4,7 @@ class_name ControlBinder
@export var property_name : String
var control : Control
var control: Control
func _ready() -> void:
control = get_parent()
@@ -15,11 +15,13 @@ func get_value() -> Variant:
return null
if control is Range:
return control.value
elif control is LineEdit or control is TextEdit:
return control.text
return (control as Range).value
elif control is LineEdit:
return (control as LineEdit).text
elif control is TextEdit:
return (control as TextEdit).text
elif control is ItemList:
var selected_indexes = control.get_selected_items()
var selected_indexes: PackedInt32Array = control.get_selected_items()
if not selected_indexes or selected_indexes.size() == 0:
return null
if control.select_mode == ItemList.SELECT_SINGLE:
@@ -29,7 +31,7 @@ func get_value() -> Variant:
return null
func set_value(value) -> void:
func set_value(value: Variant) -> void:
if not control:
return
+1 -1
View File
@@ -20,7 +20,7 @@ func _find_binders(node: Node) -> void:
_find_binders(child)
func read(resource : Resource) -> void:
func read(resource: Resource) -> void:
if resource:
data = resource
+1 -1
View File
@@ -9,7 +9,7 @@ func _ready() -> void:
func _process(_delta: float) -> void:
if OS.has_feature("mobile"):
var margin: = DisplayServer.virtual_keyboard_get_height()
var margin: int = DisplayServer.virtual_keyboard_get_height()
if OS.get_name() == "Android":
@warning_ignore("narrowing_conversion")
margin *= screen_scale