Skip to content

Commit

Permalink
Send JSON strings instead of dictionaries in signals
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 3, 2024
1 parent ff325b1 commit 2fe3975
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.7.0
### Send JSON strings instead of Dictionaries
The `gameLoaded` and `conflictEmitted` signals where sending an instance of the Dictionary class. Instead, they send a JSON string now, as suggested by @nepalisameer in [this issue](https://github.com/Iakobs/godot-play-game-services/issues/22).

## v1.6.0
### 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.
Expand Down
20 changes: 11 additions & 9 deletions plugin/export_scripts_template/autoloads/snapshots_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ func _ready() -> void:
func(is_saved: bool, save_data_name: String, save_data_description: String):
game_saved.emit(is_saved, save_data_name, save_data_description)
)
GodotPlayGameServices.android_plugin.gameLoaded.connect(func(dictionary: Dictionary):
game_loaded.emit(Snapshot.new(dictionary))
GodotPlayGameServices.android_plugin.gameLoaded.connect(func(json_data: String):
var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(json_data)
game_loaded.emit(Snapshot.new(safe_dictionary))
)
GodotPlayGameServices.android_plugin.conflictEmitted.connect(func(dictionary: Dictionary):
conflict_emitted.emit(SnapshotConflict.new(dictionary))
GodotPlayGameServices.android_plugin.conflictEmitted.connect(func(json_data: String):
var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(json_data)
conflict_emitted.emit(SnapshotConflict.new(safe_dictionary))
)
GodotPlayGameServices.android_plugin.snapshotsLoaded.connect(func(json_data: String):
var safe_array := GodotPlayGameServices.json_marshaller.safe_parse_array(json_data)
Expand All @@ -58,9 +60,9 @@ func _ready() -> void:
## [param allow_delete]: Whether or not to provide a delete overflow menu option for each snapshot in the selection UI.[br]
## [param max_snapshots]: The maximum number of snapshots to display in the UI. Use [constant DISPLAY_LIMIT_NONE] to display all snapshots.
func show_saved_games(
title: String,
allow_add_button: bool,
allow_delete: bool,
title: String,
allow_add_button: bool,
allow_delete: bool,
max_snapshots: int
) -> void:
if GodotPlayGameServices.android_plugin:
Expand All @@ -75,9 +77,9 @@ func show_saved_games(
## [param played_time_millis]: Optional. The played time of this snapshot in milliseconds.[br]
## [param progress_value]: Optional. The progress value for this snapshot.
func save_game(
file_name: String,
file_name: String,
description: String,
save_data: PackedByteArray,
save_data: PackedByteArray,
played_time_millis: int = 0,
progress_value: int = 0,
) -> void:
Expand Down
2 changes: 1 addition & 1 deletion plugin/export_scripts_template/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="GodotPlayGameServices"
description="A Godot 4.2 plugin for Google Play Game Services"
author="Jacob Ibáñez Sánchez"
version="1.5.0"
version="1.7.0"
script="export_plugin.gd"
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ object SnapshotSignals {
*
* @return A [Dictionary] representing a [com.google.android.gms.games.snapshot.Snapshot](https://developers.google.com/android/reference/com/google/android/gms/games/snapshot/Snapshot).
*/
val gameLoaded = SignalInfo("gameLoaded", Dictionary::class.java)
val gameLoaded = SignalInfo("gameLoaded", String::class.java)

/**
* This signal is emitted when saving or loading a game, whenever a conflict occurs.
*
* @return A [Dictionary] representing a [com.google.android.gms.games.SnapshotsClient.SnapshotConflict](https://developers.google.com/android/reference/com/google/android/gms/games/SnapshotsClient.SnapshotConflict).
*/
val conflictEmitted = SignalInfo("conflictEmitted", Dictionary::class.java)
val conflictEmitted = SignalInfo("conflictEmitted", String::class.java)

/**
* This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.loadSnapshots] method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class SnapshotsProxy(
godot,
GODOT_PLUGIN_NAME,
gameLoaded,
fromSnapshot(godot, snapshot)
Gson().toJson(fromSnapshot(godot, snapshot))
)
}
} else {
Expand Down Expand Up @@ -199,7 +199,7 @@ class SnapshotsProxy(
godot,
GODOT_PLUGIN_NAME,
conflictEmitted,
fromConflict(godot, it)
Gson().toJson(fromConflict(godot, it))
)
}
}
Expand Down

0 comments on commit 2fe3975

Please sign in to comment.