From fd87c998ca937d3bfcee253ae30f2840e289a0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Ib=C3=A1=C3=B1ez=20S=C3=A1nchez?= Date: Sat, 2 Mar 2024 15:41:05 +0100 Subject: [PATCH] Add loadSnapshots method to the plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jacob Ibáñez Sánchez --- CHANGELOG.md | 3 ++ .../snapshots/SnapshotsProxy.kt | 36 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d270b..3aed5de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### Load Snapshots The [loadPlayerCenteredScores](https://developers.google.com/android/reference/com/google/android/gms/games/SnapshotsClient#load(boolean)) method from Google's API has been added, returning the list of Snapshots for the current signed in player. +### Fix crash when loading non existing save game +When calling the `loadGame` method with a non existing file name, the app crashed. This is fixed now, the app just prints a log with the error and continues execution. + ## v1.5.0 ### Order of autoloads The autoloads where causing errors on first launch of the project, due to the load order and dependencies between them. The load order has now been fixed to avoid this errors. Also, the plugin is now disabled by default in the demo project. Look at the [demo project documentation](https://github.com/Iakobs/godot-play-game-services/tree/main/plugin/demo) for further info. diff --git a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/snapshots/SnapshotsProxy.kt b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/snapshots/SnapshotsProxy.kt index 17adfa8..3b6b79b 100644 --- a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/snapshots/SnapshotsProxy.kt +++ b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/snapshots/SnapshotsProxy.kt @@ -96,25 +96,23 @@ class SnapshotsProxy( fun loadGame(fileName: String) { Log.d(tag, "Loading snapshot with name $fileName.") snapshotsClient.open(fileName, false, RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED) - .addOnFailureListener { exception -> - Log.e(tag, "Error while opening Snapshot $fileName for loading.", exception); - }.continueWith { task -> - val dataOrConflict = task.result - if (dataOrConflict.isConflict) { - handleConflict(dataOrConflict.conflict) - return@continueWith null - } - dataOrConflict.data?.let { snapshot -> - return@continueWith snapshot - } - }.addOnCompleteListener { task -> - task.result?.let { snapshot -> - emitSignal( - godot, - GODOT_PLUGIN_NAME, - gameLoaded, - fromSnapshot(godot, snapshot) - ) + .addOnCompleteListener { task -> + if (task.isSuccessful) { + val dataOrConflict = task.result + if (dataOrConflict.isConflict) { + handleConflict(dataOrConflict.conflict) + return@addOnCompleteListener + } + dataOrConflict.data?.let { snapshot -> + emitSignal( + godot, + GODOT_PLUGIN_NAME, + gameLoaded, + fromSnapshot(godot, snapshot) + ) + } + } else { + Log.e(tag, "Error while opening Snapshot $fileName for loading. Cause: ${task.exception}") } } }