Skip to content

Commit

Permalink
attempt to integrate google play API
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 18, 2024
1 parent 9a60be0 commit 738fe47
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 5 deletions.
4 changes: 2 additions & 2 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ source.exclude_dirs = test, bin, .buildozer, data/collection, data/collection_co
source.exclude_patterns = data.json,*.gitignore, requirements.txt,draft_*

# (str) Application versioning (method 1)
version = 2.2.1
version = 2.2.2

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
Expand Down Expand Up @@ -188,7 +188,7 @@ android.add_src = src
#android.add_assets =

# (list) Gradle dependencies to add
android.gradle_dependencies = com.google.android.gms:play-services-ads:22.5.0, androidx.fragment:fragment-ktx:1.3.0-beta01, com.google.android.ump:user-messaging-platform:2.1.0, com.google.android.play:core:1.10.0
android.gradle_dependencies = com.google.android.gms:play-services-ads:22.5.0, androidx.fragment:fragment-ktx:1.3.0-beta01, com.google.android.ump:user-messaging-platform:2.1.0, com.google.android.play:core:1.10.0, com.google.android.gms:play-services-games-v2:+

# (bool) Enable AndroidX support. Enable when 'android.gradle_dependencies'
# contains an 'androidx' package, or any package from Kotlin source.
Expand Down
4 changes: 3 additions & 1 deletion extra_manifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="163527384353"/>
4 changes: 3 additions & 1 deletion screens/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from tools import (
music_mixer
)
from tools.kivygameservices import connect


###############
Expand Down Expand Up @@ -95,4 +96,5 @@ def start_game(self):
self.manager.current = "intermediate_menu"

def open_lupa_website(self):
webbrowser.open("https://lupadevstudio.com", 2)
connect()
# webbrowser.open("https://lupadevstudio.com", 2)
108 changes: 108 additions & 0 deletions src/GameServicesHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.org.kivygameservices;

import android.content.Context;
import android.content.IntentSender;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.GamesSignInClient;
import com.google.android.gms.games.PlayGamesSdk;
import com.google.android.gms.games.Players;

public class GameServicesHandler
implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

private static final int REQUEST_LEADERBOARD = 1;
private GoogleApiClient mGoogleApiClient;
private Context mContext;

public GameServicesHandler(Context context) {
mContext = context;
PlayGamesSdk.initialize(context);

// Initialize the Play Games SDK
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API)
.build();
}

public void connect() {
// Connect to Play Games services
mGoogleApiClient.connect();
}

public void disconnect() {
// Disconnect from Play Games services
mGoogleApiClient.disconnect();
}

// public void showLeaderboard() {
// GamesSignInClient gamesSignInClient =
// PlayGamesSdk.getGamesSignInClient(mContext);

// gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask
// -> {
// boolean isAuthenticated = (isAuthenticatedTask.isSuccessful() &&
// isAuthenticatedTask.getResult().isAuthenticated());

// if (isAuthenticated) {
// // Continue with Play Games Services
// // You can add the code to show the leaderboard here
// showLeaderboardInternal();
// } else {
// // Disable your integration with Play Games Services or show a
// // login button to ask players to sign-in. Clicking it should
// // call GamesSignInClient.signIn().
// // Handle the sign-in logic as needed in your application
// }
// });
// }

// private void showLeaderboardInternal() {
// // Retrieve the Player ID
// Players.getPlayersClient(mContext).getCurrentPlayer().addOnCompleteListener(task
// -> {
// String playerId = task.getResult().getPlayerId();
// // You can use the playerId for further processing or displaying information
// // about the current player.
// // Example: Log.d("GameServicesHandler", "Player ID: " + playerId);

// // Add your code to show the leaderboard using the retrieved Player ID
// // For example:
// //
// Games.getLeaderboardsClient(mGoogleApiClient).getLeaderboardIntent("YOUR_LEADERBOARD_ID")
// // .addOnSuccessListener(intent -> {
// // // Start the intent to show the leaderboard
// // })
// // .addOnFailureListener(e -> {
// // // Handle error
// // });
// });
// }

// Override methods for GoogleApiClient.ConnectionCallbacks
@Override
public void onConnected(Bundle bundle) {
// Connected to Play Games services
}

@Override
public void onConnectionSuspended(int i) {
// Connection suspended
}

// Override method for GoogleApiClient.OnConnectionFailedListener
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// Connection failed
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(null, REQUEST_LEADERBOARD);
} catch (IntentSender.SendIntentException e) {
// Handle error
}
}
}
}
5 changes: 4 additions & 1 deletion tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

### Version ###

__version__ = "2.2.1"
__version__ = "2.2.2"

### Mode ###

Expand Down Expand Up @@ -206,3 +206,6 @@ def change_language(self, language):
# Ads code
REWARD_INTERSTITIAL = "ca-app-pub-2909842258525517/6684743133"
INTERSTITIAL = "ca-app-pub-2909842258525517/7085343595"

# Game Services Project ID
game_services_rpoject_id = "163527384353"
16 changes: 16 additions & 0 deletions tools/kivygameservices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from kivy.utils import platform


if platform == "android":
from android import PythonJavaClass, autoclass, java_method, mActivity
from android.runnable import run_on_ui_thread

context = mActivity.getApplicationContext()
GameServicesHandler = autoclass(
'org.org.kivygameservices.GameServicesHandler')
PythonActivity = autoclass('org.kivy.android.PythonActivity')

def connect(*_):
activity = PythonActivity.mActivity
game_services_handler = GameServicesHandler(activity)
game_services_handler.connect()

0 comments on commit 738fe47

Please sign in to comment.