├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── frogsquare │ │ │ └── googleplay │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── frogsquare │ │ └── googleplay │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── GooglePlay ├── .gitignore ├── consumer-rules.pro ├── src │ ├── main │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── frogsquare │ │ │ │ └── googleplay │ │ │ │ ├── Common.kt │ │ │ │ └── GDPlayService.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── frogsquare │ │ │ └── googleplay │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── frogsquare │ │ └── googleplay │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── PlayCoreLibrary ├── .gitignore ├── consumer-rules.pro ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── kotlin │ │ │ └── com │ │ │ └── frogsquare │ │ │ └── playcorelibrary │ │ │ └── GDPlayCoreLibrary.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── frogsquare │ │ │ └── playcorelibrary │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── frogsquare │ │ └── playcorelibrary │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /GooglePlay/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /GooglePlay/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PlayCoreLibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /PlayCoreLibrary/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Godot GooglePlay Plugin 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrogSquare/GDPlayService/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Nov 09 09:23:15 IST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /GooglePlay/src/main/kotlin/com/frogsquare/googleplay/Common.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | object Common { 4 | const val RC_ACHIEVEMENT: Int = 0x0002 5 | const val RC_LEADERBOARD: Int = 0x0003 6 | 7 | const val RC_GOOGLE: Int = 0x0004 8 | 9 | const val DEFAULT_CHANNEL_ID: String = "default" 10 | } -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | 17 | *.aar 18 | 19 | .idea/ 20 | google-services.json 21 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() // Warning: this repository is going to shut down soon 7 | } 8 | } 9 | rootProject.name = "Godot GooglePlay Plugin" 10 | include ':app' 11 | include ':GooglePlay' 12 | include ':PlayCoreLibrary' 13 | -------------------------------------------------------------------------------- /GooglePlay/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /PlayCoreLibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/test/java/com/frogsquare/googleplay/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /GooglePlay/src/test/java/com/frogsquare/googleplay/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /PlayCoreLibrary/src/test/java/com/frogsquare/playcorelibrary/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.playcorelibrary 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/frogsquare/googleplay/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.frogsquare.googleplay", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /GooglePlay/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /GooglePlay/src/androidTest/java/com/frogsquare/googleplay/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.frogsquare.googleplay.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /PlayCoreLibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /PlayCoreLibrary/src/androidTest/java/com/frogsquare/playcorelibrary/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.playcorelibrary 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.frogsquare.playcorelibrary.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 31 8 | 9 | defaultConfig { 10 | applicationId "com.frogsquare.googleplay" 11 | minSdk 21 12 | targetSdk 31 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | kotlinOptions { 30 | jvmTarget = '1.8' 31 | } 32 | } 33 | 34 | dependencies { 35 | 36 | implementation 'androidx.core:core-ktx:1.7.0' 37 | implementation 'androidx.appcompat:appcompat:1.3.1' 38 | implementation 'com.google.android.material:material:1.4.0' 39 | testImplementation 'junit:junit:4.+' 40 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 41 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 42 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /PlayCoreLibrary/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 31 8 | 9 | defaultConfig { 10 | minSdk 21 11 | targetSdk 31 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | kotlinOptions { 30 | jvmTarget = '1.8' 31 | } 32 | } 33 | 34 | dependencies { 35 | compileOnly fileTree(dir: '../libs', include: ['godot-lib*.aar']) 36 | 37 | implementation("com.google.android.play:core-ktx:1.8.1") 38 | 39 | implementation 'androidx.core:core-ktx:1.7.0' 40 | implementation 'androidx.appcompat:appcompat:1.4.1' 41 | implementation 'com.google.android.material:material:1.5.0' 42 | testImplementation 'junit:junit:4.+' 43 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 44 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 45 | } -------------------------------------------------------------------------------- /GooglePlay/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 31 8 | 9 | defaultConfig { 10 | minSdk 21 11 | targetSdk 31 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | kotlinOptions { 30 | jvmTarget = '1.8' 31 | } 32 | } 33 | 34 | dependencies { 35 | compileOnly fileTree(dir: '../libs', include: ['godot-lib*.aar']) 36 | 37 | implementation 'com.google.android.gms:play-services-auth:19.2.0' 38 | implementation 'com.google.android.gms:play-services-games:21.0.0' 39 | 40 | implementation 'androidx.core:core-ktx:1.7.0' 41 | implementation 'androidx.appcompat:appcompat:1.3.1' 42 | implementation 'com.google.android.material:material:1.4.0' 43 | testImplementation 'junit:junit:4.+' 44 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 46 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GDPlayService 2 | Android plugin to implement Google Play Service into your game 3 | 4 | 5 | [![Platform](https://img.shields.io/badge/Platform-Android-green.svg)](https://github.com/FrogSquare/GDFirebase) 6 | [![GodotEngine](https://img.shields.io/badge/Godot_Engine-3.3-blue.svg)](https://github.com/godotengine/godot) 7 | ![GitHub](https://img.shields.io/github/license/FrogSquare/GDPlayService) 8 | 9 | # Depends on 10 | 11 | > Godot game engine: `git clone https://github.com/godotengine/godot` 12 | 13 | # Available Features 14 | 15 | > Login / Logout 16 | 17 | > Player Info 18 | 19 | > Achievements 20 | 21 | > Leaderboard 22 | 23 | > In-app Update 24 | 25 | # Getting Started 26 | * Install Android build Template to your `GAME-PROJECT` 27 | 28 | ``` 29 | func _ready(): 30 | if Engine.has_singleton("GDPlayService"): 31 | google = Engine.get_singleton("GDPlayService") 32 | google.initialize() 33 | ``` 34 | 35 | #### Login / Logout 36 | ``` 37 | fun isConnected(): Boolean 38 | fun signIn() 39 | fun signOut() 40 | fun getPlayerInfo(): Dictionary 41 | ``` 42 | 43 | #### Achievements 44 | ``` 45 | fun increaseAchievement(name: String, value: Int) 46 | fun unlockAchievement(name: String) 47 | fun showAchievements() 48 | ``` 49 | 50 | #### Leaderboard 51 | ``` 52 | fun loadTopScore(name: String, max: Int) 53 | fun loadCurrentPlayerScore(name: String) 54 | fun submitScore(name: String, value: Int) 55 | fun showLeaderboard(name: String) 56 | fun showAllLeaderboards() 57 | ``` 58 | 59 | #### Record 60 | ``` 61 | fun canRecord(): Boolean 62 | fun record() 63 | ``` 64 | 65 | ### GDPlayCoreLibrary 66 | Implements In-App Update 67 | ``` 68 | func _ready(): 69 | if Engine.has_singleton("GDPlayCoreLibrary"): 70 | playCore = Engine.get_singleton("GDPlayCoreLibrary") 71 | playCore.startAppUpdatedManager({ 72 | immediate = false, 73 | flexible_days = 3 74 | }) 75 | playCore.connect("update_available", self, "_update_available") 76 | 77 | func _update_available(data: Dictionary): 78 | if data.mode == "IMMEDIATE": 79 | playCore.startUpdateImmediate(false) 80 | else: 81 | playCore.startUpdateFlexible(false) 82 | ``` 83 | 84 | ``` 85 | fun isUpdateAvailable(): Boolean 86 | fun startAppUpdatedManager(params: Dictionary) 87 | fun startUpdateImmediate(allow_remove_asset: Boolean) 88 | fun startUpdateFlexible(allow_remove_asset: Boolean) 89 | ``` 90 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /PlayCoreLibrary/src/main/kotlin/com/frogsquare/playcorelibrary/GDPlayCoreLibrary.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.playcorelibrary 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.util.Log 6 | import com.google.android.material.snackbar.Snackbar 7 | import com.google.android.play.core.appupdate.AppUpdateInfo 8 | import com.google.android.play.core.appupdate.AppUpdateManagerFactory 9 | import com.google.android.play.core.appupdate.AppUpdateOptions 10 | import com.google.android.play.core.install.InstallStateUpdatedListener 11 | import com.google.android.play.core.install.model.ActivityResult 12 | import com.google.android.play.core.install.model.AppUpdateType 13 | import com.google.android.play.core.install.model.InstallStatus 14 | import com.google.android.play.core.install.model.UpdateAvailability 15 | import com.google.android.play.core.ktx.clientVersionStalenessDays 16 | import org.godotengine.godot.Dictionary 17 | import org.godotengine.godot.Godot 18 | import org.godotengine.godot.GodotLib 19 | import org.godotengine.godot.plugin.GodotPlugin 20 | import org.godotengine.godot.plugin.SignalInfo 21 | import org.godotengine.godot.plugin.UsedByGodot 22 | 23 | const val TAG: String = "PlayCoreLibrary" 24 | 25 | @Suppress("UNUSED") 26 | class GDPlayCoreLibrary constructor(godot: Godot): GodotPlugin(godot) { 27 | 28 | private var context = godot.requireContext() 29 | 30 | private val appUpdateManager = AppUpdateManagerFactory.create(context) 31 | private var appUpdateInfo : AppUpdateInfo? = null 32 | 33 | @UsedByGodot 34 | fun initialize(params: Dictionary) { 35 | 36 | Log.i(TAG, "Initialized Godot PlayCoreLibrary") 37 | } 38 | 39 | @UsedByGodot 40 | fun isUpdateAvailable(): Boolean { 41 | return appUpdateInfo != null 42 | } 43 | 44 | @UsedByGodot 45 | fun startAppUpdatedManager(params: Dictionary) { 46 | val immediate = params["immediate"] as? Boolean 47 | Log.i(TAG, "Checking Update in mode `${ if (immediate == true) "IMMEDIATE" else "FLEXIBLE" }`") 48 | 49 | if (immediate == false) { 50 | appUpdateManager.registerListener(listener) 51 | } 52 | 53 | appUpdateManager 54 | .appUpdateInfo 55 | .addOnSuccessListener { info -> 56 | appUpdateInfo = info 57 | 58 | if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) { 59 | Log.i(TAG, "Update Available :: ${info.availableVersionCode()}") 60 | 61 | if (immediate == true) { 62 | if (info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) { 63 | val data = Dictionary() 64 | data["package"] = info.packageName() 65 | data["version"] = info.availableVersionCode() 66 | data["mode"] = "IMMEDIATE" 67 | 68 | Log.i(TAG, "Request Immediate Update") 69 | emitSignal("update_available", data) 70 | } 71 | } else { 72 | Log.i(TAG, "Client Version Staleness Days :: ${info.clientVersionStalenessDays}") 73 | val flexibleUpdateDays = (params["flexible_days"] as? Int) ?: 1 74 | if (info.clientVersionStalenessDays ?: -1 >= flexibleUpdateDays 75 | && info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { 76 | 77 | val data = Dictionary() 78 | data["package"] = info.packageName() 79 | data["version"] = info.availableVersionCode() 80 | data["mode"] = "FLEXIBLE" 81 | 82 | Log.i(TAG, "Request Flexible Update") 83 | emitSignal("update_available", data) 84 | } 85 | } 86 | } else { 87 | Log.i(TAG, "No Update Available!") 88 | } 89 | } 90 | } 91 | 92 | @UsedByGodot 93 | fun startUpdateImmediate(allow_remove_asset: Boolean) { 94 | if (appUpdateInfo == null) { 95 | Log.i(TAG, "AppUpdateInfo is null!") 96 | return 97 | } 98 | 99 | Log.i(TAG, "Starting update flow IMMEDIATE") 100 | if (allow_remove_asset) { 101 | appUpdateManager.startUpdateFlowForResult( 102 | appUpdateInfo!!, 103 | activity!!, 104 | AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE) 105 | .setAllowAssetPackDeletion(true) 106 | .build(), 107 | 0x001 108 | ) 109 | } else { 110 | appUpdateManager.startUpdateFlowForResult( 111 | appUpdateInfo!!, 112 | AppUpdateType.IMMEDIATE, 113 | activity!!, 114 | 0x001 115 | ) 116 | } 117 | } 118 | 119 | @UsedByGodot 120 | fun startUpdateFlexible(allow_remove_asset: Boolean) { 121 | if (appUpdateInfo == null) { 122 | Log.i(TAG, "AppUpdateInfo is null!") 123 | return 124 | } 125 | 126 | Log.i(TAG, "Starting update flow FLEXIBLE") 127 | if (allow_remove_asset) { 128 | appUpdateManager.startUpdateFlowForResult( 129 | appUpdateInfo!!, 130 | activity!!, 131 | AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE) 132 | .setAllowAssetPackDeletion(true) 133 | .build(), 134 | 0x001 135 | ) 136 | } else { 137 | appUpdateManager.startUpdateFlowForResult( 138 | appUpdateInfo!!, 139 | AppUpdateType.FLEXIBLE, 140 | activity!!, 141 | 0x001 142 | ) 143 | } 144 | } 145 | 146 | // Displays the snackbar notification and call to action. 147 | private fun popupSnackbarForCompleteUpdate() { 148 | Snackbar.make( 149 | super.getGodot().mView, 150 | "An update has just been downloaded.", 151 | Snackbar.LENGTH_INDEFINITE 152 | ).apply { 153 | setAction("RESTART") { appUpdateManager.completeUpdate() } 154 | show() 155 | } 156 | } 157 | 158 | // Create a listener to track request state updates. 159 | private val listener = InstallStateUpdatedListener { state -> 160 | if (state.installStatus() == InstallStatus.DOWNLOADED) { 161 | popupSnackbarForCompleteUpdate() 162 | } 163 | } 164 | 165 | override fun onMainResume() { 166 | super.onMainResume() 167 | 168 | appUpdateManager.appUpdateInfo.addOnSuccessListener { info -> 169 | if (info.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) { 170 | // If an in-app update is already running, resume the update. 171 | Log.i(TAG, "Resume Update Process") 172 | appUpdateManager.startUpdateFlowForResult( 173 | appUpdateInfo!!, 174 | AppUpdateType.IMMEDIATE, 175 | activity!!, 176 | 0x001 177 | ) 178 | } 179 | 180 | if (info.installStatus() == InstallStatus.DOWNLOADED) { 181 | popupSnackbarForCompleteUpdate() 182 | } 183 | } 184 | } 185 | 186 | override fun onMainDestroy() { 187 | appUpdateManager.unregisterListener(listener) 188 | appUpdateInfo = null 189 | 190 | super.onMainDestroy() 191 | } 192 | 193 | override fun onMainActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 194 | if (requestCode == 0x001) { 195 | when (resultCode) { 196 | Activity.RESULT_OK -> { 197 | Log.i(TAG, "Update flow success") 198 | emitSignal("update_success") 199 | } 200 | Activity.RESULT_CANCELED -> { 201 | Log.i(TAG, "Update flow canceled, $resultCode") 202 | emitSignal("update_canceled") 203 | } 204 | ActivityResult.RESULT_IN_APP_UPDATE_FAILED -> { 205 | Log.i(TAG, "Update flow failed, $resultCode") 206 | emitSignal("update_failed") 207 | } 208 | } 209 | } 210 | 211 | super.onMainActivityResult(requestCode, resultCode, data) 212 | } 213 | 214 | override fun getPluginSignals(): MutableSet { 215 | return mutableSetOf( 216 | SignalInfo("update_available", Dictionary::class.javaObjectType), 217 | SignalInfo("update_success"), 218 | SignalInfo("update_failed"), 219 | SignalInfo("update_canceled") 220 | ) 221 | } 222 | 223 | override fun getPluginName(): String { 224 | return "GDPlayCoreLibrary" 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /GooglePlay/src/main/kotlin/com/frogsquare/googleplay/GDPlayService.kt: -------------------------------------------------------------------------------- 1 | package com.frogsquare.googleplay 2 | 3 | import android.content.Intent 4 | import android.content.IntentSender 5 | import android.util.Log 6 | import com.google.android.gms.auth.api.Auth 7 | import com.google.android.gms.auth.api.signin.* 8 | import com.google.android.gms.common.ConnectionResult 9 | import com.google.android.gms.common.GoogleApiAvailability 10 | import com.google.android.gms.games.* 11 | import com.google.android.gms.games.leaderboard.LeaderboardScore 12 | import com.google.android.gms.games.leaderboard.LeaderboardVariant 13 | import org.godotengine.godot.Dictionary 14 | import org.godotengine.godot.Godot 15 | import org.godotengine.godot.plugin.GodotPlugin 16 | import org.godotengine.godot.plugin.SignalInfo 17 | import org.godotengine.godot.plugin.UsedByGodot 18 | 19 | private const val TAG: String = "GooglePlay" 20 | 21 | @Suppress("UNUSED") 22 | class GDPlayService constructor(godot: Godot): GodotPlugin(godot) { 23 | 24 | private val context = godot.requireContext() 25 | 26 | private var client: GoogleSignInClient? = null 27 | private var achievementClient: AchievementsClient? = null 28 | private var leaderboardsClient: LeaderboardsClient? = null 29 | private var playersClient: PlayersClient? = null 30 | private var videosClient: VideosClient? = null 31 | 32 | private var canRecord: Boolean = false 33 | private var playerDetails = Dictionary() 34 | 35 | private var isIntentInProgress: Boolean = false 36 | private var isResolvingConnectionFailure: Boolean = false 37 | 38 | private var _connected: Boolean = false 39 | 40 | @UsedByGodot 41 | fun initialize() { 42 | if (!isAvailable()) { 43 | Log.d(TAG, "Google play service is not available in this device.") 44 | } else { 45 | val builder = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) 46 | client = GoogleSignIn.getClient(godot.requireActivity(), builder.build()) 47 | } 48 | 49 | val account = GoogleSignIn.getLastSignedInAccount(context) 50 | if (account != null) { 51 | Log.d(TAG, "Already Connected") 52 | onSignInSuccess(account) 53 | } else { 54 | signInSilently() 55 | } 56 | } 57 | 58 | @UsedByGodot 59 | fun isConnected(): Boolean { 60 | return GoogleSignIn.getLastSignedInAccount(context) != null 61 | } 62 | 63 | @UsedByGodot 64 | fun signIn() { 65 | if (this.client == null) { 66 | Log.d(TAG, "GoogleSignIn Client is not initialized.") 67 | return 68 | } 69 | 70 | if (isConnected()) { 71 | Log.d(TAG, "Google service is already connected.") 72 | return 73 | } 74 | 75 | val intent = client?.signInIntent 76 | activity?.startActivityForResult(intent, Common.RC_GOOGLE) 77 | } 78 | 79 | @UsedByGodot 80 | fun signOut() { 81 | client?.let { 82 | it.signOut().addOnCompleteListener { 83 | Log.d(TAG, "Signed out.") 84 | 85 | achievementClient = null 86 | leaderboardsClient = null 87 | playersClient = null 88 | videosClient = null 89 | 90 | playerDetails.clear() 91 | 92 | _connected = false 93 | emitSignal("signed_out") 94 | } 95 | } 96 | } 97 | 98 | @UsedByGodot 99 | fun increaseAchievement(name: String, value: Int) { 100 | if (!_connected) return 101 | 102 | runOnUiThread { 103 | achievementClient?.increment(name, value) 104 | } 105 | } 106 | 107 | @UsedByGodot 108 | fun unlockAchievement(name: String) { 109 | if (!_connected) return 110 | 111 | runOnUiThread { 112 | achievementClient?.unlock(name) 113 | } 114 | } 115 | 116 | @UsedByGodot 117 | fun loadTopScore(name: String, max: Int) { 118 | if (!isConnected()) { return } 119 | 120 | leaderboardsClient?.loadTopScores( 121 | name, 122 | LeaderboardVariant.TIME_SPAN_ALL_TIME, 123 | LeaderboardVariant.COLLECTION_PUBLIC, 124 | max 125 | )?.addOnSuccessListener { 126 | it.get()?.let { boards -> 127 | val scores: ArrayList = arrayListOf() 128 | for (score in boards.scores) { 129 | scores.add(convertToDict(score, name)) 130 | } 131 | 132 | emitSignal("scores_loaded", scores) 133 | } 134 | } 135 | } 136 | 137 | @UsedByGodot 138 | fun loadCurrentPlayerScore(name: String) { 139 | if (!isConnected()) { return } 140 | 141 | leaderboardsClient?.loadCurrentPlayerLeaderboardScore( 142 | name, 143 | LeaderboardVariant.TIME_SPAN_ALL_TIME, 144 | LeaderboardVariant.COLLECTION_PUBLIC 145 | )?.addOnSuccessListener { 146 | it.get()?.let { score -> 147 | emitSignal("score_loaded", convertToDict(score, name)) 148 | } 149 | } 150 | } 151 | 152 | @UsedByGodot 153 | fun submitScore(name: String, value: Int) { 154 | if (!_connected) return 155 | 156 | runOnUiThread { 157 | leaderboardsClient?.submitScore(name, value.toLong()) 158 | } 159 | } 160 | 161 | @UsedByGodot 162 | fun showAchievements() { 163 | if (!_connected) return 164 | 165 | achievementClient?.let { 166 | it.achievementsIntent 167 | .addOnSuccessListener { intent -> 168 | activity?.startActivityForResult(intent, Common.RC_ACHIEVEMENT) 169 | } 170 | .addOnFailureListener { exception -> 171 | Log.d(TAG, "Showing::Achievements::Failed ${exception.message}") 172 | } 173 | } 174 | } 175 | 176 | @UsedByGodot 177 | fun showLeaderboard(name: String) { 178 | if (!_connected) return 179 | 180 | leaderboardsClient?.let { 181 | it.getLeaderboardIntent(name) 182 | .addOnSuccessListener { intent -> 183 | activity?.startActivityForResult(intent, Common.RC_LEADERBOARD) 184 | } 185 | .addOnFailureListener { exception -> 186 | Log.d(TAG, "Showing::Leaderboard::Failed ${exception.message}") 187 | } 188 | } 189 | } 190 | 191 | @UsedByGodot 192 | fun showAllLeaderboards() { 193 | if (!_connected) return 194 | 195 | leaderboardsClient?.let { 196 | it.allLeaderboardsIntent 197 | .addOnSuccessListener { intent -> 198 | activity?.startActivityForResult(intent, Common.RC_LEADERBOARD) 199 | } 200 | .addOnFailureListener { exception -> 201 | Log.d(TAG, "Showing::All::Leaderboard::Failed ${exception.message}") 202 | } 203 | } 204 | } 205 | 206 | @UsedByGodot 207 | fun canRecord(): Boolean { 208 | if (!_connected) return false 209 | 210 | if (videosClient == null) { 211 | Log.d(TAG, "Play Service Video Client is not initialized.") 212 | return false 213 | } 214 | 215 | return canRecord 216 | } 217 | 218 | @UsedByGodot 219 | fun record() { 220 | if (!_connected || !canRecord) return 221 | 222 | val account = GoogleSignIn.getLastSignedInAccount(context) 223 | account?.let { 224 | val client = Games.getVideosClient(context, it) 225 | client.captureOverlayIntent.addOnSuccessListener { intent -> 226 | emitSignal("recording_started") 227 | activity?.startActivityForResult(intent, 0) 228 | } 229 | } 230 | } 231 | 232 | @UsedByGodot 233 | fun isAvailable(): Boolean { 234 | val googleApiAvailability = GoogleApiAvailability.getInstance() 235 | val resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context) 236 | 237 | return resultCode == ConnectionResult.SUCCESS 238 | } 239 | 240 | @UsedByGodot 241 | fun getPlayerInfo(): Dictionary { 242 | if (!_connected) return Dictionary() 243 | 244 | return playerDetails 245 | } 246 | 247 | private fun onSignInSuccess(account: GoogleSignInAccount?) { 248 | Log.d(TAG, "SignIn Complete") 249 | 250 | account?.let { 251 | achievementClient = Games.getAchievementsClient(context, it) 252 | leaderboardsClient = Games.getLeaderboardsClient(context, it) 253 | playersClient = Games.getPlayersClient(context, it) 254 | videosClient = Games.getVideosClient(context, it) 255 | 256 | _connected = true 257 | 258 | emitSignal("signed_in") 259 | 260 | playersClient?.currentPlayer?.let { current -> 261 | current.addOnCompleteListener { player -> 262 | if (player.isSuccessful) { 263 | playerDetails.clear() 264 | 265 | val details = player.result 266 | 267 | playerDetails["name"] = details.name 268 | playerDetails["title"] = details.title 269 | playerDetails["player_id"] = details.playerId 270 | playerDetails["display_name"] = details.displayName 271 | playerDetails["icon_uri"] = details.iconImageUri?.toString() 272 | 273 | emitSignal("profile_updated", playerDetails) 274 | } 275 | } 276 | } 277 | 278 | isResolvingConnectionFailure = false 279 | } 280 | } 281 | 282 | private fun convertToDict(score: LeaderboardScore, name: String): Dictionary { 283 | val dict = Dictionary() 284 | dict["name"] = name 285 | dict["rank"] = score.rank 286 | dict["display_rank"] = score.displayRank 287 | dict["display_score"] = score.displayScore 288 | dict["raw_score"] = score.rawScore 289 | dict["tag"] = score.scoreTag 290 | dict["timestamp"] = score.timestampMillis 291 | 292 | return dict 293 | } 294 | 295 | private fun handleSignInResult(result: GoogleSignInResult) { 296 | if (result.isSuccess) { 297 | onSignInSuccess(result.signInAccount) 298 | } else { 299 | val s = result.status 300 | Log.e(TAG, "SignInResult::status::Code, Message: ${s.statusCode}, ${s.statusMessage}") 301 | 302 | if (isResolvingConnectionFailure) { return } 303 | if (!isIntentInProgress && result.status.hasResolution()) { 304 | try { 305 | isIntentInProgress = true 306 | 307 | s.resolution?.let { 308 | activity?.startIntentSenderForResult( 309 | it.intentSender, 310 | Common.RC_GOOGLE, 311 | null, 312 | 0, 313 | 0, 314 | 0 315 | ) 316 | } 317 | 318 | } catch (e: IntentSender.SendIntentException) { 319 | signIn() 320 | } 321 | 322 | isResolvingConnectionFailure = true 323 | } 324 | } 325 | } 326 | 327 | private fun signInSilently() { 328 | if (isConnected()) return 329 | 330 | val client = GoogleSignIn.getClient(context, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) 331 | client.silentSignIn() 332 | .addOnSuccessListener { account -> 333 | onSignInSuccess(account) 334 | } 335 | .addOnFailureListener { 336 | Log.e(TAG, "SignInResult::Failed::${it.message}\n"+Log.getStackTraceString(it)) 337 | } 338 | } 339 | 340 | override fun onMainActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 341 | if (requestCode == Common.RC_GOOGLE) { 342 | isIntentInProgress = false 343 | 344 | data?.let { 345 | val result = Auth.GoogleSignInApi.getSignInResultFromIntent(it) 346 | if (result != null) { 347 | handleSignInResult(result) 348 | } 349 | } 350 | } 351 | } 352 | 353 | override fun getPluginSignals(): MutableSet { 354 | return mutableSetOf( 355 | SignalInfo("signed_in"), 356 | SignalInfo("signed_out"), 357 | SignalInfo("scores_loaded", ArrayList::class.javaObjectType), 358 | SignalInfo("score_loaded", Dictionary::class.javaObjectType), 359 | SignalInfo("profile_updated", Dictionary::class.javaObjectType), 360 | SignalInfo("recording_started") 361 | ) 362 | } 363 | 364 | override fun getPluginName(): String { 365 | return "GDPlayService" 366 | } 367 | } 368 | --------------------------------------------------------------------------------