Merge pull request #40557 from PoqXert/game-center
iOS Game Center improvements
This commit is contained in:
commit
014147e511
|
@ -49,7 +49,7 @@ class GameCenter : public Object {
|
||||||
void return_connect_error(const char *p_error_description);
|
void return_connect_error(const char *p_error_description);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void connect();
|
Error authenticate();
|
||||||
bool is_authenticated();
|
bool is_authenticated();
|
||||||
|
|
||||||
Error post_score(Variant p_score);
|
Error post_score(Variant p_score);
|
||||||
|
|
|
@ -50,6 +50,7 @@ extern "C" {
|
||||||
GameCenter *GameCenter::instance = NULL;
|
GameCenter *GameCenter::instance = NULL;
|
||||||
|
|
||||||
void GameCenter::_bind_methods() {
|
void GameCenter::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("authenticate"), &GameCenter::authenticate);
|
||||||
ClassDB::bind_method(D_METHOD("is_authenticated"), &GameCenter::is_authenticated);
|
ClassDB::bind_method(D_METHOD("is_authenticated"), &GameCenter::is_authenticated);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score);
|
ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score);
|
||||||
|
@ -64,35 +65,18 @@ void GameCenter::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event);
|
ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event);
|
||||||
};
|
};
|
||||||
|
|
||||||
void GameCenter::return_connect_error(const char *p_error_description) {
|
Error GameCenter::authenticate() {
|
||||||
authenticated = false;
|
|
||||||
Dictionary ret;
|
|
||||||
ret["type"] = "authentication";
|
|
||||||
ret["result"] = "error";
|
|
||||||
ret["error_code"] = 0;
|
|
||||||
ret["error_description"] = p_error_description;
|
|
||||||
pending_events.push_back(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameCenter::connect() {
|
|
||||||
|
|
||||||
//if this class isn't available, game center isn't implemented
|
//if this class isn't available, game center isn't implemented
|
||||||
if ((NSClassFromString(@"GKLocalPlayer")) == nil) {
|
if ((NSClassFromString(@"GKLocalPlayer")) == nil) {
|
||||||
return_connect_error("GameCenter not available");
|
return ERR_UNAVAILABLE;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
||||||
if (![player respondsToSelector:@selector(authenticateHandler)]) {
|
ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE);
|
||||||
return_connect_error("GameCenter doesn't respond to 'authenticateHandler'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
||||||
if (!root_controller) {
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
||||||
return_connect_error("Window doesn't have root ViewController");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This handler is called several times. First when the view needs to be shown, then again
|
// This handler is called several times. First when the view needs to be shown, then again
|
||||||
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's
|
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's
|
||||||
|
@ -118,6 +102,8 @@ void GameCenter::connect() {
|
||||||
pending_events.push_back(ret);
|
pending_events.push_back(ret);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GameCenter::is_authenticated() {
|
bool GameCenter::is_authenticated() {
|
||||||
|
|
|
@ -165,7 +165,6 @@ Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p
|
||||||
#ifdef GAME_CENTER_ENABLED
|
#ifdef GAME_CENTER_ENABLED
|
||||||
game_center = memnew(GameCenter);
|
game_center = memnew(GameCenter);
|
||||||
Engine::get_singleton()->add_singleton(Engine::Singleton("GameCenter", game_center));
|
Engine::get_singleton()->add_singleton(Engine::Singleton("GameCenter", game_center));
|
||||||
game_center->connect();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STOREKIT_ENABLED
|
#ifdef STOREKIT_ENABLED
|
||||||
|
|
Loading…
Reference in a new issue