This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
/
gs_android.py
76 lines (60 loc) · 2.32 KB
/
gs_android.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Game services for Android
from jnius import autoclass, PythonJavaClass, java_method
from android.runnable import run_on_ui_thread
import android
import android.activity
PythonActivity = autoclass('org.renpy.android.PythonActivity')
GameHelper = autoclass('com.google.example.games.basegameutils.GameHelper')
Games = autoclass('com.google.android.gms.games.Games')
class GameHelperListener(PythonJavaClass):
__javacontext__ = 'app'
__javainterfaces__ = ['com.google.example.games.basegameutils.GameHelper$GameHelperListener']
@java_method('()V')
def onSignInFailed(self):
print 'signing failed :('
@java_method('()V')
def onSignInSucceeded(self):
print 'signin success :)'
gh_instance = None
gh_instance_listener = None
def _on_activity_result(request, response, data):
gh_instance.onActivityResult(request, response, data)
@run_on_ui_thread
def setup(app):
global gh_instance
global gh_instance_listener
gh_instance = GameHelper(PythonActivity.mActivity, GameHelper.CLIENT_ALL)
#gh_instance.enableDebugLog(True)
gh_instance_listener = GameHelperListener()
gh_instance.setup(gh_instance_listener)
gh_instance.onStart(PythonActivity.mActivity)
android.activity.unbind(on_activity_result=_on_activity_result)
android.activity.bind(on_activity_result=_on_activity_result)
def unlock(uid):
if not gh_instance.isSignedIn():
return
Games.Achievements.unlock(gh_instance.getApiClient(), uid)
def increment(uid, count):
if not gh_instance.isSignedIn():
return
Games.Achievements.increment(gh_instance.getApiClient(), uid, count)
def leaderboard(uid, score):
if not gh_instance.isSignedIn():
return
Games.Leaderboards.submitScore(gh_instance.getApiClient(), uid, score)
def show_leaderboard(uid):
if not gh_instance.isSignedIn():
return
PythonActivity.mActivity.startActivityForResult(
Games.Leaderboards.getLeaderboardIntent(
gh_instance.getApiClient(), uid), 0x6601)
def show_achievements():
if not gh_instance.isSignedIn():
return
PythonActivity.mActivity.startActivityForResult(
Games.Achievements.getAchievementsIntent(
gh_instance.getApiClient()), 0x6602)
def on_stop():
gh_instance.onStop()
def on_start():
gh_instance.onStart(PythonActivity.mActivity)