Skip to content

Commit 8635c90

Browse files
authored
Removing unnecessary headers. (#15)
Duplicate libaray statements replaced with using statement.
1 parent 8668f18 commit 8635c90

File tree

8 files changed

+151
-114
lines changed

8 files changed

+151
-114
lines changed

demos/TicTacToe/Classes/app_delegate.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "app_delegate.h"
1616

1717
#include "main_menu_scene.h"
18-
#include "tic_tac_toe_scene.h"
1918

2019
USING_NS_CC;
2120

demos/TicTacToe/Classes/app_delegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#ifndef TICTACTOE_DEMO_CLASSES_APPDELEGATE_SCENE_H_
1616
#define TICTACTOE_DEMO_CLASSES_APPDELEGATE_SCENE_H_
17+
1718
#include "cocos2d.h"
1819

1920
class AppDelegate : private cocos2d::Application {

demos/TicTacToe/Classes/main_menu_scene.cc

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,33 @@
1515
#include "main_menu_scene.h"
1616

1717
#include <regex>
18+
#include <string>
1819

1920
#include "cocos2d.h"
21+
#include "firebase/auth.h"
22+
#include "firebase/database.h"
23+
#include "firebase/future.h"
2024
#include "firebase/util.h"
2125
#include "tic_tac_toe_scene.h"
2226
#include "util.h"
2327

28+
using cocos2d::Event;
29+
using cocos2d::Label;
30+
using cocos2d::Scene;
31+
using cocos2d::Size;
32+
using cocos2d::Sprite;
33+
using cocos2d::TextFieldTTF;
34+
using cocos2d::Touch;
35+
using cocos2d::Vec2;
36+
using firebase::App;
37+
using firebase::InitResult;
38+
using firebase::kFutureStatusComplete;
39+
using firebase::ModuleInitializer;
40+
using firebase::auth::Auth;
41+
using firebase::auth::kAuthErrorNone;
42+
using firebase::database::Database;
43+
using std::to_string;
44+
2445
static const char* kCreateGameImage = "create_game.png";
2546
static const char* kTextFieldBorderImage = "text_field_border.png";
2647
static const char* kJoinButtonImage = "join_game.png";
@@ -106,8 +127,8 @@ bool MainMenuScene::init() {
106127

107128
auto anonymous_label_touch_listener = EventListenerTouchOneByOne::create();
108129

109-
anonymous_label_touch_listener->onTouchBegan =
110-
[this](cocos2d::Touch* touch, cocos2d::Event* event) -> bool {
130+
anonymous_label_touch_listener->onTouchBegan = [this](Touch* touch,
131+
Event* event) -> bool {
111132
// Returns false, not consuming the event, to exit the layer if
112133
// current_state_ is not in the kAuthState or is switching states.
113134
if (previous_state_ != current_state_ || current_state_ != kAuthState) {
@@ -156,7 +177,7 @@ bool MainMenuScene::init() {
156177
Color4F(0, 0, 0, 0), 1, Color4F::WHITE);
157178

158179
// Create a text field to enter the user's email.
159-
email_text_field_ = cocos2d::TextFieldTTF::textFieldWithPlaceHolder(
180+
email_text_field_ = TextFieldTTF::textFieldWithPlaceHolder(
160181
"enter an email address", email_text_field_size, TextHAlignment::LEFT,
161182
"Arial", email_font_size);
162183
email_text_field_->setPosition(email_text_field_position);
@@ -166,8 +187,8 @@ bool MainMenuScene::init() {
166187

167188
auto email_text_field_touch_listener = EventListenerTouchOneByOne::create();
168189

169-
email_text_field_touch_listener->onTouchBegan =
170-
[this](cocos2d::Touch* touch, cocos2d::Event* event) -> bool {
190+
email_text_field_touch_listener->onTouchBegan = [this](Touch* touch,
191+
Event* event) -> bool {
171192
// Returns false, not consuming the event, to exit the layer if
172193
// current_state_ is not in the kAuthState or is switching states.
173194
if (previous_state_ != current_state_ || current_state_ != kAuthState) {
@@ -225,7 +246,7 @@ bool MainMenuScene::init() {
225246
password_border_corners, 4, Color4F(0, 0, 0, 0), 1, Color4F::WHITE);
226247

227248
// Create a text field to enter the user's password.
228-
password_text_field_ = cocos2d::TextFieldTTF::textFieldWithPlaceHolder(
249+
password_text_field_ = TextFieldTTF::textFieldWithPlaceHolder(
229250
"enter a password", password_text_field_size, TextHAlignment::LEFT,
230251
"Arial", password_font_size);
231252
password_text_field_->setPosition(password_text_field_position);
@@ -238,7 +259,7 @@ bool MainMenuScene::init() {
238259
EventListenerTouchOneByOne::create();
239260

240261
password_text_field_touch_listener->onTouchBegan =
241-
[this](cocos2d::Touch* touch, cocos2d::Event* event) -> bool {
262+
[this](Touch* touch, Event* event) -> bool {
242263
// Returns false, not consuming the event, to exit the layer if
243264
// current_state_ is not in the kAuthState or is switching states.
244265
if (previous_state_ != current_state_ || current_state_ != kAuthState) {
@@ -362,9 +383,8 @@ bool MainMenuScene::init() {
362383

363384
// Create, set the position and assign a placeholder to the text
364385
// field for the user to enter the join game uuid.
365-
TextFieldTTF* join_text_field =
366-
cocos2d::TextFieldTTF::textFieldWithPlaceHolder(
367-
"code", cocos2d::Size(200, 100), TextHAlignment::LEFT, "Arial", 55.0);
386+
TextFieldTTF* join_text_field = TextFieldTTF::textFieldWithPlaceHolder(
387+
"code", Size(200, 100), TextHAlignment::LEFT, "Arial", 55.0);
368388
join_text_field->setPosition(420, 45);
369389
join_text_field->setAnchorPoint(Vec2(0, 0));
370390
join_text_field->setColorSpaceHolder(Color3B::WHITE);
@@ -380,8 +400,7 @@ bool MainMenuScene::init() {
380400
auto join_text_field_touch_listener = EventListenerTouchOneByOne::create();
381401

382402
join_text_field_touch_listener->onTouchBegan =
383-
[join_text_field, this](cocos2d::Touch* touch,
384-
cocos2d::Event* event) -> bool {
403+
[join_text_field, this](Touch* touch, Event* event) -> bool {
385404
// Returns false, not consuming the event, to exit the layer if
386405
// current_state_ is not in the kGameMenuState or is switching states.
387406
if (previous_state_ != current_state_ || current_state_ != kGameMenuState) {
@@ -550,12 +569,12 @@ bool MainMenuScene::init() {
550569
// are missing.
551570
void MainMenuScene::InitializeFirebase() {
552571
LogMessage("Initialize Firebase App.");
553-
::firebase::App* app;
572+
App* app;
554573

555574
#if defined(_ANDROID_)
556-
app = ::firebase::App::Create(GetJniEnv(), GetActivity());
575+
app = App::Create(GetJniEnv(), GetActivity());
557576
#else
558-
app = ::firebase::App::Create();
577+
app = App::Create();
559578
#endif // defined(ANDROID)
560579

561580
LogMessage("Initialize Firebase Auth and Firebase Database.");
@@ -566,25 +585,24 @@ void MainMenuScene::InitializeFirebase() {
566585
auth_ = nullptr;
567586
void* initialize_targets[] = {&auth_, &database_};
568587

569-
const firebase::ModuleInitializer::InitializerFn initializers[] = {
570-
[](::firebase::App* app, void* data) {
588+
const ModuleInitializer::InitializerFn initializers[] = {
589+
[](::App* app, void* data) {
571590
LogMessage("Attempt to initialize Firebase Auth.");
572591
void** targets = reinterpret_cast<void**>(data);
573-
::firebase::InitResult result;
574-
*reinterpret_cast<::firebase::auth::Auth**>(targets[0]) =
575-
::firebase::auth::Auth::GetAuth(app, &result);
592+
InitResult result;
593+
*reinterpret_cast<::Auth**>(targets[0]) = Auth::GetAuth(app, &result);
576594
return result;
577595
},
578-
[](::firebase::App* app, void* data) {
596+
[](::App* app, void* data) {
579597
LogMessage("Attempt to initialize Firebase Database.");
580598
void** targets = reinterpret_cast<void**>(data);
581-
::firebase::InitResult result;
582-
*reinterpret_cast<::firebase::database::Database**>(targets[1]) =
583-
::firebase::database::Database::GetInstance(app, &result);
599+
InitResult result;
600+
*reinterpret_cast<::Database**>(targets[1]) =
601+
Database::GetInstance(app, &result);
584602
return result;
585603
}};
586604

587-
::firebase::ModuleInitializer initializer;
605+
ModuleInitializer initializer;
588606
initializer.Initialize(app, initialize_targets, initializers,
589607
sizeof(initializers) / sizeof(initializers[0]));
590608

@@ -659,8 +677,8 @@ void MainMenuScene::onEnter() {
659677
void MainMenuScene::update(float /*delta*/) {
660678
if (current_state_ != previous_state_) {
661679
if (current_state_ == kWaitingAnonymousState) {
662-
if (user_result_.status() == firebase::kFutureStatusComplete) {
663-
if (user_result_.error() == firebase::auth::kAuthErrorNone) {
680+
if (user_result_.status() == kFutureStatusComplete) {
681+
if (user_result_.error() == kAuthErrorNone) {
664682
user_ = *user_result_.result();
665683
user_uid_ = GenerateUid(10);
666684

@@ -670,8 +688,8 @@ void MainMenuScene::update(float /*delta*/) {
670688
}
671689
}
672690
} else if (current_state_ == kWaitingSignUpState) {
673-
if (user_result_.status() == firebase::kFutureStatusComplete) {
674-
if (user_result_.error() == firebase::auth::kAuthErrorNone) {
691+
if (user_result_.status() == kFutureStatusComplete) {
692+
if (user_result_.error() == kAuthErrorNone) {
675693
user_ = *user_result_.result();
676694
user_uid_ = user_->uid();
677695

@@ -686,8 +704,8 @@ void MainMenuScene::update(float /*delta*/) {
686704
}
687705
}
688706
} else if (current_state_ == kWaitingLoginState) {
689-
if (user_result_.status() == firebase::kFutureStatusComplete) {
690-
if (user_result_.error() == firebase::auth::kAuthErrorNone) {
707+
if (user_result_.status() == kFutureStatusComplete) {
708+
if (user_result_.error() == kAuthErrorNone) {
691709
user_ = *user_result_.result();
692710
user_uid_ = user_->uid();
693711

demos/TicTacToe/Classes/main_menu_scene.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
#ifndef TICTACTOE_DEMO_CLASSES_MAINMENU_SCENE_H_
1616
#define TICTACTOE_DEMO_CLASSES_MAINMENU_SCENE_H_
1717

18-
#include <string.h>
18+
#include <string>
1919

2020
#include "cocos2d.h"
2121
#include "firebase/auth.h"
2222
#include "firebase/database.h"
2323
#include "firebase/future.h"
2424

25-
using std::to_string;
25+
using cocos2d::Label;
26+
using cocos2d::TextFieldTTF;
27+
using firebase::Future;
28+
using firebase::auth::Auth;
29+
using firebase::auth::User;
30+
using firebase::database::Database;
31+
using firebase::database::DatabaseReference;
32+
using std::string;
2633

2734
class MainMenuScene : public cocos2d::Layer, public cocos2d::TextFieldDelegate {
2835
public:
@@ -69,10 +76,10 @@ class MainMenuScene : public cocos2d::Layer, public cocos2d::TextFieldDelegate {
6976
cocos2d::DrawNode* auth_background_;
7077

7178
// Labels and textfields for the authentication menu.
72-
cocos2d::Label* invalid_login_label_;
73-
cocos2d::Label* user_record_label_;
74-
cocos2d::TextFieldTTF* email_text_field_;
75-
cocos2d::TextFieldTTF* password_text_field_;
79+
Label* invalid_login_label_;
80+
Label* user_record_label_;
81+
TextFieldTTF* email_text_field_;
82+
TextFieldTTF* password_text_field_;
7683

7784
// Variable to track the current state and previous state to check against to
7885
// see if the state changed.
@@ -84,12 +91,12 @@ class MainMenuScene : public cocos2d::Layer, public cocos2d::TextFieldDelegate {
8491
int user_loses_;
8592
int user_ties_;
8693

87-
std::string user_uid_;
88-
firebase::auth::User* user_;
89-
firebase::Future<firebase::auth::User*> user_result_;
90-
firebase::database::Database* database_;
91-
firebase::auth::Auth* auth_;
92-
firebase::database::DatabaseReference ref_;
94+
string user_uid_;
95+
Auth* auth_;
96+
User* user_;
97+
Future<User*> user_result_;
98+
Database* database_;
99+
DatabaseReference ref_;
93100
};
94101

95102
#endif // TICTACTOE_DEMO_CLASSES_MAINMENU_SCENE_H_

0 commit comments

Comments
 (0)