Repository navigation
Expand file tree
/
Copy pathStateManager.cpp
More file actions
113 lines (99 loc) · 3.47 KB
/
Copy pathStateManager.cpp
File metadata and controls
113 lines (99 loc) · 3.47 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2014 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "StateManager.h"
#include "android/log.h"
#define DEBUG_TAG "TeapotNativeActivity"
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, __VA_ARGS__))
bool StateManager::is_auth_in_progress_ = false;
std::unique_ptr<gpg::GameServices> StateManager::game_services_;
void OnAuthActionFinished(gpg::AuthOperation op, gpg::AuthStatus status) {
LOGI("OnAuthActionFinished");
}
void OnAuthActionStarted(gpg::AuthOperation op) {
LOGI("OnAuthActionStarted");
switch ( op ) {
case gpg::AuthOperation::SIGN_IN:
LOGI("Signing In");
break;
case gpg::AuthOperation::SIGN_OUT:
LOGI("Signing Out");
break;
}
}
gpg::GameServices* StateManager::GetGameServices() {
return game_services_.get();
}
void StateManager::BeginUserInitiatedSignIn() {
if (!game_services_->IsAuthorized()) {
LOGI("StartAuthorizationUI");
game_services_->StartAuthorizationUI();
}
}
void StateManager::SignOut() {
if (game_services_->IsAuthorized()) {
LOGI("SignOut");
game_services_->SignOut();
}
}
void StateManager::UnlockAchievement(char const *achievement_id) {
if (game_services_->IsAuthorized()) {
LOGI("Achievement unlocked");
game_services_->Achievements().Unlock(achievement_id);
}
}
void StateManager::SubmitHighScore(char const *leaderboard_id, uint64_t score) {
if (game_services_->IsAuthorized()) {
LOGI("High score submitted");
game_services_->Leaderboards().SubmitScore(leaderboard_id, score);
}
}
void StateManager::ShowAchievements() {
if (game_services_->IsAuthorized()) {
LOGI("Show achievement");
game_services_->Achievements().ShowAllUI([](gpg::UIStatus status){});
}
}
void StateManager::ShowLeaderboard(char const *leaderboard_id) {
if (game_services_->IsAuthorized()) {
LOGI("Show achievement");
game_services_->Leaderboards().ShowUI(leaderboard_id,[](gpg::UIStatus status){});
}
}
void StateManager::InitServices(
gpg::PlatformConfiguration const &pc,
gpg::GameServices::Builder::OnAuthActionStartedCallback started_callback,
gpg::GameServices::Builder::OnAuthActionFinishedCallback
finished_callback) {
LOGI("Initializing Services");
if (!game_services_) {
LOGI("Uninitialized services, so creating");
game_services_ = gpg::GameServices::Builder()
.SetOnLog(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
.SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {
is_auth_in_progress_ = true;
started_callback(op);
})
.SetOnAuthActionFinished([finished_callback](gpg::AuthOperation op,
gpg::AuthStatus status) {
LOGI("Sign %s finished with a result of %d",
op == gpg::AuthOperation::SIGN_IN ? "in" : "out", status);
is_auth_in_progress_ = false;
finished_callback(op, status);
})
.Create(pc);
}
LOGI("Created");
}