-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathStateManager.cpp
More file actions
106 lines (95 loc) · 3.27 KB
/
StateManager.cpp
File metadata and controls
106 lines (95 loc) · 3.27 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
/* 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"
bool StateManager::is_auth_in_progress_ = false;
std::unique_ptr<gpg::GameServices> StateManager::game_services_;
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 achievements");
game_services_->Achievements().ShowAllUI([](gpg::UIStatus const &status) {
if (gpg::IsSuccess(status)) {
LOGI("Achievements Result: success.");
} else {
LOGI("Achievements Result: failure.");
}
});
}
}
void StateManager::ShowLeaderboards() {
if (game_services_->IsAuthorized()) {
LOGI("Show leaderboards");
game_services_->Leaderboards().ShowAllUI([](gpg::UIStatus const &status) {
if (gpg::IsSuccess(status)) {
LOGI("Leaderboards Result: success.");
} else {
LOGI("Leaderboards Result: failure.");
}
});
}
}
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()
.SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {
is_auth_in_progress_ = true;
if (started_callback != nullptr) {
started_callback(op);
}
})
.SetOnAuthActionFinished([finished_callback](gpg::AuthOperation op,
gpg::AuthStatus status) {
LOGI("Sign in finished with a result of %d", status);
is_auth_in_progress_ = false;
if (finished_callback != nullptr) {
finished_callback(op, status);
}
})
.Create(pc);
}
LOGI("Created");
}