Skip to content

Commit

Permalink
New android plugin for godot 3.2.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
cgisca committed Jul 24, 2020
1 parent 7da599f commit 8addfd2
Show file tree
Hide file tree
Showing 52 changed files with 1,819 additions and 1,097 deletions.
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
### Android ###
# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
91 changes: 47 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Google Play Games Services Plugin for Godot
This is an Android Play Games Services plugin for Godot Game Engine 3.2 and higher.
This is an Android Play Games Services plugin for Godot Game Engine 3.2.2+.

[![Android](https://img.shields.io/badge/Platform-Android-brightgreen.svg)](https://developer.android.com)
[![Godot](https://img.shields.io/badge/Godot%20Engine-3.2-blue.svg)](https://github.com/godotengine/godot/)
[![Godot](https://img.shields.io/badge/Godot%20Engine-3.2.2-blue.svg)](https://github.com/godotengine/godot/)
[![PGS](https://img.shields.io/badge/Play%20Games%20Services-19.0.0-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/)
[![Donate](https://img.shields.io/badge/Donate-PayPal-informational.svg)](https://paypal.me/cgisca)


If you want to use the old plugin version visit [Old README file](https://github.com/cgisca/PGSGP/README_OLD.md).


### Supported features:
Expand All @@ -17,43 +19,51 @@ This is an Android Play Games Services plugin for Godot Game Engine 3.2 and high
- Saved Games

## Getting started
Before using this plugin please follow instructions on [Setting Up Google Play Games Services](https://developers.google.com/games/services/console/enabling) official guide.
### Set up
- Set up the custom build environment for your project and enable it. See [Godot Engine docs](https://docs.godotengine.org/en/latest/getting_started/workflow/export/android_custom_build.html).
- Download and move `android-pgs-plugin` from the current repository into `res://android/` of your godot project.
- After downloading `android-pgs-plugin`, open it and go to `res` -> `values`. Search for `ids.xml` and open it. Replace `PUT_YOUR_APP_ID_HERE` with your Games Services Application ID for the `app_id` resource. (Don't forget to save file)
- In Godot Engine, go to `Project` -> `Project Settings`. Then on the tab `General` go to the `Android` section, and fill the `Modules` part with `org/godotengine/godot/PlayGameServices`. See [Godot Engine docs](
https://docs.godotengine.org/en/latest/tutorials/plugins/android/android_plugin.html#using-it-from-gdscript).
<br/>*Note: If you have already added one plugin to the `Modules` append the current one by separating them with comma (ex: `xx/xx/Module1,org/godotengine/godot/PlayGameServices`)
<br/>*Note 2: If you have already added other plugin that has `meta-data android:name="com.google.android.gms.version"` declared inside it's `AndroidManifest`, remove **below lines** from the `android-pgs-plugin`-> `AndroidManifest.conf` file. (Don't forget to save file after removing below lines)

```xml
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
- Download `GodotPlayGamesServices.release.aar` and `GodotPlayGamesServices.gdap` from releases section.
- Move the plugin configuration file (`GodotPlayGamesServices.gdap`) and the binary (`GodotPlayGamesServices.release.aar`) downloaded from the previous step to the Godot project's res://android/plugins directory.
- Enable plugin by accessing `Project` -> `Export`, Plugins section. Follow the [image](https://docs.godotengine.org/en/stable/_images/android_export_preset_plugins_section.png).
- Go to res://android/build directory. Add below lines to `AndroidManifest.xml`:
```xml
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />

<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
```
- In the same res://android/build directory,(if it is not already created) create `res` -> `values` -> `Strings.xml`. Add below lines to `Strings.xml`:
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_id">ADD_YOUR_APP_ID</string>
</resources>
```
Replace ADD_YOUR_APP_ID with the app id that was generated after following instructions on [Setting Up Google Play Games Services](https://developers.google.com/games/services/console/enabling)

### Latest version
Latest version could be found [here (1.2.0)](https://github.com/cgisca/PGSGP/releases/tag/1.2.0).
Check demo project. In order demo project to work, replace <string name="app_id">ADD_YOUR_APP_ID</string> with your own app id, and in Main.gd add your ids for achievements and leaderboards.

### How to use
First step is plugin initialization
```gdscript
var play_games_services
# Check if plugin was added to the project
if Engine.has_singleton("PlayGameServices"):
play_games_services = Engine.get_singleton("PlayGameServices")
if Engine.has_singleton("GodotPlayGamesServices"):
play_games_services = Engine.get_singleton("GodotPlayGamesServices")
# Initialize plugin by calling init method and passing to it get_instance_id() and a boolean to enable/disable displaying game pop-ups
# Initialize plugin by calling init method and passing to it a boolean to enable/disable displaying game pop-ups
var show_popups := true # For example, your game can display a “Welcome back” or an “Achievements unlocked” pop-up. true for enabling it.
var enable_save_games := true # If you want to enable Saved Games functionality. true for enabling it. If enabled, it will require additional Google Drive API permission from the user.
play_games_services.init(get_instance_id(), show_popups, enable_save_games)
play_games_services.init(show_popups)
# For enabling saved games functionality use below initialization instead
# play_games_services.initWithSavedGames(show_popups, "SavedGamesName")
```
After what plugin was initialized you can use supported features
#### Sign-in / Sign out
##### Sign-in

```gdscript
play_games_services.sign_in()
play_games_services.signIn()
# Callbacks:
func _on_sign_in_success(account_id: String) -> void:
Expand All @@ -65,7 +75,7 @@ func _on_sign_in_failed(error_code: int) -> void:
```
##### Sign out
```gdscript
play_games_services.sign_out()
play_games_services.signOut()
# Callbacks:
func _on_sign_out_success():
Expand All @@ -77,7 +87,7 @@ func _on_sign_out_failed():
#### Achievements
##### Unlock Achievement
```gdscript
play_games_services.unlock_achievement("ACHIEVEMENT_ID")
play_games_services.unlockAchievement("ACHIEVEMENT_ID")
# Callbacks:
func _on_achievement_unlocked(achievement: String):
Expand All @@ -89,7 +99,7 @@ func _on_achievement_unlocking_failed(achievement: String):
##### Increment Achievement
```gdscript
var step = 1
play_games_services.increment_achievement("ACHIEVEMENT_ID", step)
play_games_services.incrementAchievement("ACHIEVEMENT_ID", step)
# Callbacks:
func _on_achievement_incremented(achievement: String):
Expand All @@ -100,7 +110,7 @@ func _on_achievement_incrementing_failed(achievement: String):
```
##### Reveal Achievement
```gdscript
play_games_services.reveal_achievement("ACHIEVEMENT_ID")
play_games_services.revealAchievement("ACHIEVEMENT_ID")
# Callbacks:
func _on_achievement_revealed(achievement: String):
Expand All @@ -111,13 +121,13 @@ func _on_achievement_revealing_failed(achievement: String):
```
##### Show Achievements List
```gdscript
play_games_services.show_achievements()
play_games_services.showAchievements()
```
#### Leaderboards
##### Submit leaderboard score
```gdscript
var score = 1234
play_games_services.submit_leaderboard_score("LEADERBOARD_ID", score)
play_games_services.submitLeaderBoardScore("LEADERBOARD_ID", score)
# Callbacks:
func _on_leaderboard_score_submitted(leaderboard_id: String):
Expand All @@ -128,24 +138,17 @@ func _on_leaderboard_score_submitting_failed(leaderboard_id: String):
```
##### Show leaderboard
```gdscript
play_games_services.show_leaderboard("LEADERBOARD_ID")
play_games_services.showLeaderBoard("LEADERBOARD_ID")
play_games_services.show_all_leaderboards()
play_games_services.showAllLeaderBoards()
```
#### Player connection
```gdscript
play_games_services.is_player_connected()

#Callback:
func _on_player_is_already_connected(is_connected: bool):
pass
```
#### Events
##### Submit event
```gdscript
var increment_by := 2
play_games_services.submit_event("EVENT_ID", increment_by)
play_games_services.submitEvent("EVENT_ID", increment_by)
# Callbacks:
func _on_event_submitted(event_id: String):
Expand All @@ -157,9 +160,9 @@ func _on_event_submitted_failed(event_id: String):
##### Load events
```gdscript
# Load all events
play_games_services.load_events()
play_games_services.loadEvents()
# Or load events by given ids
play_games_services.load_events_by_id(["EVENT_ID_1", "EVENT_ID_2", ...])
play_games_services.loadEventsById(["EVENT_ID_1", "EVENT_ID_2", ...])
# Callbacks:
# If there is at least one event, following callback will be triggered:
Expand All @@ -186,7 +189,7 @@ func _on_events_loading_failed():
#### Player Stats
```gdscript
var force_refresh := true # If true, this call will clear any locally cached data and attempt to fetch the latest data from the server.
play_games_services.load_player_stats(force_refresh)
play_games_services.loadPlayerStats(force_refresh)
# Callbacks:
func _on_player_stats_loaded(stats):
Expand All @@ -211,7 +214,7 @@ var data_to_save: Dictionary = {
"height": 1.82,
"is_gamer": true
}
play_games_services.save_snapshot("SNAPSHOT_NAME", to_json(data_to_save), "DESCRIPTION")
play_games_services.saveSnapshot("SNAPSHOT_NAME", to_json(data_to_save), "DESCRIPTION")
# Callbacks:
func _on_game_saved_success():
Expand All @@ -222,7 +225,7 @@ func _on_game_saved_fail():
```
##### Load game snapshot
```gdscript
play_games_services.load_snapshot("SNAPSHOT_NAME")
play_games_services.loadSnapshot("SNAPSHOT_NAME")
# Callbacks:
func _on_game_load_success(data):
Expand All @@ -240,7 +243,7 @@ func _on_game_load_fail():
var allow_add_button := true
var allow_delete_button := true
var max_saved_games_snapshots := 5
play_games_services.show_saved_games("SNAPSHOT_NAME", allow_add_button, allow_delete_button, max_saved_games_snapshots)
play_games_services.showSavedGames("SNAPSHOT_NAME", allow_add_button, allow_delete_button, max_saved_games_snapshots)
#Godot callback
# If user clicked on add new snapshot button on the screen with all saved snapshots, below callback will be triggered:
Expand Down
Loading

0 comments on commit 8addfd2

Please sign in to comment.