diff --git a/plugin/demo/MainMenu.gd b/plugin/demo/MainMenu.gd index 83215e2..4cc6d50 100644 --- a/plugin/demo/MainMenu.gd +++ b/plugin/demo/MainMenu.gd @@ -4,9 +4,9 @@ extends Control func _ready() -> void: if GodotPlayGameServices.android_plugin: - SignInClient.is_user_authenticated.connect(func(is_authenticated: bool): + SignInClient.user_authenticated.connect(func(is_authenticated: bool): print("Is user authenticated?: %s" % is_authenticated) ) button.pressed.connect(func(): - GodotPlayGameServices.android_plugin.showAllLeaderboards() + GodotPlayGameServices.android_plugin.showAchievements() ) diff --git a/plugin/export_scripts_template/autoloads/sign_in_client.gd b/plugin/export_scripts_template/autoloads/sign_in_client.gd index 955cd7b..59d2cef 100644 --- a/plugin/export_scripts_template/autoloads/sign_in_client.gd +++ b/plugin/export_scripts_template/autoloads/sign_in_client.gd @@ -1,17 +1,17 @@ extends Node -signal is_user_authenticated -signal is_user_signed_in +signal user_authenticated +signal user_signed_in func _ready() -> void: connect_signals() func connect_signals() -> void: - GodotPlayGameServices.android_plugin.isUserAuthenticated.connect(func(is_authenticated: bool): - is_user_authenticated.emit(is_authenticated) + GodotPlayGameServices.android_plugin.userAuthenticated.connect(func(is_authenticated: bool): + user_authenticated.emit(is_authenticated) ) - GodotPlayGameServices.android_plugin.isUserSignedIn.connect(func(is_signed_in: bool): - is_user_signed_in.emit(is_signed_in) + GodotPlayGameServices.android_plugin.userSignedIn.connect(func(is_signed_in: bool): + user_signed_in.emit(is_signed_in) ) func is_authenticated() -> void: diff --git a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/GodotAndroidPlugin.kt b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/GodotAndroidPlugin.kt index 3099ceb..bcc78bb 100644 --- a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/GodotAndroidPlugin.kt +++ b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/GodotAndroidPlugin.kt @@ -57,7 +57,7 @@ class GodotAndroidPlugin(godot: Godot) : GodotPlugin(godot) { * Use this method to check if the user is already authenticated. If the user is authenticated, * a popup will be shown on screen. * - * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.isUserAuthenticated] signal. + * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.userAuthenticated] signal. */ @UsedByGodot fun isAuthenticated() = signInProxy.isAuthenticated() @@ -65,7 +65,7 @@ class GodotAndroidPlugin(godot: Godot) : GodotPlugin(godot) { /** * Use this method to provide a manual way to the user for signing in. * - * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.isUserSignedIn] signal. + * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.userSignedIn] signal. */ @UsedByGodot fun signIn() = signInProxy.signIn() @@ -74,26 +74,54 @@ class GodotAndroidPlugin(godot: Godot) : GodotPlugin(godot) { * Use this method to increment a given achievement in the given amount. For normal achievements, * use the [unlockAchievement] method instead. * - * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.isAchievementUnlocked] signal. + * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementUnlocked] signal. * - * @param achievementId The achievement Id. + * @param achievementId The achievement id. * @param amount The number of steps to increment by. Must be greater than 0. */ @UsedByGodot fun incrementAchievement(achievementId: String, amount: Int) = achievementsProxy.incrementAchievement(achievementId, amount) + /** + * Call this method and subscribe to the emitted signal to receive the list of the game + * achievements in JSON format. The JSON received from the [com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementsLoaded] + * signal contains a representation of the [com.google.android.gms.games.achievement.Achievement](https://developers.google.com/android/reference/com/google/android/gms/games/achievement/Achievement) class. + * + * @param forceReload If true, this call will clear any locally cached data and attempt to fetch + * the latest data from the server. + */ @UsedByGodot fun loadAchievements(forceReload: Boolean) = achievementsProxy.loadAchievements(forceReload) + /** + * Use this method to reveal a hidden achievement to the current signed player. If the achievement + * is already unlocked, this method will have no effect. + * + * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementRevealed] signal. + * + * @param achievementId The achievement id. + */ @UsedByGodot fun revealAchievement(achievementId: String) = achievementsProxy.revealAchievement(achievementId) + /** + * Use this method to open a new window with the achievements of the game, and the progress of + * the player to unlock those achievements. + */ @UsedByGodot fun showAchievements() = achievementsProxy.showAchievements() + /** + * Immediately unlocks the given achievement for the signed in player. If the achievement is + * secret, it will be revealed to the player. + * + * The method emits the [com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementUnlocked] signal. + * + * @param achievementId The achievement id. + */ @UsedByGodot fun unlockAchievement(achievementId: String) = achievementsProxy.unlockAchievement(achievementId) diff --git a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/achievements/AchievementsProxy.kt b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/achievements/AchievementsProxy.kt index f962695..76b331a 100644 --- a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/achievements/AchievementsProxy.kt +++ b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/achievements/AchievementsProxy.kt @@ -6,13 +6,9 @@ import com.google.android.gms.games.AchievementsClient import com.google.android.gms.games.PlayGames import com.google.gson.Gson import com.jacobibanez.plugin.android.godotplaygameservices.BuildConfig -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.isAchievementUnlocked -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.loadAchievementsFailure -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.loadAchievementsSuccess -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.revealAchievementFailure -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.revealAchievementSuccess -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.unlockAchievementFailure -import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.unlockAchievementSuccess +import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementUnlocked +import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementsLoaded +import com.jacobibanez.plugin.android.godotplaygameservices.signals.AchievementsSignals.achievementRevealed import org.godotengine.godot.Dictionary import org.godotengine.godot.Godot import org.godotengine.godot.plugin.GodotPlugin.emitSignal @@ -34,14 +30,14 @@ class AchievementsProxy( tag, "Achievement $achievementId incremented successfully. Unlocked? ${task.result}" ) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, isAchievementUnlocked, task.result) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementUnlocked, task.result) } else { Log.e( tag, "Achievement $achievementId not incremented. Cause: ${task.exception}", task.exception ) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, isAchievementUnlocked, false) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementUnlocked, false) } } } @@ -62,10 +58,11 @@ class AchievementsProxy( emptyList() } - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, loadAchievementsSuccess, Gson().toJson(achievements)) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementsLoaded, Gson().toJson(achievements)) } else { Log.e(tag, "Failed to load achievements. Cause: ${task.exception}", task.exception) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, loadAchievementsFailure) + val emptyResponse: List = listOf(Dictionary()) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementsLoaded, Gson().toJson(emptyResponse)) } } } @@ -75,14 +72,14 @@ class AchievementsProxy( achievementsClient.revealImmediate(achievementId).addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(tag, "Achievement $achievementId revealed") - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, revealAchievementSuccess) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementRevealed, true) } else { Log.e( tag, "Achievement $achievementId not revealed. Cause: ${task.exception}", task.exception ) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, revealAchievementFailure) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementRevealed, false) } } } @@ -102,14 +99,14 @@ class AchievementsProxy( achievementsClient.unlockImmediate(achievementId).addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(tag, "Achievement with id $achievementId unlocked") - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, unlockAchievementSuccess) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementUnlocked, true) } else { Log.e( tag, "Error unlocking achievement $achievementId. Cause: ${task.exception}", task.exception ) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, unlockAchievementFailure) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, achievementUnlocked, false) } } } diff --git a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signals/Signals.kt b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signals/Signals.kt index 9587463..dcbce29 100644 --- a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signals/Signals.kt +++ b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signals/Signals.kt @@ -4,16 +4,12 @@ import org.godotengine.godot.plugin.SignalInfo /** @suppress */ fun getSignals(): MutableSet = mutableSetOf( - SignInSignals.isUserAuthenticated, - SignInSignals.isUserSignedIn, + SignInSignals.userAuthenticated, + SignInSignals.userSignedIn, - AchievementsSignals.isAchievementUnlocked, - AchievementsSignals.loadAchievementsSuccess, - AchievementsSignals.loadAchievementsFailure, - AchievementsSignals.revealAchievementSuccess, - AchievementsSignals.revealAchievementFailure, - AchievementsSignals.unlockAchievementSuccess, - AchievementsSignals.unlockAchievementFailure, + AchievementsSignals.achievementUnlocked, + AchievementsSignals.achievementsLoaded, + AchievementsSignals.achievementRevealed, LeaderboardSignals.submitScoreSuccess, LeaderboardSignals.submitScoreFailure, @@ -31,7 +27,7 @@ object SignInSignals { * * @return `true` if the user is authenticated. `false` otherwise. */ - val isUserAuthenticated = SignalInfo("isUserAuthenticated", Boolean::class.javaObjectType) + val userAuthenticated = SignalInfo("userAuthenticated", Boolean::class.javaObjectType) /** * This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.signIn] method. @@ -39,7 +35,7 @@ object SignInSignals { * @return `true` if the user is signed in. `false` otherwise. * */ - val isUserSignedIn = SignalInfo("isUserSignedIn", Boolean::class.javaObjectType) + val userSignedIn = SignalInfo("userSignedIn", Boolean::class.javaObjectType) } /** @@ -47,17 +43,26 @@ object SignInSignals { */ object AchievementsSignals { /** - * This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.incrementAchievement] method. + * This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.incrementAchievement] + * or [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.unlockAchievement] methods. * * @return `true` if the achievement is unlocked. `false` otherwise. */ - val isAchievementUnlocked = SignalInfo("isAchievementUnlocked", Boolean::class.javaObjectType) - val loadAchievementsSuccess = SignalInfo("loadAchievementsSuccess", String::class.java) - val loadAchievementsFailure = SignalInfo("loadAchievementsFailure") - val revealAchievementSuccess = SignalInfo("revealAchievement") - val revealAchievementFailure = SignalInfo("revealAchievement") - val unlockAchievementSuccess = SignalInfo("unlockAchievementSuccess") - val unlockAchievementFailure = SignalInfo("unlockAchievementFailure") + val achievementUnlocked = SignalInfo("achievementUnlocked", Boolean::class.javaObjectType) + + /** + * This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.loadAchievements] method. + * + * @return A JSON with a list of [com.google.android.gms.games.achievement.Achievement](https://developers.google.com/android/reference/com/google/android/gms/games/achievement/Achievement). + */ + val achievementsLoaded = SignalInfo("achievementsLoaded", String::class.java) + + /** + * This signal is emitted when calling the [com.jacobibanez.plugin.android.godotplaygameservices.GodotAndroidPlugin.revealAchievement] method. + * + * @return `true` if the achievement is revealed. `false` otherwise. + */ + val achievementRevealed = SignalInfo("achievementRevealed", Boolean::class.javaObjectType) } /** diff --git a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signin/SignInProxy.kt b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signin/SignInProxy.kt index 4835237..2d05b34 100644 --- a/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signin/SignInProxy.kt +++ b/plugin/src/main/java/com/jacobibanez/plugin/android/godotplaygameservices/signin/SignInProxy.kt @@ -4,8 +4,8 @@ import android.util.Log import com.google.android.gms.games.GamesSignInClient import com.google.android.gms.games.PlayGames import com.jacobibanez.plugin.android.godotplaygameservices.BuildConfig -import com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.isUserAuthenticated -import com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.isUserSignedIn +import com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.userAuthenticated +import com.jacobibanez.plugin.android.godotplaygameservices.signals.SignInSignals.userSignedIn import org.godotengine.godot.Godot import org.godotengine.godot.plugin.GodotPlugin.emitSignal @@ -24,7 +24,7 @@ class SignInProxy( emitSignal( godot, BuildConfig.GODOT_PLUGIN_NAME, - isUserAuthenticated, + userAuthenticated, task.result.isAuthenticated ) } else { @@ -32,7 +32,7 @@ class SignInProxy( emitSignal( godot, BuildConfig.GODOT_PLUGIN_NAME, - isUserAuthenticated, + userAuthenticated, false ) } @@ -44,10 +44,10 @@ class SignInProxy( gamesSignInClient.signIn().addOnCompleteListener { task -> if (task.isSuccessful) { Log.d(tag, "User signed in: ${task.result.isAuthenticated}") - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, isUserSignedIn, task.result.isAuthenticated) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, userSignedIn, task.result.isAuthenticated) } else { Log.e(tag, "User not signed in. Cause: ${task.exception}", task.exception) - emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, isUserSignedIn, false) + emitSignal(godot, BuildConfig.GODOT_PLUGIN_NAME, userSignedIn, false) } } }