Auto sync every 5 minutes of play
This commit is contained in:
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user