Auto sync every 5 minutes of play

This commit is contained in:
Adrien Ufferte
2025-06-06 16:07:37 +02:00
parent 298a2bf863
commit 24d094d01b
6 changed files with 43 additions and 11 deletions
+2
View File
@@ -68,6 +68,8 @@ const Kalulu: = preload("res://sources/minigames/base/kalulu.gd")
@onready var help_speech: AudioStream = Database.load_external_sound(Database.get_kalulu_speech_path("brain_screen", "help"))
func _ready() -> void:
UserDataManager.start_synchronization_timer()
for index: int in range(garden_buttons.size()):
garden_buttons[index].pressed.connect(_on_garden_button_pressed.bind(index))
@@ -58,8 +58,6 @@ func _ready() -> void:
_show_error(1)
return
# TODO WE REMOVED CONFIGURATION AT LAUNCH, BUT WE DID NOT TEST REGISTER / LOGIN
# Gets the info of the language pack on the server
var res: Dictionary = await ServerManager.get_language_pack_url(device_language)
if res.code == 200:
+3 -1
View File
@@ -21,6 +21,8 @@ var wrong_password_speech: AudioStream
var right_password_speech: AudioStream
func _ready() -> void:
UserDataManager.stop_synchronization_timer()
# Check if the database is connected, if not go to loader
if not Database.is_open:
await get_tree().process_frame
@@ -44,7 +46,7 @@ func _ready() -> void:
func _on_code_keyboard_password_entered(password: String) -> void:
if UserDataManager.login_student(password):
UserDataManager.user_database_synchronizer.on_synchronize_button_pressed()
UserDataManager.user_database_synchronizer.synchronize()
kalulu_button.hide()
await kalulu.play_kalulu_speech(right_password_speech)
await OpeningCurtain.close()
+1 -1
View File
@@ -189,7 +189,7 @@ func update_student_name(student_code: int, student_name: String) -> void:
#region Synchronization
func _on_synchronize_button_pressed() -> void:
UserDataManager.user_database_synchronizer.on_synchronize_button_pressed()
UserDataManager.user_database_synchronizer.synchronize()
func _on_loading_popup_ok() -> void:
+29 -1
View File
@@ -25,7 +25,12 @@ var _student_difficulty: UserDifficulty
var _student_speeches: UserSpeeches
var user_database_synchronizer: UserDataBaseSynchronizer
var synchronization_timer: float = 0.0
var synchronization_timer_running: bool = false
var synchronization_time_limit: float = 300000.0 # 5 minutes in milliseconds
var now: int
var last_time: float = 0.0
var real_delta: int
func _ready() -> void:
if get_device_settings().teacher:
@@ -34,6 +39,29 @@ func _ready() -> void:
user_database_synchronizer = UserDataBaseSynchronizer.new()
func _process(_delta: float) -> void:
if synchronization_timer_running:
now = Time.get_ticks_msec()
real_delta = now - last_time
last_time = now
synchronization_timer += real_delta
if synchronization_timer >= synchronization_time_limit:
synchronization_timer = 0.0
user_database_synchronizer.synchronize()
#region synchronization
func start_synchronization_timer() -> void:
if not synchronization_timer_running:
synchronization_timer = 0.0
synchronization_timer_running = true
func stop_synchronization_timer() -> void:
synchronization_timer_running = false
#endregion
#region Registering and logging in
func register(register_settings: TeacherSettings) -> bool:
@@ -20,10 +20,11 @@ enum UpdateNeeded {
func start_sync() -> void:
synchronizing = true
loading_popup.set_finished(false)
set_loading_bar_text("SYNCHRONIZATION_INITIALISATION")
await set_loading_bar_progression(0.0)
loading_popup.show()
if loading_popup != null:
loading_popup.set_finished(false)
set_loading_bar_text("SYNCHRONIZATION_INITIALISATION")
await set_loading_bar_progression(0.0)
loading_popup.show()
func stop_sync(success: bool = false) -> void:
@@ -31,10 +32,11 @@ func stop_sync(success: bool = false) -> void:
if success:
await set_loading_bar_progression(100.0, 1.0)
set_loading_bar_text("SYNCHRONIZATION_SUCCESS")
loading_popup.set_finished(true)
if loading_popup != null:
loading_popup.set_finished(true)
func on_synchronize_button_pressed() -> void:
func synchronize() -> void:
Logger.trace("UserDataBaseSynchronizer: Start synchronizing user data.")
if synchronizing:
Logger.trace("UserDataBaseSynchronizer: User synchronization already started, cancel double-call.")