Skip to content

Commit

Permalink
Updated Godot's aar to 3.2.3. Added changes from cgisca#48 by Hamdiov…
Browse files Browse the repository at this point in the history
…ish.
  • Loading branch information
oneseedfruit committed Apr 19, 2021
1 parent a736d0d commit bdf7ddd
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 51 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Google Play Games Services Plugin for Godot
This is an Android Play Games Services plugin for Godot Game Engine 3.2.2+.
This is an Android Play Games Services plugin for Godot Game Engine 3.2.3+.

[![Android](https://img.shields.io/badge/Platform-Android-brightgreen.svg)](https://developer.android.com)
[![Godot](https://img.shields.io/badge/Godot%20Engine-3.2.2-blue.svg)](https://github.com/godotengine/godot/)
[![Godot](https://img.shields.io/badge/Godot%20Engine-3.2.3-blue.svg)](https://github.com/godotengine/godot/)
[![PGS](https://img.shields.io/badge/Play%20Games%20Services-20.0.1-green.svg)](https://developers.google.com/games/services/android/quickstart)
[![MIT license](https://img.shields.io/badge/License-MIT-yellowgreen.svg)](https://lbesson.mit-license.org/)

Expand Down Expand Up @@ -54,10 +54,16 @@ if Engine.has_singleton("GodotPlayGamesServices"):
# Initialize plugin by calling init method and passing to it a boolean to enable/disable displaying game pop-ups
var show_popups := true
play_games_services.init(show_popups)
var show_popups := true
var request_email := true
var request_profile := true
#The client id must be created in [the google console](https://console.cloud.google.com/apis/credentials), an OAuth 2.0 Client credentials of a Web application type
var request_token := "Client ID"
play_games_services.init(show_popups, request_email, request_profile, request_token)
# For enabling saved games functionality use below initialization instead
# play_games_services.initWithSavedGames(show_popups, "SavedGamesName")
# play_games_services.initWithSavedGames(show_popups, "SavedGamesName", request_email, request_profile, request_token)
# Connect callbacks (Use only those that you need)
play_games_services.connect("_on_sign_in_success", self, "_on_sign_in_success") # account_id: String
Expand Down Expand Up @@ -92,9 +98,16 @@ After what plugin was initialized you can use supported features
play_games_services.signIn()
# Callbacks:
func _on_sign_in_success(account_id: String) -> void:
pass
func _on_sign_in_success(userProfile_json: String) -> void:
var userProfile = parse_json(userProfile_json)
# The returned JSON contains an object of userProfile info.
# Use the following keys to access the fields
userProfile["displayName"] # The user's display name
userProfile["email"] # The user's email
userProfile["token"] # User token for backend use
userProfile["id"] # The user's id
func _on_sign_in_failed(error_code: int) -> void:
pass
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
buildToolsVersion "30.0.1"

defaultConfig {
minSdkVersion 16
Expand Down Expand Up @@ -34,10 +34,10 @@ android {
}

dependencies {
compileOnly project(":godot-lib.3.2.2.stable.release")
compileOnly project(":godot-lib.3.2.3.stable.release")
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.android.gms:play-services-games:20.0.1'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.google.android.gms:play-services-games:21.0.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.code.gson:gson:2.8.6'

testImplementation 'junit:junit:4.13'
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/io/cgisca/godot/gpgs/ConnectionController.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
package io.cgisca.godot.gpgs

import android.app.Activity
import android.util.Log
import android.util.Pair
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import io.cgisca.godot.gpgs.signin.UserProfile

class ConnectionController(
private val activity: Activity,
private var signInOptions: GoogleSignInOptions
) {

fun isConnected(): Pair<Boolean, String> {
fun isConnected(): Pair<Boolean, UserProfile> {
val userProfile = UserProfile(null, null, null, null)
val googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity)
var accId = ""
?: return Pair(false, userProfile)

googleSignInAccount?.id?.let {
accId = it
if (!googleSignInAccount.isExpired) {
Log.i("godot","Sign in data is valid")
userProfile.let {
it.displayName = googleSignInAccount.displayName
it.email = googleSignInAccount.email
it.token = googleSignInAccount.idToken
it.id = googleSignInAccount.id
}
return Pair(GoogleSignIn.hasPermissions(googleSignInAccount, *signInOptions.scopeArray), userProfile)
}else{
Log.i("godot","Sign in data has expired")
return Pair(false, userProfile)
}
return Pair(GoogleSignIn.hasPermissions(googleSignInAccount, *signInOptions.scopeArray), accId)
}
}
32 changes: 21 additions & 11 deletions app/src/main/java/io/cgisca/godot/gpgs/PlayGameServicesGodot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.Scope
import com.google.android.gms.games.SnapshotsClient
import com.google.android.gms.games.snapshot.SnapshotMetadata
import com.google.gson.Gson
import io.cgisca.godot.gpgs.accountinfo.PlayerInfoController
import io.cgisca.godot.gpgs.accountinfo.PlayerInfoListener
import io.cgisca.godot.gpgs.achievements.AchievementsController
Expand All @@ -22,6 +23,7 @@ import io.cgisca.godot.gpgs.savedgames.SavedGamesController
import io.cgisca.godot.gpgs.savedgames.SavedGamesListener
import io.cgisca.godot.gpgs.signin.SignInController
import io.cgisca.godot.gpgs.signin.SignInListener
import io.cgisca.godot.gpgs.signin.UserProfile
import io.cgisca.godot.gpgs.stats.PlayerStatsController
import io.cgisca.godot.gpgs.stats.PlayerStatsListener
import org.godotengine.godot.Godot
Expand Down Expand Up @@ -165,22 +167,30 @@ class PlayGameServicesGodot(godot: Godot) : GodotPlugin(godot), AchievementsList
}
}

fun init(enablePopups: Boolean) {
initialize(false, enablePopups, "DefaultGame")
fun init(enablePopups: Boolean, requestEmail: Boolean, requestProfile: Boolean, requestToken: String) {
initialize(false, enablePopups, "DefaultGame", requestEmail, requestProfile, requestToken)
}

fun initWithSavedGames(enablePopups: Boolean, saveGameName: String) {
initialize(true, enablePopups, saveGameName)
fun initWithSavedGames(enablePopups: Boolean, saveGameName: String, requestEmail: Boolean, requestProfile: Boolean, requestToken: String) {
initialize(true, enablePopups, saveGameName, requestEmail, requestProfile, requestToken)
}

private fun initialize(enableSaveGamesFunctionality: Boolean, enablePopups: Boolean, saveGameName: String) {
private fun initialize(enableSaveGamesFunctionality: Boolean, enablePopups: Boolean, saveGameName: String,
requestEmail: Boolean, requestProfile: Boolean, requestToken: String) {
this.saveGameName = saveGameName
val signInOptions = if (enableSaveGamesFunctionality) {
val signInOptions = run {
val signInOptionsBuilder = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
signInOptionsBuilder.requestScopes(Scope(Scopes.DRIVE_APPFOLDER))
if (enableSaveGamesFunctionality)
signInOptionsBuilder.requestScopes(Scope(Scopes.DRIVE_APPFOLDER))
if (requestToken.isNotEmpty()) {
signInOptionsBuilder.requestIdToken(requestToken)
}
if (requestEmail)
signInOptionsBuilder.requestEmail()
if (requestProfile)
signInOptionsBuilder.requestProfile()
signInOptionsBuilder.requestId()
signInOptionsBuilder.build()
} else {
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
}

connectionController = ConnectionController(godot as Activity, signInOptions)
Expand Down Expand Up @@ -405,8 +415,8 @@ class PlayGameServicesGodot(godot: Godot) : GodotPlugin(godot), AchievementsList
emitSignal(SIGNAL_SAVED_GAME_CREATE_SNAPSHOT.name, currentSaveName)
}

override fun onSignedInSuccessfully(accountId: String) {
emitSignal(SIGNAL_SIGN_IN_SUCCESSFUL.name, accountId)
override fun onSignedInSuccessfully(userProfile: UserProfile) {
emitSignal(SIGNAL_SIGN_IN_SUCCESSFUL.name, Gson().toJson(userProfile))
}

override fun onSignInFailed(statusCode: Int) {
Expand Down
31 changes: 22 additions & 9 deletions app/src/main/java/io/cgisca/godot/gpgs/signin/SignInController.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.cgisca.godot.gpgs.signin

import android.app.Activity
import android.util.Log
import android.util.Pair
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
Expand All @@ -25,22 +26,29 @@ class SignInController(
}

fun signIn(googleSignInClient: GoogleSignInClient) {
val connection: Pair<Boolean, String> = connectionController.isConnected()
val userProfile = UserProfile(null, null, null, null)
val connection: Pair<Boolean, UserProfile> = connectionController.isConnected()
if (connection.first) {
Log.i("godot","Using cached signin data")
signInListener.onSignedInSuccessfully(connection.second)
enablePopUps()
} else {
Log.i("godot","Using new signin data")
googleSignInClient
.silentSignIn()
.addOnCompleteListener(activity) { task ->
if (task.isSuccessful) {
val googleSignInAccount = task.result
var accId = ""
googleSignInAccount?.id?.let {
accId = it
if (googleSignInAccount != null) {
userProfile.let {
it.displayName = googleSignInAccount.displayName
it.email = googleSignInAccount.email
it.token = googleSignInAccount.idToken
it.id = googleSignInAccount.id
}
}

signInListener.onSignedInSuccessfully(accId)
signInListener.onSignedInSuccessfully(userProfile)
enablePopUps()
} else {
val intent = googleSignInClient.signInIntent
Expand All @@ -51,14 +59,19 @@ class SignInController(
}

fun onSignInActivityResult(googleSignInResult: GoogleSignInResult?) {
val userProfile = UserProfile(null, null, null, null)
if (googleSignInResult != null && googleSignInResult.isSuccess) {
val googleSignInAccount = googleSignInResult.signInAccount
var accId = ""
googleSignInAccount?.id?.let {
accId = it
if (googleSignInAccount != null) {
userProfile.let {
it.displayName = googleSignInAccount.displayName
it.email = googleSignInAccount.email
it.token = googleSignInAccount.idToken
it.id = googleSignInAccount.id
}
}
enablePopUps()
signInListener.onSignedInSuccessfully(accId)
signInListener.onSignedInSuccessfully(userProfile)
} else {
var statusCode = Int.MIN_VALUE
googleSignInResult?.status?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.cgisca.godot.gpgs.signin

interface SignInListener {
fun onSignedInSuccessfully(accountId: String)
fun onSignedInSuccessfully(userProfile: UserProfile)
fun onSignInFailed(statusCode: Int)
fun onSignOutSuccess()
fun onSignOutFailed()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/cgisca/godot/gpgs/signin/UserProfile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.cgisca.godot.gpgs.signin

data class UserProfile(var displayName: String?, var email: String?, var token: String?, var id: String?) {
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.0"
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -23,4 +23,4 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
11 changes: 7 additions & 4 deletions demo/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func _ready():
play_games_services.connect("_on_player_info_loaded", self, "_on_player_info_loaded")
play_games_services.connect("_on_player_info_loading_failed", self, "_on_player_info_loading_failed")

play_games_services.init(true)
# play_games_services.initWithSavedGames(true, "SAVE_GAME_NAME") # Use this init if you want saved games feature to be enabled
play_games_services.init(true,false,false,"")
# play_games_services.init(true,true,false,"") # Use this init if you want to get email of the player
# play_games_services.init(true,true,true,"") # Use this init if you want to get email and profile data of the player
# play_games_services.initWithSavedGames(true, "SAVE_GAME_NAME",false, false, "") # Use this init if you want saved games feature to be enabled


# Sign-in/sign-out methods
Expand Down Expand Up @@ -127,8 +129,9 @@ func load_player_info() -> void:

# CALLBACKS
# Sign-in / sign-out callbacks
func _on_sign_in_success(account_id: String) -> void:
print("Sign in success %s"%account_id)
func _on_sign_in_success(userProfile_json: String) -> void:
var userProfile = parse_json(userProfile_json)
print("Sign in success ",userProfile)

func _on_sign_in_failed(error_code: int) -> void:
print("Sign in failed %s"%error_code)
Expand Down
2 changes: 1 addition & 1 deletion demo/android/.build_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2.stable
3.2.3.stable
2 changes: 1 addition & 1 deletion demo/android/plugins/GodotPlayGamesServices.gdap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ binary="GodotPlayGamesServices.release.aar"

[dependencies]

remote=["com.google.android.gms:play-services-games:20.0.1", "com.google.android.gms:play-services-auth:18.1.0", "com.google.code.gson:gson:2.8.6"]
remote=["com.google.android.gms:play-services-games:21.0.0", "com.google.android.gms:play-services-auth:19.0.0", "com.google.code.gson:gson:2.8.6"]


Binary file modified demo/android/plugins/GodotPlayGamesServices.release.aar
Binary file not shown.
2 changes: 0 additions & 2 deletions godot-lib.3.2.2.stable.release/build.gradle

This file was deleted.

Binary file not shown.
2 changes: 2 additions & 0 deletions godot-lib.3.2.3.stable.release/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('godot-lib.3.2.3.stable.release.aar'))
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':godot-lib.3.2.2.stable.release'
include ':app', ':godot-lib.3.2.3.stable.release'

0 comments on commit bdf7ddd

Please sign in to comment.