diff --git a/addons/talo/apis/channels_api.gd b/addons/talo/apis/channels_api.gd index 4ea926f..a98382c 100644 --- a/addons/talo/apis/channels_api.gd +++ b/addons/talo/apis/channels_api.gd @@ -36,7 +36,7 @@ func _on_message_received(res: String, data: Dictionary) -> void: ## Get a channel by its ID. func find(channel_id: int) -> TaloChannel: - var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % channel_id) + var res := await client.make_request(HTTPClient.METHOD_GET, "/%s" % channel_id) match res.status: 200: @@ -46,7 +46,7 @@ func find(channel_id: int) -> TaloChannel: ## Get a list of channels that players can join. func get_channels(page: int) -> ChannelPage: - var res = await client.make_request(HTTPClient.METHOD_GET, "?page=%s" % page) + var res := await client.make_request(HTTPClient.METHOD_GET, "?page=%s" % page) match res.status: 200: @@ -61,7 +61,7 @@ func get_subscribed_channels() -> Array[TaloChannel]: if Talo.identity_check() != OK: return [] - var res = await client.make_request(HTTPClient.METHOD_GET, "/subscriptions") + var res := await client.make_request(HTTPClient.METHOD_GET, "/subscriptions") match res.status: 200: @@ -76,9 +76,9 @@ func create(name: String, auto_cleanup: bool = false, props: Dictionary = {}) -> if Talo.identity_check() != OK: return - var props_to_send = props.keys().map(func (key: String): return { key = key, value = str(props[key]) }) + var props_to_send := props.keys().map(func (key: String): return { key = key, value = str(props[key]) }) - var res = await client.make_request(HTTPClient.METHOD_POST, "", { + var res := await client.make_request(HTTPClient.METHOD_POST, "", { name = name, autoCleanup = auto_cleanup, props = props_to_send @@ -95,7 +95,7 @@ func join(channel_id: int) -> TaloChannel: if Talo.identity_check() != OK: return - var res = await client.make_request(HTTPClient.METHOD_POST, "/%s/join" % channel_id) + var res := await client.make_request(HTTPClient.METHOD_POST, "/%s/join" % channel_id) match res.status: 200: @@ -115,7 +115,7 @@ func update(channel_id: int, name: String = "", new_owner_alias_id: int = -1, pr if Talo.identity_check() != OK: return - var data = {} + var data := {} if not name.is_empty(): data.name = name if new_owner_alias_id != -1: @@ -123,7 +123,7 @@ func update(channel_id: int, name: String = "", new_owner_alias_id: int = -1, pr if props.size() > 0: data.props = props - var res = await client.make_request(HTTPClient.METHOD_PUT, "/%s" % channel_id, data) + var res := await client.make_request(HTTPClient.METHOD_PUT, "/%s" % channel_id, data) match res.status: 200: @@ -139,7 +139,7 @@ func delete(channel_id: int) -> void: if Talo.identity_check() != OK: return - var res = await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % channel_id) + var res := await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % channel_id) match res.status: 403: diff --git a/addons/talo/apis/events_api.gd b/addons/talo/apis/events_api.gd index f3fc061..f83dcae 100644 --- a/addons/talo/apis/events_api.gd +++ b/addons/talo/apis/events_api.gd @@ -5,8 +5,8 @@ class_name EventsAPI extends TaloAPI ## ## @tutorial: https://docs.trytalo.com/docs/godot/events -var _queue = [] -var _min_queue_size = 10 +var _queue: = [] +var _min_queue_size := 10 func _get_window_mode() -> String: match DisplayServer.window_get_mode(): @@ -36,7 +36,7 @@ func track(name: String, props: Dictionary = {}) -> void: if Talo.identity_check() != OK: return - var final_props = _build_meta_props() + var final_props := _build_meta_props() final_props.append_array( props .keys() @@ -57,7 +57,7 @@ func flush() -> void: if _queue.size() == 0: return - var res = await client.make_request(HTTPClient.METHOD_POST, "/", { events = _queue }) + var res := await client.make_request(HTTPClient.METHOD_POST, "/", { events = _queue }) _queue.clear() match res.status: diff --git a/addons/talo/apis/feedback_api.gd b/addons/talo/apis/feedback_api.gd index dc05d96..2cbcc9c 100644 --- a/addons/talo/apis/feedback_api.gd +++ b/addons/talo/apis/feedback_api.gd @@ -7,7 +7,7 @@ class_name FeedbackAPI extends TaloAPI ## Get a list of feedback categories that are available for players to submit feedback. func get_categories() -> Array[TaloFeedbackCategory]: - var res = await client.make_request(HTTPClient.METHOD_GET, "/categories") + var res := await client.make_request(HTTPClient.METHOD_GET, "/categories") match res.status: 200: diff --git a/addons/talo/apis/game_config_api.gd b/addons/talo/apis/game_config_api.gd index 6e43b70..d318283 100644 --- a/addons/talo/apis/game_config_api.gd +++ b/addons/talo/apis/game_config_api.gd @@ -21,7 +21,7 @@ func _on_message_received(res: String, data: Dictionary) -> void: ## Get the live config for your game. func get_live_config() -> TaloLiveConfig: - var res = await client.make_request(HTTPClient.METHOD_GET, "/") + var res := await client.make_request(HTTPClient.METHOD_GET, "/") match res.status: 200: Talo.live_config = TaloLiveConfig.new(res.body.config) diff --git a/addons/talo/apis/health_check_api.gd b/addons/talo/apis/health_check_api.gd index be197d2..01c017d 100644 --- a/addons/talo/apis/health_check_api.gd +++ b/addons/talo/apis/health_check_api.gd @@ -7,5 +7,5 @@ class_name HealthCheckAPI extends TaloAPI ## Ping the Talo Health Check API to check if Talo can be reached. func ping() -> bool: - var res = await client.make_request(HTTPClient.METHOD_GET, "") + var res := await client.make_request(HTTPClient.METHOD_GET, "") return res.status == 204 diff --git a/addons/talo/apis/leaderboards_api.gd b/addons/talo/apis/leaderboards_api.gd index 72ad75e..9a66a09 100644 --- a/addons/talo/apis/leaderboards_api.gd +++ b/addons/talo/apis/leaderboards_api.gd @@ -5,7 +5,7 @@ class_name LeaderboardsAPI extends TaloAPI ## ## @tutorial: https://docs.trytalo.com/docs/godot/leaderboards -var _entries_manager = TaloLeaderboardEntriesManager.new() +var _entries_manager := TaloLeaderboardEntriesManager.new() ## Get a list of all the entries that have been previously fetched or created for a leaderboard. func get_cached_entries(internal_name: String) -> Array: @@ -23,8 +23,8 @@ func get_cached_entries_for_current_player(internal_name: String) -> Array: ## Get a list of entries for a leaderboard. The page parameter is used for pagination. func get_entries(internal_name: String, page: int, alias_id = -1, include_archived = false) -> EntriesPage: - var url = "/%s/entries?page=%s" - var url_data = [internal_name, page] + var url := "/%s/entries?page=%s" + var url_data := [internal_name, page] if alias_id != -1: url += "&aliasId=%s" @@ -33,13 +33,13 @@ func get_entries(internal_name: String, page: int, alias_id = -1, include_archiv if include_archived: url += "&withDeleted=1" - var res = await client.make_request(HTTPClient.METHOD_GET, url % url_data) + var res := await client.make_request(HTTPClient.METHOD_GET, url % url_data) match res.status: 200: var entries: Array[TaloLeaderboardEntry] = Array(res.body.entries.map( func(data: Dictionary): - var entry = TaloLeaderboardEntry.new(data) + var entry := TaloLeaderboardEntry.new(data) _entries_manager.upsert_entry(internal_name, entry) return entry @@ -60,7 +60,7 @@ func add_entry(internal_name: String, score: float, props: Dictionary = {}) -> A if Talo.identity_check() != OK: return null - var props_to_send: Array = props.keys().map(func(key: String) -> Dictionary: return {key = key, value = str(props[key])}) + var props_to_send := props.keys().map(func(key: String) -> Dictionary: return {key = key, value = str(props[key])}) var res := await client.make_request(HTTPClient.METHOD_POST, "/%s/entries" % internal_name, { score = score, diff --git a/addons/talo/apis/player_auth_api.gd b/addons/talo/apis/player_auth_api.gd index 2ef6ea3..332b9de 100644 --- a/addons/talo/apis/player_auth_api.gd +++ b/addons/talo/apis/player_auth_api.gd @@ -11,7 +11,7 @@ enum LoginResult { VERIFICATION_REQUIRED, } -var session_manager = TaloSessionManager.new() +var session_manager := TaloSessionManager.new() var last_error: TaloAuthError = null func _handle_error(res: Dictionary, ret: Variant = FAILED) -> Variant: @@ -28,7 +28,7 @@ func register(identifier: String, password: String, email: String = "", verifica push_error("Email is required when verification is enabled") return FAILED - var res = await client.make_request(HTTPClient.METHOD_POST, "/register", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/register", { identifier = identifier, password = password, email = email, @@ -44,7 +44,7 @@ func register(identifier: String, password: String, email: String = "", verifica ## Log in to an existing player account. If verification is required, a verification code will be sent to the player's email. func login(identifier: String, password: String) -> LoginResult: - var res = await client.make_request(HTTPClient.METHOD_POST, "/login", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/login", { identifier = identifier, password = password }) @@ -65,7 +65,7 @@ func login(identifier: String, password: String) -> LoginResult: ## Verify a player account using the verification code sent to the player's email. func verify(verification_code: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_POST, "/verify", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/verify", { aliasId = session_manager.get_verification_alias_id(), code = verification_code }) @@ -85,7 +85,7 @@ func logout() -> void: ## Change the password of the current player account. func change_password(current_password: String, new_password: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_POST, "/change_password", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/change_password", { currentPassword = current_password, newPassword = new_password }) @@ -98,7 +98,7 @@ func change_password(current_password: String, new_password: String) -> Error: ## Change the email of the current player account. func change_email(current_password: String, new_email: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_POST, "/change_email", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/change_email", { currentPassword = current_password, newEmail = new_email }) @@ -111,7 +111,7 @@ func change_email(current_password: String, new_email: String) -> Error: ## Send a password reset email to the player's email. func forgot_password(email: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_POST, "/forgot_password", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/forgot_password", { email = email }) @@ -123,7 +123,7 @@ func forgot_password(email: String) -> Error: ## Reset the password of the player account using the code sent to the player's email. func reset_password(code: String, password: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_POST, "/reset_password", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/reset_password", { code = code, password = password }) @@ -136,7 +136,7 @@ func reset_password(code: String, password: String) -> Error: ## Toggle email verification for the current player account. func toggle_verification(current_password: String, verification_enabled: bool, email: String = "") -> Error: - var res = await client.make_request(HTTPClient.METHOD_PATCH, "/toggle_verification", { + var res := await client.make_request(HTTPClient.METHOD_PATCH, "/toggle_verification", { currentPassword = current_password, verificationEnabled = verification_enabled, email = email @@ -150,7 +150,7 @@ func toggle_verification(current_password: String, verification_enabled: bool, e ## Delete the current player account. func delete_account(current_password: String) -> Error: - var res = await client.make_request(HTTPClient.METHOD_DELETE, "/", { + var res := await client.make_request(HTTPClient.METHOD_DELETE, "/", { currentPassword = current_password }) diff --git a/addons/talo/apis/player_groups_api.gd b/addons/talo/apis/player_groups_api.gd index a4b4c9c..155ecb6 100644 --- a/addons/talo/apis/player_groups_api.gd +++ b/addons/talo/apis/player_groups_api.gd @@ -7,7 +7,7 @@ class_name PlayerGroupsAPI extends TaloAPI ## Get the members of a group. If the group is public (as set in the dashboard), the members will be returned. If the group is private, only a membership count will be returned. func get_group(group_id: String) -> TaloPlayerGroup: - var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % group_id) + var res := await client.make_request(HTTPClient.METHOD_GET, "/%s" % group_id) match res.status: 200: diff --git a/addons/talo/apis/player_presence_api.gd b/addons/talo/apis/player_presence_api.gd index af3a020..88663b2 100644 --- a/addons/talo/apis/player_presence_api.gd +++ b/addons/talo/apis/player_presence_api.gd @@ -19,7 +19,7 @@ func _on_message_received(res: String, data: Dictionary) -> void: ## Get the presence status for a specific player. func get_presence(player_id: String) -> TaloPlayerPresence: - var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % player_id) + var res := await client.make_request(HTTPClient.METHOD_GET, "/%s" % player_id) match res.status: 200: @@ -32,7 +32,7 @@ func update_presence(online: bool, custom_status: String = "") -> TaloPlayerPres if Talo.identity_check() != OK: return null - var res = await client.make_request(HTTPClient.METHOD_PUT, "", { + var res := await client.make_request(HTTPClient.METHOD_PUT, "", { online = online, customStatus = custom_status }) diff --git a/addons/talo/apis/players_api.gd b/addons/talo/apis/players_api.gd index 321d8e6..e4fd043 100644 --- a/addons/talo/apis/players_api.gd +++ b/addons/talo/apis/players_api.gd @@ -10,7 +10,7 @@ signal identified(player: TaloPlayer) ## Identify a player using a service (e.g. "username") and identifier (e.g. "bob"). func identify(service: String, identifier: String) -> TaloPlayer: - var res = await client.make_request(HTTPClient.METHOD_GET, "/identify?service=%s&identifier=%s" % [service, identifier]) + var res := await client.make_request(HTTPClient.METHOD_GET, "/identify?service=%s&identifier=%s" % [service, identifier]) match res.status: 200: Talo.current_alias = TaloPlayerAlias.new(res.body.alias) @@ -31,7 +31,7 @@ func identify_steam(ticket: String, identity: String = "") -> TaloPlayer: ## Flush and sync the player's current data with Talo. func update() -> TaloPlayer: - var res = await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % Talo.current_player.id, { props = Talo.current_player.get_serialized_props() }) + var res := await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % Talo.current_player.id, { props = Talo.current_player.get_serialized_props() }) match res.status: 200: if is_instance_valid(Talo.current_alias.player): @@ -44,7 +44,7 @@ func update() -> TaloPlayer: ## Merge all of the data from player_id2 into player_id1 and delete player_id2. func merge(player_id1: String, player_id2: String) -> TaloPlayer: - var res = await client.make_request(HTTPClient.METHOD_POST, "/merge", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/merge", { playerId1 = player_id1, playerId2 = player_id2 }) @@ -57,7 +57,7 @@ func merge(player_id1: String, player_id2: String) -> TaloPlayer: ## Get a player by their ID. func find(player_id: String) -> TaloPlayer: - var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % player_id) + var res := await client.make_request(HTTPClient.METHOD_GET, "/%s" % player_id) match res.status: 200: return TaloPlayer.new(res.body.player) @@ -66,7 +66,7 @@ func find(player_id: String) -> TaloPlayer: ## Generate a mostly-unique identifier. func generate_identifier() -> String: - var time_hash: String = str(TaloTimeUtils.get_timestamp_msec()).sha256_text() - var size = 12 - var split_start: int = RandomNumberGenerator.new().randi_range(0, time_hash.length() - size) + var time_hash := str(TaloTimeUtils.get_timestamp_msec()).sha256_text() + var size := 12 + var split_start := RandomNumberGenerator.new().randi_range(0, time_hash.length() - size) return time_hash.substr(split_start, size) diff --git a/addons/talo/apis/saves_api.gd b/addons/talo/apis/saves_api.gd index 665aa2a..5815c34 100644 --- a/addons/talo/apis/saves_api.gd +++ b/addons/talo/apis/saves_api.gd @@ -12,7 +12,7 @@ signal save_chosen(save: TaloGameSave) ## Emitted when the chosen save has finished loading. signal save_loading_completed -var _saves_manager = TaloSavesManager.new() +var _saves_manager := TaloSavesManager.new() ## All of the player's fetched saves. var all: Array[TaloGameSave]: @@ -28,9 +28,9 @@ var current: TaloGameSave: ## Sync an offline save with an online save using the offline save data. func replace_save_with_offline_save(offline_save: TaloGameSave) -> TaloGameSave: - var res = await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % offline_save.id, { - name=offline_save.name, - content=offline_save.content + var res := await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % offline_save.id, { + name = offline_save.name, + content = offline_save.content }) match res.status: @@ -51,7 +51,7 @@ func get_saves() -> Array[TaloGameSave]: if Talo.identity_check() != OK: return [] - var res = await client.make_request(HTTPClient.METHOD_GET, "/") + var res := await client.make_request(HTTPClient.METHOD_GET, "/") match res.status: 200: online_saves.append_array(res.body.saves.map(func (data: Dictionary): return TaloGameSave.new(data))) @@ -80,16 +80,16 @@ func create_save(save_name: String, content: Dictionary = {}) -> TaloGameSave: var save: TaloGameSave _saves_manager.register_fields_for_saved_objects() - var save_content = content if not content.is_empty() else _saves_manager.get_save_content() + var save_content := content if not content.is_empty() else _saves_manager.get_save_content() if await Talo.is_offline(): save = TaloGameSave.new({ - name=save_name, - content=save_content, - updatedAt=TaloTimeUtils.get_current_datetime_string() + name = save_name, + content = save_content, + updatedAt = TaloTimeUtils.get_current_datetime_string() }) else: - var res = await client.make_request(HTTPClient.METHOD_POST, "/", { + var res := await client.make_request(HTTPClient.METHOD_POST, "/", { name=save_name, content=save_content }) @@ -120,7 +120,7 @@ func update_current_save(new_name: String = "") -> TaloGameSave: ## Update the given save using the current state of the game and with the given name. func update_save(save: TaloGameSave, new_name: String = "") -> TaloGameSave: - var content = _saves_manager.get_save_content() + var content := _saves_manager.get_save_content() if await Talo.is_offline(): if not new_name.is_empty(): @@ -132,7 +132,7 @@ func update_save(save: TaloGameSave, new_name: String = "") -> TaloGameSave: if Talo.identity_check() != OK: return - var res = await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % save.id, { + var res := await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % save.id, { name=save.name if new_name.is_empty() else new_name, content=content }) @@ -150,7 +150,7 @@ func delete_save(save: TaloGameSave) -> void: if Talo.identity_check() != OK: return - var res = await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % save.id) + var res := await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % save.id) match res.status: _: diff --git a/addons/talo/apis/socket_tickets_api.gd b/addons/talo/apis/socket_tickets_api.gd index 0c607be..462d040 100644 --- a/addons/talo/apis/socket_tickets_api.gd +++ b/addons/talo/apis/socket_tickets_api.gd @@ -7,7 +7,7 @@ class_name SocketTicketsAPI extends TaloAPI ## Create a new socket ticket. func create_ticket() -> String: - var res = await client.make_request(HTTPClient.METHOD_POST, "") + var res := await client.make_request(HTTPClient.METHOD_POST, "") match res.status: 200: diff --git a/addons/talo/entities/entity_with_props.gd b/addons/talo/entities/entity_with_props.gd index 57c723f..7336df8 100644 --- a/addons/talo/entities/entity_with_props.gd +++ b/addons/talo/entities/entity_with_props.gd @@ -7,12 +7,12 @@ func _init(props: Array) -> void: ## Get a property value by key. Returns the fallback value if the key is not found. func get_prop(key: String, fallback: String = "") -> String: - var filtered = props.filter(func (prop: TaloProp): return prop.key == key && prop.value != null) + var filtered := props.filter(func (prop: TaloProp): return prop.key == key && prop.value != null) return fallback if filtered.is_empty() else filtered.front().value ## Set a property by key and value. func set_prop(key: String, value: String) -> void: - var filtered = props.filter(func (prop: TaloProp): return prop.key == key) + var filtered := props.filter(func (prop: TaloProp): return prop.key == key) if filtered.is_empty(): props.push_back(TaloProp.new(key, value)) else: diff --git a/addons/talo/entities/live_config.gd b/addons/talo/entities/live_config.gd index ae7bbe5..5a7da4a 100644 --- a/addons/talo/entities/live_config.gd +++ b/addons/talo/entities/live_config.gd @@ -10,5 +10,5 @@ func _init(props: Array): ## Get a property value by key. Returns the fallback value if the key is not found. func get_prop(key: String, fallback: String) -> String: - var filtered = props.filter(func (prop: TaloProp): return prop.key == key) + var filtered := props.filter(func (prop: TaloProp): return prop.key == key) return fallback if filtered.is_empty() else filtered.front().value diff --git a/addons/talo/entities/loadable.gd b/addons/talo/entities/loadable.gd index 1063369..4c823b0 100644 --- a/addons/talo/entities/loadable.gd +++ b/addons/talo/entities/loadable.gd @@ -18,9 +18,9 @@ func _load_data(save: TaloGameSave) -> void: if not save: return - var fields = {} + var fields := {} - var filtered = save.content.objects.filter(func (obj: Dictionary): return obj.id == id) + var filtered := save.content.objects.filter(func (obj: Dictionary): return obj.id == id) as Array if filtered.is_empty(): push_warning("Loadable with id '%s' not found in save '%s'" % [id, save.name]) return diff --git a/addons/talo/entities/saved_object.gd b/addons/talo/entities/saved_object.gd index d0a44a1..5b63749 100644 --- a/addons/talo/entities/saved_object.gd +++ b/addons/talo/entities/saved_object.gd @@ -18,7 +18,7 @@ func register_loadable_fields(): func to_dictionary() -> Dictionary: register_loadable_fields() - var destroyed_data = [{ key = "meta.destroyed", value = str(true), type = str(TYPE_BOOL) }] + var destroyed_data := [{ key = "meta.destroyed", value = str(true), type = str(TYPE_BOOL) }] return { id = id, diff --git a/addons/talo/samples/authentication/scripts/change_email.gd b/addons/talo/samples/authentication/scripts/change_email.gd index 1d19bb1..bc32e05 100644 --- a/addons/talo/samples/authentication/scripts/change_email.gd +++ b/addons/talo/samples/authentication/scripts/change_email.gd @@ -18,7 +18,7 @@ func _on_submit_pressed() -> void: validation_label.text = "New email is required" return - var res = await Talo.player_auth.change_email(password.text, new_email.text) + var res := await Talo.player_auth.change_email(password.text, new_email.text) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.INVALID_CREDENTIALS: diff --git a/addons/talo/samples/authentication/scripts/change_password.gd b/addons/talo/samples/authentication/scripts/change_password.gd index 0e50cc9..de67a89 100644 --- a/addons/talo/samples/authentication/scripts/change_password.gd +++ b/addons/talo/samples/authentication/scripts/change_password.gd @@ -18,7 +18,7 @@ func _on_submit_pressed() -> void: validation_label.text = "New password is required" return - var res = await Talo.player_auth.change_password(current_password.text, new_password.text) + var res := await Talo.player_auth.change_password(current_password.text, new_password.text) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.INVALID_CREDENTIALS: diff --git a/addons/talo/samples/authentication/scripts/delete_account.gd b/addons/talo/samples/authentication/scripts/delete_account.gd index c181a5d..0128a56 100644 --- a/addons/talo/samples/authentication/scripts/delete_account.gd +++ b/addons/talo/samples/authentication/scripts/delete_account.gd @@ -13,7 +13,7 @@ func _on_delete_pressed() -> void: validation_label.text = "Current password is required" return - var res = await Talo.player_auth.delete_account(current_password.text) + var res := await Talo.player_auth.delete_account(current_password.text) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.INVALID_CREDENTIALS: diff --git a/addons/talo/samples/authentication/scripts/register.gd b/addons/talo/samples/authentication/scripts/register.gd index 68ec01f..ff28e6d 100644 --- a/addons/talo/samples/authentication/scripts/register.gd +++ b/addons/talo/samples/authentication/scripts/register.gd @@ -23,7 +23,7 @@ func _on_submit_button_pressed() -> void: validation_label.text = "Email is required when verification is enabled" return - var res = await Talo.player_auth.register(username.text, password.text, email.text, enable_verification.button_pressed) + var res := await Talo.player_auth.register(username.text, password.text, email.text, enable_verification.button_pressed) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.IDENTIFIER_TAKEN: diff --git a/addons/talo/samples/authentication/scripts/reset_password.gd b/addons/talo/samples/authentication/scripts/reset_password.gd index 57afe64..27e54e6 100644 --- a/addons/talo/samples/authentication/scripts/reset_password.gd +++ b/addons/talo/samples/authentication/scripts/reset_password.gd @@ -18,7 +18,7 @@ func _on_submit_pressed() -> void: validation_label.text = "New password is required" return - var res = await Talo.player_auth.reset_password(code.text, new_password.text) + var res := await Talo.player_auth.reset_password(code.text, new_password.text) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.PASSWORD_RESET_CODE_INVALID: diff --git a/addons/talo/samples/authentication/scripts/verify.gd b/addons/talo/samples/authentication/scripts/verify.gd index 39b1876..528876d 100644 --- a/addons/talo/samples/authentication/scripts/verify.gd +++ b/addons/talo/samples/authentication/scripts/verify.gd @@ -10,7 +10,7 @@ func _on_submit_pressed() -> void: validation_label.text = "Verification code is required" return - var res = await Talo.player_auth.verify(code.text) + var res := await Talo.player_auth.verify(code.text) if res != OK: match Talo.player_auth.last_error.get_code(): TaloAuthError.ErrorCode.VERIFICATION_CODE_INVALID: diff --git a/addons/talo/samples/chat/scripts/chat.gd b/addons/talo/samples/chat/scripts/chat.gd index 1a2d843..ae79e1b 100644 --- a/addons/talo/samples/chat/scripts/chat.gd +++ b/addons/talo/samples/chat/scripts/chat.gd @@ -1,8 +1,8 @@ extends Node2D -@export var player_username = "" +@export var player_username := "" -var _active_channel_id = -1 +var _active_channel_id := -1 var _subscriptions: Array[TaloChannel] = [] func _ready(): @@ -23,9 +23,10 @@ func _on_presence_changed(presence: TaloPlayerPresence, online_changed: bool, cu func _on_identified(player: TaloPlayer) -> void: _subscriptions = await Talo.channels.get_subscribed_channels() - var res = await Talo.channels.get_channels(0) + var res := await Talo.channels.get_channels(0) assert(is_instance_valid(res)) - var channels = res.channels + var channels := res.channels + _add_chat_message("[SYSTEM] Found %s channel%s" % [channels.size(), "" if channels.size() == 1 else "s"]) for channel in channels: _add_channel_label(channel.id, channel.name) @@ -38,14 +39,14 @@ func _on_add_channel_button_pressed() -> void: if %ChannelName.text.is_empty(): return - var channel = await Talo.channels.create(%ChannelName.text, true) + var channel := await Talo.channels.create(%ChannelName.text, true) if channel: _subscriptions.append(channel) _add_channel_label(channel.id, channel.name) %ChannelName.text = "" func _add_chat_message(message: String) -> void: - var chat_message = Label.new() + var chat_message := Label.new() chat_message.text = message %Messages.add_child(chat_message) @@ -53,7 +54,7 @@ func _is_subscribed_to_channel(id: int) -> bool: return _subscriptions.map(func (channel): return channel.id).find(id) != -1 func _add_channel_label(id: int, name: String) -> void: - var button = Button.new() + var button := Button.new() button.text = name button.pressed.connect(func (): _set_active_channel(id, name)) %Channels.add_child(button) @@ -63,7 +64,7 @@ func _set_active_channel(id: int, name: String) -> void: return if !_is_subscribed_to_channel(id): - var channel = await Talo.channels.join(id) + var channel := await Talo.channels.join(id) _subscriptions.append(channel) _add_chat_message("[SYSTEM] Subscribed to channel %s" % name) diff --git a/addons/talo/samples/leaderboards/scripts/leaderboard.gd b/addons/talo/samples/leaderboards/scripts/leaderboard.gd index d4379aa..8b6aea1 100644 --- a/addons/talo/samples/leaderboards/scripts/leaderboard.gd +++ b/addons/talo/samples/leaderboards/scripts/leaderboard.gd @@ -3,7 +3,7 @@ extends Node2D var entry_scene = preload("res://addons/talo/samples/leaderboards/entry.tscn") @export var leaderboard_internal_name: String -@export var include_archived: bool = false +@export var include_archived: bool @onready var leaderboard_name: Label = %LeaderboardName @onready var entries_container: VBoxContainer = %Entries @@ -13,7 +13,7 @@ var entry_scene = preload("res://addons/talo/samples/leaderboards/entry.tscn") var _entries_error: bool var _filter: String = "All" -var _filter_idx: int = 0 +var _filter_idx: int func _ready() -> void: leaderboard_name.text = leaderboard_name.text.replace("{leaderboard}", leaderboard_internal_name) @@ -46,8 +46,8 @@ func _build_entries() -> void: _create_entry(entry) func _load_entries() -> void: - var page = 0 - var done = false + var page := 0 + var done := false while !done: var res := await Talo.leaderboards.get_entries(leaderboard_internal_name, page, -1, include_archived) @@ -68,8 +68,8 @@ func _load_entries() -> void: func _on_submit_pressed() -> void: await Talo.players.identify("username", username.text) - var score = RandomNumberGenerator.new().randi_range(0, 100) - var team = "Blue" if RandomNumberGenerator.new().randi_range(0, 1) == 0 else "Red" + var score := RandomNumberGenerator.new().randi_range(0, 100) + var team := "Blue" if RandomNumberGenerator.new().randi_range(0, 1) == 0 else "Red" var res := await Talo.leaderboards.add_entry(leaderboard_internal_name, score, {team = team}) assert(is_instance_valid(res)) diff --git a/addons/talo/samples/playground/scripts/add_entry_button.gd b/addons/talo/samples/playground/scripts/add_entry_button.gd index b5213ed..a4f4f30 100644 --- a/addons/talo/samples/playground/scripts/add_entry_button.gd +++ b/addons/talo/samples/playground/scripts/add_entry_button.gd @@ -11,7 +11,7 @@ func _on_pressed() -> void: %ResponseLabel.text = "leaderboard_name not set on AddEntryButton" return - var score = RandomNumberGenerator.new().randi_range(1, 50) + var score := RandomNumberGenerator.new().randi_range(1, 50) var res := await Talo.leaderboards.add_entry(leaderboard_name, score) if is_instance_valid(res): diff --git a/addons/talo/samples/playground/scripts/get_categories_button.gd b/addons/talo/samples/playground/scripts/get_categories_button.gd index 08b71a9..5353a1c 100644 --- a/addons/talo/samples/playground/scripts/get_categories_button.gd +++ b/addons/talo/samples/playground/scripts/get_categories_button.gd @@ -1,10 +1,10 @@ extends Button func _on_pressed() -> void: - var categories = await Talo.feedback.get_categories() + var categories := await Talo.feedback.get_categories() if categories.size() == 0: %ResponseLabel.text = "No categories found. Create some in the Talo dashboard!" else: - var mapped = categories.map(func (c): return "%s (%s)" % [c.name, c.internal_name]) + var mapped := categories.map(func (c): return "%s (%s)" % [c.name, c.internal_name]) %ResponseLabel.text = "Categories: " + ", ".join(mapped) diff --git a/addons/talo/samples/playground/scripts/get_entries_button.gd b/addons/talo/samples/playground/scripts/get_entries_button.gd index 2ff1a16..f9db211 100644 --- a/addons/talo/samples/playground/scripts/get_entries_button.gd +++ b/addons/talo/samples/playground/scripts/get_entries_button.gd @@ -7,10 +7,10 @@ func _on_pressed() -> void: %ResponseLabel.text = "leaderboard_name not set on GetEntriesButton" return - var res = await Talo.leaderboards.get_entries(leaderboard_name, 0) + var res := await Talo.leaderboards.get_entries(leaderboard_name, 0) if is_instance_valid(res): - var entries = res.entries + var entries := res.entries %ResponseLabel.text = "Received %s entries" % entries.size() else: %ResponseLabel.text = "No entries found for %s" % leaderboard_name diff --git a/addons/talo/samples/playground/scripts/get_global_history_button.gd b/addons/talo/samples/playground/scripts/get_global_history_button.gd index 3fe5c1a..e86a7a7 100644 --- a/addons/talo/samples/playground/scripts/get_global_history_button.gd +++ b/addons/talo/samples/playground/scripts/get_global_history_button.gd @@ -1,7 +1,7 @@ extends Button @export var stat_name: String -@export var player_id: String = "" +@export var player_id: String func _on_pressed() -> void: if stat_name.is_empty(): diff --git a/addons/talo/samples/playground/scripts/get_group_button.gd b/addons/talo/samples/playground/scripts/get_group_button.gd index f5bc3c0..877eea0 100644 --- a/addons/talo/samples/playground/scripts/get_group_button.gd +++ b/addons/talo/samples/playground/scripts/get_group_button.gd @@ -7,7 +7,7 @@ func _on_pressed() -> void: %ResponseLabel.text = "group_id not set on GetGroupButton" return - var group = await Talo.player_groups.get_group(group_id) + var group := await Talo.player_groups.get_group(group_id) if group != null: %ResponseLabel.text = "%s has %s player(s)" % [group.name, group.count] else: diff --git a/addons/talo/samples/playground/scripts/toggle_network_button.gd b/addons/talo/samples/playground/scripts/toggle_network_button.gd index aba60d9..7386a07 100644 --- a/addons/talo/samples/playground/scripts/toggle_network_button.gd +++ b/addons/talo/samples/playground/scripts/toggle_network_button.gd @@ -7,7 +7,7 @@ func _set_text(offline: bool): text = "Go online" if offline else "Go offline" func _on_pressed() -> void: - var offline = Talo.offline_mode_enabled() + var offline := Talo.offline_mode_enabled() Talo.settings.set_value( "debug", diff --git a/addons/talo/samples/playground/scripts/track_event_button.gd b/addons/talo/samples/playground/scripts/track_event_button.gd index f6b32fa..45059de 100644 --- a/addons/talo/samples/playground/scripts/track_event_button.gd +++ b/addons/talo/samples/playground/scripts/track_event_button.gd @@ -1,9 +1,7 @@ extends Button @export var event_name: String -@export var event_props: Dictionary = { - "prop1": "value1" -} +@export var event_props: Dictionary = { prop1 = "value1" } @export var flush_immediately: bool func _on_pressed() -> void: diff --git a/addons/talo/samples/playground/scripts/update_save_button.gd b/addons/talo/samples/playground/scripts/update_save_button.gd index 4a94875..bba9627 100644 --- a/addons/talo/samples/playground/scripts/update_save_button.gd +++ b/addons/talo/samples/playground/scripts/update_save_button.gd @@ -5,15 +5,15 @@ func _on_pressed() -> void: push_error("No save currently loaded") return - var version = 0 + var version := 0 - var regex = RegEx.new() + var regex := RegEx.new() regex.compile("version\\s+(\\d+)") - var result = regex.search(Talo.saves.current.name) + var result := regex.search(Talo.saves.current.name) if result: version = int(result.get_string(1)) - var new_name = Talo.saves.current.name.replace("version %s" % version, "version %s" % (version + 1)) + var new_name := Talo.saves.current.name.replace("version %s" % version, "version %s" % (version + 1)) Talo.saves.update_current_save(new_name) diff --git a/addons/talo/samples/saves/loadable_button.gd b/addons/talo/samples/saves/loadable_button.gd index 5e7d515..b927f71 100644 --- a/addons/talo/samples/saves/loadable_button.gd +++ b/addons/talo/samples/saves/loadable_button.gd @@ -1,7 +1,7 @@ class_name LoadableButton extends TaloLoadable var button: Button -var clicks: int = 0 +var clicks: int func _ready() -> void: super() diff --git a/addons/talo/samples/saves/stateful_buttons_manager.gd b/addons/talo/samples/saves/stateful_buttons_manager.gd index e904ff0..5400fbf 100644 --- a/addons/talo/samples/saves/stateful_buttons_manager.gd +++ b/addons/talo/samples/saves/stateful_buttons_manager.gd @@ -7,7 +7,7 @@ func _ready() -> void: Talo.players.identify("username", username) func _on_identified(_player: TaloPlayer) -> void: - var saves = await Talo.saves.get_saves() + var saves := await Talo.saves.get_saves() if saves.is_empty(): await Talo.saves.create_save("save") diff --git a/addons/talo/talo_client.gd b/addons/talo/talo_client.gd index 74125f4..4293fdc 100644 --- a/addons/talo/talo_client.gd +++ b/addons/talo/talo_client.gd @@ -14,37 +14,41 @@ func _get_method_name(method: HTTPClient.Method): HTTPClient.METHOD_PATCH: return "PATCH" HTTPClient.METHOD_DELETE: return "DELETE" -func _simulate_offline_request(): - return [ +func _simulate_offline_request() -> TaloClientResponse: + return TaloClientResponse.new( HTTPRequest.RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray() - ] + ) + +func _build_response(http_request: HTTPRequest) -> TaloClientResponse: + var res = await http_request.request_completed + return TaloClientResponse.new(res[0], res[1], res[2], res[3]) func make_request(method: HTTPClient.Method, url: String, body: Dictionary = {}, headers: Array[String] = [], continuity: bool = false) -> Dictionary: - var continuity_timestamp = TaloTimeUtils.get_timestamp_msec() + var continuity_timestamp := TaloTimeUtils.get_timestamp_msec() - var full_url = url if continuity else _build_full_url(url) - var all_headers = headers if continuity else _build_headers(headers) - var request_body = "" if body.keys().is_empty() else JSON.stringify(body) + var full_url := url if continuity else _build_full_url(url) + var all_headers := headers if continuity else _build_headers(headers) + var request_body := "" if body.keys().is_empty() else JSON.stringify(body) - var http_request = HTTPRequest.new() + var http_request := HTTPRequest.new() add_child(http_request) http_request.name = "%s %s" % [_get_method_name(method), url] http_request.request(full_url, all_headers, method, request_body) - var res = _simulate_offline_request() if Talo.offline_mode_enabled() else await http_request.request_completed - var status = res[1] + var res := _simulate_offline_request() if Talo.offline_mode_enabled() else await _build_response(http_request) + var status := res.response_code - var response_body = res[3] - var json = JSON.new() + var response_body := res.body + var json := JSON.new() json.parse(response_body.get_string_from_utf8()) - if res[0] != HTTPRequest.RESULT_SUCCESS: + if res.result != HTTPRequest.RESULT_SUCCESS: json.set_data({ message = - "Request failed: result %s, details: https://docs.godotengine.org/en/stable/classes/class_httprequest.html#enum-httprequest-result" % res[0] + "Request failed: result %s, details: https://docs.godotengine.org/en/stable/classes/class_httprequest.html#enum-httprequest-result" % res.result }) if Talo.settings.get_value("logging", "requests", false): @@ -67,7 +71,7 @@ func make_request(method: HTTPClient.Method, url: String, body: Dictionary = {}, if ret.status >= 400: handle_error(ret) - if res[0] != HTTPRequest.RESULT_SUCCESS or ret.status >= 500: + if res.result != HTTPRequest.RESULT_SUCCESS or ret.status >= 500: Talo.continuity_manager.push_request(method, full_url, body, all_headers, continuity_timestamp) http_request.queue_free() @@ -89,7 +93,7 @@ func _build_headers(extra_headers: Array[String] = []) -> Array[String]: "X-Talo-Alias: %s" % Talo.current_alias.id ]) - var session_token = Talo.player_auth.session_manager.get_token() + var session_token := Talo.player_auth.session_manager.get_token() if session_token: headers.append("X-Talo-Session: %s" % session_token) @@ -115,3 +119,15 @@ func handle_error(res: Dictionary) -> void: return push_error("%s: Unknown error" % res.status) + +class TaloClientResponse: + var result: int + var response_code: int + var headers: PackedStringArray + var body: PackedByteArray + + func _init(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void: + self.result = result + self.response_code = response_code + self.headers = headers + self.body = body diff --git a/addons/talo/talo_manager.gd b/addons/talo/talo_manager.gd index 7dc02a2..ac62e6a 100644 --- a/addons/talo/talo_manager.gd +++ b/addons/talo/talo_manager.gd @@ -139,6 +139,6 @@ func _do_flush() -> void: events.flush() func _check_session() -> void: - var session_token = player_auth.session_manager.get_token() + var session_token := player_auth.session_manager.get_token() if not session_token.is_empty(): players.identify("talo", player_auth.session_manager.get_identifier()) diff --git a/addons/talo/talo_socket.gd b/addons/talo/talo_socket.gd index cde7532..0236c1b 100644 --- a/addons/talo/talo_socket.gd +++ b/addons/talo/talo_socket.gd @@ -7,10 +7,10 @@ class_name TaloSocket extends Node const DEFAULT_SOCKET_URL = "wss://api.trytalo.com" -var _socket = WebSocketPeer.new() -var _temp_socket_token = "" -var _socket_authenticated = false -var _identified = false +var _socket := WebSocketPeer.new() +var _temp_socket_token: String +var _socket_authenticated: bool +var _identified: bool ## Emitted when a message is received from the Talo Socket server. Not recommended for direct use. See the Talo docs for a list of responses and message structures. signal message_received(res: String, message: Dictionary) @@ -40,14 +40,14 @@ func _identify_player() -> void: send("v1.players.identify", payload) func _get_socket_url(ticket: String) -> String: - var url = Talo.settings.get_value("", "socket_url", DEFAULT_SOCKET_URL) + var url := Talo.settings.get_value("", "socket_url", DEFAULT_SOCKET_URL) return "%s/?ticket=%s" % [url, ticket] ## Open the connection to the Talo Socket server. A new ticket is created to authenticate the connection. func open_connection(): - var ticket = await Talo.socket_tickets.create_ticket() + var ticket := await Talo.socket_tickets.create_ticket() - var err = _socket.connect_to_url(_get_socket_url(ticket)) + var err := _socket.connect_to_url(_get_socket_url(ticket)) if err != OK: print_rich("[color=yellow]Warning: Failed connecting to the Talo Socket: %s[/color]" % err) @@ -83,11 +83,11 @@ func send(req: String, data: Dictionary = {}) -> int: })) func _get_json() -> String: - var pkt = _socket.get_packet() + var pkt := _socket.get_packet() return pkt.get_string_from_utf8() func _emit_message(message: String) -> void: - var json = JSON.new() + var json := JSON.new() json.parse(message) var res = json.get_data().res @@ -111,7 +111,7 @@ func _poll() -> void: _reset_socket() while _socket.get_ready_state() == _socket.STATE_OPEN and _socket.get_available_packet_count() > 0: - var message = _get_json() + var message := _get_json() _emit_message(message) func _process(_delta: float) -> void: diff --git a/addons/talo/utils/continuity_manager.gd b/addons/talo/utils/continuity_manager.gd index c60321a..87d3c5b 100644 --- a/addons/talo/utils/continuity_manager.gd +++ b/addons/talo/utils/continuity_manager.gd @@ -45,18 +45,18 @@ func _read_requests() -> Array: if not FileAccess.file_exists(_CONTINUITY_PATH): return [] - var content = FileAccess.open_encrypted_with_pass(_CONTINUITY_PATH, FileAccess.READ, Talo.crypto_manager.get_key()) + var content := FileAccess.open_encrypted_with_pass(_CONTINUITY_PATH, FileAccess.READ, Talo.crypto_manager.get_key()) if content == null: TaloCryptoManager.handle_undecryptable_file(_CONTINUITY_PATH, "continuity file") return [] - var json = JSON.new() + var json := JSON.new() json.parse(content.get_as_text()) return json.get_data() func _write_requests(): - var file = FileAccess.open_encrypted_with_pass(_CONTINUITY_PATH, FileAccess.WRITE, Talo.crypto_manager.get_key()) + var file := FileAccess.open_encrypted_with_pass(_CONTINUITY_PATH, FileAccess.WRITE, Talo.crypto_manager.get_key()) file.store_line(JSON.stringify(_requests)) func _on_timeout(): @@ -67,7 +67,7 @@ func _on_timeout(): if _requests.is_empty(): break - var req = _requests.pop_front() + var req := _requests.pop_front() _write_requests() var headers: Array[String] = ["Authorization: Bearer %s" % Talo.settings.get_value("", "access_key")] diff --git a/addons/talo/utils/crypto_manager.gd b/addons/talo/utils/crypto_manager.gd index af98f16..109bd1f 100644 --- a/addons/talo/utils/crypto_manager.gd +++ b/addons/talo/utils/crypto_manager.gd @@ -4,8 +4,8 @@ const _KEY_FILE_PATH = "user://ti.bin" static func handle_undecryptable_file(path: String, what: String) -> void: push_error("Failed to decrypt %s" % what) - var split_path = path.split(".") - var timestamp = TaloTimeUtils.get_timestamp_msec() + var split_path := path.split(".") + var timestamp := TaloTimeUtils.get_timestamp_msec() DirAccess.rename_absolute(path, "%s-invalid-%s.%s" % [split_path[0], timestamp, split_path[1]]) func _get_pass() -> String: @@ -20,10 +20,10 @@ func _init() -> void: push_error("Unable to create key file: cannot generate a suitable password") return - var crypto = Crypto.new() - var key = crypto.generate_random_bytes(32).hex_encode() + var crypto := Crypto.new() + var key := crypto.generate_random_bytes(32).hex_encode() - var file = FileAccess.open_encrypted_with_pass(_KEY_FILE_PATH, FileAccess.WRITE, _get_pass()) + var file := FileAccess.open_encrypted_with_pass(_KEY_FILE_PATH, FileAccess.WRITE, _get_pass()) file.store_line(key) file.close() @@ -31,11 +31,11 @@ func get_key() -> String: if not FileAccess.file_exists(_KEY_FILE_PATH): _init() - var file = FileAccess.open_encrypted_with_pass(_KEY_FILE_PATH, FileAccess.READ, _get_pass()) + var file := FileAccess.open_encrypted_with_pass(_KEY_FILE_PATH, FileAccess.READ, _get_pass()) if file == null: handle_undecryptable_file(_KEY_FILE_PATH, "crypto init file") return "" - var key = file.get_as_text() + var key := file.get_as_text() file.close() return key diff --git a/addons/talo/utils/saves_manager.gd b/addons/talo/utils/saves_manager.gd index f3ab591..e3d1cdf 100644 --- a/addons/talo/utils/saves_manager.gd +++ b/addons/talo/utils/saves_manager.gd @@ -12,12 +12,12 @@ func read_offline_saves() -> Array[TaloGameSave]: if not FileAccess.file_exists(_OFFLINE_SAVES_PATH): return [] - var content = FileAccess.open_encrypted_with_pass(_OFFLINE_SAVES_PATH, FileAccess.READ, Talo.crypto_manager.get_key()) + var content := FileAccess.open_encrypted_with_pass(_OFFLINE_SAVES_PATH, FileAccess.READ, Talo.crypto_manager.get_key()) if content == null: TaloCryptoManager.handle_undecryptable_file(_OFFLINE_SAVES_PATH, "offline saves file") return [] - var json = JSON.new() + var json := JSON.new() json.parse(content.get_as_text()) var res: Array[TaloGameSave] = [] @@ -26,15 +26,15 @@ func read_offline_saves() -> Array[TaloGameSave]: return res func write_offline_saves(offline_saves: Array[TaloGameSave]): - var saves = FileAccess.open_encrypted_with_pass(_OFFLINE_SAVES_PATH, FileAccess.WRITE, Talo.crypto_manager.get_key()) + var saves := FileAccess.open_encrypted_with_pass(_OFFLINE_SAVES_PATH, FileAccess.WRITE, Talo.crypto_manager.get_key()) saves.store_line(JSON.stringify(offline_saves.map(func (save: TaloGameSave): return save.to_dictionary()))) func sync_save(online_save: TaloGameSave, offline_save: TaloGameSave) -> TaloGameSave: - var online_updated_at = Time.get_unix_time_from_datetime_string(online_save.updated_at) - var offline_updated_at = Time.get_unix_time_from_datetime_string(offline_save.updated_at) + var online_updated_at := Time.get_unix_time_from_datetime_string(online_save.updated_at) + var offline_updated_at := Time.get_unix_time_from_datetime_string(offline_save.updated_at) if offline_updated_at > online_updated_at: - var save = await Talo.saves.replace_save_with_offline_save(offline_save) + var save := await Talo.saves.replace_save_with_offline_save(offline_save) delete_offline_save(offline_save) return save @@ -50,7 +50,7 @@ func sync_offline_saves(offline_saves: Array[TaloGameSave]) -> Array[TaloGameSav for offline_save in offline_saves: if offline_save.id < 0: - var save = await Talo.saves.create_save(offline_save.name, offline_save.content) + var save := await Talo.saves.create_save(offline_save.name, offline_save.content) delete_offline_save(offline_save) new_saves.push_back(save) @@ -62,21 +62,21 @@ func get_synced_saves(online_saves: Array[TaloGameSave]) -> Array[TaloGameSave]: if not offline_saves.is_empty(): for online_save in online_saves: - var filtered = offline_saves.filter(func (save: TaloGameSave): return save.id == online_save.id) + var filtered := offline_saves.filter(func (save: TaloGameSave): return save.id == online_save.id) if not filtered.is_empty(): - var save = await sync_save(online_save, filtered.front()) + var save := await sync_save(online_save, filtered.front()) saves.push_back(save) else: saves.push_back(online_save) - var synced_saves = await sync_offline_saves(offline_saves) + var synced_saves := await sync_offline_saves(offline_saves) saves.append_array(synced_saves) return saves func update_offline_saves(incoming_save: TaloGameSave) -> void: - var offline_saves: Array[TaloGameSave] = read_offline_saves() - var updated = false + var offline_saves := read_offline_saves() + var updated := false for i in range(offline_saves.size()): if offline_saves[i].id == incoming_save.id: @@ -118,7 +118,7 @@ func get_save_content() -> Dictionary: } func replace_save(new_save: TaloGameSave) -> void: - var existing_saves = all_saves.filter(func (save): return save.id == new_save.id) + var existing_saves := all_saves.filter(func (save): return save.id == new_save.id) if existing_saves.is_empty(): push_error("Save %s cannot be replaced as it does not exist" % new_save.id) all_saves.push_back(new_save) @@ -131,14 +131,14 @@ func replace_save(new_save: TaloGameSave) -> void: update_offline_saves(new_save) func get_latest_save() -> TaloGameSave: - var dupe = all_saves.duplicate() + var dupe := all_saves.duplicate() if dupe.is_empty(): return null dupe.sort_custom( func (a, b): - var time_a = Time.get_unix_time_from_datetime_string(a.updated_at) - var time_b = Time.get_unix_time_from_datetime_string(b.updated_at) + var time_a := Time.get_unix_time_from_datetime_string(a.updated_at) + var time_b := Time.get_unix_time_from_datetime_string(b.updated_at) return time_a > time_b ) diff --git a/addons/talo/utils/session_manager.gd b/addons/talo/utils/session_manager.gd index e5729f6..21c4f48 100644 --- a/addons/talo/utils/session_manager.gd +++ b/addons/talo/utils/session_manager.gd @@ -1,33 +1,33 @@ class_name TaloSessionManager extends RefCounted -var _verification_alias_id = "" +var _verification_alias_id: int const _SESSION_CONFIG_PATH = "user://talo_session.cfg" func _load_config(path: String) -> ConfigFile: - var config = ConfigFile.new() + var config := ConfigFile.new() config.load(path) return config func _save_session(session_token: String) -> void: - var config = ConfigFile.new() + var config := ConfigFile.new() config.set_value("session", "token", session_token) config.set_value("session", "identifier", Talo.current_alias.identifier) config.save(_SESSION_CONFIG_PATH) func clear_session() -> void: - var config = _load_config(_SESSION_CONFIG_PATH) + var config := _load_config(_SESSION_CONFIG_PATH) if config.has_section("session"): config.erase_section("session") config.save(_SESSION_CONFIG_PATH) func get_token() -> String: - var config = _load_config(_SESSION_CONFIG_PATH) + var config := _load_config(_SESSION_CONFIG_PATH) return config.get_value("session", "token", "") func get_identifier() -> String: - var config = _load_config(_SESSION_CONFIG_PATH) + var config := _load_config(_SESSION_CONFIG_PATH) return config.get_value("session", "identifier", "") func save_verification_alias_id(alias_id: int) -> void: