From bb3a7848c201a598177a41833518cf2fd16afc73 Mon Sep 17 00:00:00 2001 From: Adrien Ufferte Date: Mon, 7 Jul 2025 09:43:32 +0200 Subject: [PATCH] Add many logs --- sources/utils/autoloads/database.gd | 19 ++++++++--------- sources/utils/autoloads/user_data_manager.gd | 22 +++++++++++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/sources/utils/autoloads/database.gd b/sources/utils/autoloads/database.gd index 4b926a58..b9856ed5 100644 --- a/sources/utils/autoloads/database.gd +++ b/sources/utils/autoloads/database.gd @@ -51,6 +51,8 @@ func connect_to_db() -> void: db.close_db() if FileAccess.file_exists(db.path): is_open = db.open_db() + else: + Logger.warn("Database: DB file not found at %s" % db.path) func get_additional_word_list_path() -> String: @@ -77,6 +79,8 @@ func load_additional_word_list() -> String: data[title_line[index]] = line[index] additional_word_list[line[ortho_index]] = data file.close() + else: + Logger.warn("Database: Additional word list file not found: %s" % word_list_path) return "" @@ -86,16 +90,6 @@ func get_exercise_for_lesson(lesson_nb: int) -> Array[int]: WHERE LessonNB == " + str(lesson_nb) db.query(query) - #var answer: Array[String] = [] - #for res in Database.db.query_result: - # Database.db.query("Select Type FROM ExerciseTypes WHERE ID == " + str(res.Exercise1)) - # answer.append(Database.db.query_result[0].Type) - # Database.db.query("Select Type FROM ExerciseTypes WHERE ID == " + str(res.Exercise2)) - # answer.append(Database.db.query_result[0].Type) - # Database.db.query("Select Type FROM ExerciseTypes WHERE ID == " + str(res.Exercise3)) - # answer.append(Database.db.query_result[0].Type) - #return answer - var result: Array[int] = [] for element: Dictionary in db.query_result: result.append(element.Exercise1) @@ -488,6 +482,7 @@ func get_audio_stream_for_phoneme(phoneme: String) -> AudioStream: if FileAccess.file_exists(path) and ResourceLoader.exists(path): return load(path) + Logger.trace("Database: Audio stream not found for phoneme %s" % phoneme) return null @@ -501,6 +496,7 @@ func get_gp_look_and_learn_image(gp: Dictionary) -> Texture: var texture: ImageTexture = ImageTexture.create_from_image(image) return texture + Logger.trace("Database: Look & Learn image not found for GP %s" % str(gp)) return null @@ -515,6 +511,7 @@ func get_gp_look_and_learn_sound(gp: Dictionary) -> AudioStream: sound.data = file.get_buffer(file.get_length()) return sound + Logger.trace("Database: Look & Learn sound not found for GP %s" % str(gp)) return null @@ -524,6 +521,7 @@ func get_gp_look_and_learn_video(gp: Dictionary) -> VideoStream: var video: VideoStream = load(path) return video + Logger.trace("Database: Look & Learn video not found for GP %s" % gp) return null @@ -568,6 +566,7 @@ func get_kalulu_speech_path(speech_category: String, speech_name: String) -> Str func load_external_sound(path: String) -> AudioStreamMP3: if not FileAccess.file_exists(path): + Logger.trace("Database: External sound file not found: %s" % path) return null var file: FileAccess = FileAccess.open(path, FileAccess.READ) diff --git a/sources/utils/autoloads/user_data_manager.gd b/sources/utils/autoloads/user_data_manager.gd index 3fccc4a0..f9acf1b2 100644 --- a/sources/utils/autoloads/user_data_manager.gd +++ b/sources/utils/autoloads/user_data_manager.gd @@ -106,6 +106,7 @@ func stop_synchronization_timer() -> void: func register(register_settings: TeacherSettings) -> bool: if not register_settings: + Logger.warn("UserDataManager: register called with invalid register_settings") return false # Handles device settings @@ -194,9 +195,11 @@ func safe_load_and_fix_resource(path: String, old_texts: Array[String], new_text func set_device_id(device: int) -> bool: if not _device_settings: + Logger.warn("UserDataManager: set_device_id called with no device settings loaded") return false if not device: + Logger.warn("UserDataManager: set_device_id called with invalid device") return false _device_settings.device_id = device @@ -222,7 +225,11 @@ func delete_teacher_data() -> void: _delete_dir(get_teacher_folder()) func student_exists(code: String) -> bool: - if not _device_settings or not teacher_settings: + if not _device_settings: + Logger.trace("UserDataManager: student_exists called with invalid _device_settings") + return false + if not teacher_settings: + Logger.trace("UserDataManager: student_exists called with invalid teacher_settings") return false var students: Array[StudentData] = teacher_settings.students[_device_settings.device_id] as Array[StudentData] if students: @@ -232,7 +239,11 @@ func student_exists(code: String) -> bool: return false func login_student(code: String) -> bool: - if not _device_settings or not teacher_settings: + if not _device_settings: + Logger.warn("UserDataManager: login_student failed because of invalid _device_settings") + return false + if not teacher_settings: + Logger.warn("UserDataManager: login_student failed because of invalid teacher_settings") return false var students: Array[StudentData] = teacher_settings.students[_device_settings.device_id] as Array[StudentData] @@ -243,10 +254,15 @@ func login_student(code: String) -> bool: (ServerManager as ServerManagerClass).first_login_student() return true + Logger.warn("UserDataManager: login_student failed, code not found: " + code) return false func logout_student() -> bool: - if not _device_settings or not teacher_settings: + if not _device_settings: + Logger.warn("UserDataManager: logout_student failed because of invalid _device_settings") + return false + if not teacher_settings: + Logger.warn("UserDataManager: logout_student failed because of invalid teacher_settings") return false student = ""