Skip to content

Commit

Permalink
Add extra parameter to loadGame method
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Ibáñez Sánchez <jacobibanez@jacobibanez.com>
  • Loading branch information
Iakobs committed Mar 2, 2024
1 parent 33f64a8 commit 10634bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The [loadPlayerCenteredScores](https://developers.google.com/android/reference/c
### 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.

### Add new parameter to loadGame method
Added the `createIfNotFound` parameter to the `loadGame` method, with a default value of `false` to not break backwards compatibility. This parameter creates a new snapshot if the file name does not exist.

## 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.
Expand Down
7 changes: 4 additions & 3 deletions plugin/export_scripts_template/autoloads/snapshots_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ func save_game(
## [br]
## This method emits the [signal game_loaded] signal.[br]
## [br]
## [param fileName]: The name of the save file. Must be between 1 and 100 non-URL-reserved charactes (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~").
func load_game(file_name: String) -> void:
## [param fileName]: The name of the save file. Must be between 1 and 100 non-URL-reserved charactes (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~").[br]
## [param create_if_not_found]: False by default. If true, the snapshot will be created if one cannot be found.
func load_game(file_name: String, create_if_not_found := false) -> void:
if GodotPlayGameServices.android_plugin:
GodotPlayGameServices.android_plugin.loadGame(file_name)
GodotPlayGameServices.android_plugin.loadGame(file_name, create_if_not_found)

## Loads the list of [SnapshotMetadata] of the current signed in player.[br]
## [br]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ class GodotAndroidPlugin(godot: Godot) : GodotPlugin(godot) {
*
* @param fileName The name of the save file. Must be between 1 and 100 non-URL-reserved
* characters (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~").
* @param createIfNotFound False by default. If true, the snapshot will be created if one cannot be found.
*/
@UsedByGodot
fun loadGame(fileName: String) = snapshotsProxy.loadGame(fileName)
fun loadGame(fileName: String, createIfNotFound: Boolean = false) =
snapshotsProxy.loadGame(fileName, createIfNotFound)

/**
* Loads the list of [com.google.android.gms.games.snapshot.SnapshotMetadata](https://developers.google.com/android/reference/com/google/android/gms/games/snapshot/SnapshotMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SnapshotsProxy(
if (intent.hasExtra(EXTRA_SNAPSHOT_METADATA)) {
val snapshotMetadata = intent.extras
?.get(EXTRA_SNAPSHOT_METADATA) as SnapshotMetadata
loadGame(snapshotMetadata.uniqueName)
loadGame(snapshotMetadata.uniqueName, false)
}
}
}
Expand Down Expand Up @@ -93,9 +93,9 @@ class SnapshotsProxy(
}
}

fun loadGame(fileName: String) {
fun loadGame(fileName: String, createIfNotFound: Boolean) {
Log.d(tag, "Loading snapshot with name $fileName.")
snapshotsClient.open(fileName, false, RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED)
snapshotsClient.open(fileName, createIfNotFound, RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val dataOrConflict = task.result
Expand Down

0 comments on commit 10634bc

Please sign in to comment.