Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5049a9f

Browse files
Run game script (#70)
* Function to CreateRectangle. Function to InitializeAuthenticaionLayer. Function to InitializeLoginLayer. Function to InitializeSignUpLayer. * Creating setup, rebuild and run process. * Consistent spacing changes. * Pylint yapf formatting changes. More specific instructions.
1 parent 4ee541b commit 5049a9f

File tree

3 files changed

+240
-59
lines changed

3 files changed

+240
-59
lines changed

‎demos/TicTacToe/rebuild_demo.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/python
2+
# coding=utf-8
3+
4+
# Copyright 2020 Google Inc. All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
import logging
19+
import os
20+
import subprocess
21+
import sys
22+
23+
24+
def logger_setup():
25+
# The root logger of the hierarchy.
26+
logger = logging.getLogger()
27+
logger.setLevel(logging.DEBUG)
28+
29+
# Add a StreamHandler to log to stdout.
30+
stream_handler = logging.StreamHandler(sys.stdout)
31+
stream_handler.setLevel(logging.DEBUG)
32+
formatter = logging.Formatter(
33+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
34+
stream_handler.setFormatter(formatter)
35+
logger.addHandler(stream_handler)
36+
37+
return logger
38+
39+
40+
def log_run(dir, logger, cmd):
41+
# Logs the command.
42+
logger.info(cmd)
43+
# Runs the command.
44+
subprocess.call(cmd, cwd=dir, shell=True)
45+
46+
47+
def main():
48+
"""The main function."""
49+
# The run_demo.py script directory.
50+
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
51+
52+
# Sets up the logging format and handler.
53+
logger = logger_setup()
54+
55+
# Directory and file paths.
56+
game_name = "tic_tac_toe_demo"
57+
build_dir = os.path.join(ROOT_DIRECTORY, game_name, "build")
58+
59+
# Checks whether the build directory was created.
60+
if os.path.isdir(build_dir):
61+
logger.info("Building the demo...")
62+
# Builds the tic_tac_toe_demo executable.
63+
log_run(build_dir, logger, "cmake --build .")
64+
else:
65+
logger.error(
66+
"Build directory expected at {} does not exist.".format(build_dir))
67+
exit()
68+
69+
70+
# Check to see if this script is being called directly.
71+
if __name__ == "__main__":
72+
exit(main())

‎demos/TicTacToe/run_demo.py‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/python
2+
# coding=utf-8
3+
4+
# Copyright 2020 Google Inc. All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
import logging
19+
import os
20+
import subprocess
21+
import sys
22+
23+
24+
def logger_setup():
25+
# The root logger of the hierarchy.
26+
logger = logging.getLogger()
27+
logger.setLevel(logging.DEBUG)
28+
29+
# Add a StreamHandler to log to stdout.
30+
stream_handler = logging.StreamHandler(sys.stdout)
31+
stream_handler.setLevel(logging.DEBUG)
32+
formatter = logging.Formatter(
33+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
34+
stream_handler.setFormatter(formatter)
35+
logger.addHandler(stream_handler)
36+
37+
return logger
38+
39+
40+
def log_run(dir, logger, cmd):
41+
# Logs the command.
42+
logger.info(cmd)
43+
# Runs the command.
44+
subprocess.call(cmd, cwd=dir, shell=True)
45+
46+
47+
def main():
48+
"""The main function."""
49+
# The run_demo.py script directory.
50+
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
51+
52+
# Sets up the logging format and handler.
53+
logger = logger_setup()
54+
55+
# Directory paths.
56+
game_name = "tic_tac_toe_demo"
57+
executable_dir = os.path.join(ROOT_DIRECTORY, game_name, "build", "bin",
58+
game_name, "Debug")
59+
60+
# Checks whether the demo was set up properly.
61+
if not os.path.isdir(executable_dir):
62+
logger.error(
63+
"Demo setup incomplete. Did you run the setup script first?")
64+
exit()
65+
66+
# Checks whether the google-services.json exists in the debug directory.
67+
if not os.path.isfile(os.path.join(executable_dir,
68+
"google-services.json")):
69+
logger.error(
70+
"google-services.json file is missing in {} directory.".format(
71+
executable_dir))
72+
exit()
73+
74+
# Checks whether the executable exists in the debug directory.
75+
if os.path.isfile(os.path.join(executable_dir,
76+
"{}.exe".format(game_name))):
77+
logger.info("Lanching the demo...")
78+
# Runs the tic-tac-toe executable.
79+
log_run(executable_dir, logger, '{}.exe'.format(game_name))
80+
else:
81+
logger.error("Game executable does not exist.")
82+
exit()
83+
84+
85+
# Check to see if this script is being called directly.
86+
if __name__ == "__main__":
87+
exit(main())

‎demos/TicTacToe/setup_demo.py‎

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,74 +21,96 @@
2121
import subprocess
2222
import sys
2323

24+
2425
def logger_setup():
25-
# The root logger of the hierarchy.
26-
logger = logging.getLogger()
27-
logger.setLevel(logging.DEBUG)
26+
# The root logger of the hierarchy.
27+
logger = logging.getLogger()
28+
logger.setLevel(logging.DEBUG)
29+
30+
# Add a StreamHandler to log to stdout.
31+
stream_handler = logging.StreamHandler(sys.stdout)
32+
stream_handler.setLevel(logging.DEBUG)
33+
formatter = logging.Formatter(
34+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
35+
stream_handler.setFormatter(formatter)
36+
logger.addHandler(stream_handler)
2837

29-
# Add a StreamHandler to log to stdout.
30-
stream_handler = logging.StreamHandler(sys.stdout)
31-
stream_handler.setLevel(logging.DEBUG)
32-
formatter = logging.Formatter(
33-
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
34-
stream_handler.setFormatter(formatter)
35-
logger.addHandler(stream_handler)
38+
return logger
3639

37-
return logger
3840

3941
def log_run(dir, logger, cmd):
40-
# Logs the command.
41-
logger.info(cmd)
42-
# Runs the command.
43-
subprocess.call(cmd, cwd=dir, shell=True)
42+
# Logs the command.
43+
logger.info(cmd)
44+
# Runs the command.
45+
subprocess.call(cmd, cwd=dir, shell=True)
46+
4447

4548
def modify_proj_file(dir):
46-
f = fileinput.FileInput(files = [os.path.join(dir,"main.cpp")], inplace = True)
47-
for line in f:
48-
print line.replace("AppDelegate.h", "app_delegate.h"),
49+
f = fileinput.FileInput(files=[os.path.join(dir, "main.cpp")],
50+
inplace=True)
51+
for line in f:
52+
print line.replace("AppDelegate.h", "app_delegate.h"),
53+
4954

5055
def main():
51-
"""The main function."""
52-
# The setup_demo.py script directory.
53-
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
54-
55-
# Sets up the logging format and handler.
56-
logger = logger_setup()
57-
58-
# Directory paths.
59-
game_name = "tic_tac_toe_demo"
60-
game_resources_dir = os.path.join(ROOT_DIRECTORY, "game_resources")
61-
game_files_dir = os.path.join(ROOT_DIRECTORY, game_name);
62-
windows_proj_dir = os.path.join(game_files_dir,"proj.win32")
63-
mac_proj_dir = os.path.join(game_files_dir,"proj.ios_mac","mac")
64-
linux_proj_dir = os.path.join(game_files_dir,"proj.linux")
65-
build_dir = os.path.join(game_files_dir,"build")
66-
executable_dir = os.path.join(build_dir,"bin",game_name,"Debug")
67-
68-
# Creating the cocos2d-x project.
69-
log_run(ROOT_DIRECTORY, logger,"cocos new {0} -p com.DemoApp.{0} -l cpp -d .".format(game_name))
70-
71-
# Removing the default cocos2d-x project files.
72-
log_run(ROOT_DIRECTORY, logger,"rm -r {0}/Classes {0}/Resources {0}/CMakeLists.txt".format(game_files_dir) )
73-
74-
# Copies the google-services.json file into the correct directory to run the executable.
75-
log_run(ROOT_DIRECTORY, logger,"cp google_services/google-services.json {}".format(os.path.join(game_resources_dir,"build","bin", game_name, "Debug")))
76-
77-
# Copies the tic-tac-toe game files into the cocos2d-x project files.
78-
log_run(ROOT_DIRECTORY, logger, "cp {} {} -TRv".format(game_resources_dir,game_files_dir))
79-
80-
# Changes the windows project main.cpp to include the new app_delegate header.
81-
modify_proj_file(windows_proj_dir)
82-
83-
# Changes directory into the build directory.
84-
log_run(build_dir, logger, 'cmake .. -G "Visual Studio 16 2019" -A Win32')
85-
86-
# Runs cmake with the Visual Studio 2019 as the generator and windows as the target.
87-
log_run(build_dir, logger,"cmake --build .")
88-
89-
# Runs the tic-tac-toe executable.
90-
log_run(executable_dir, logger,'{}.exe'.format(game_name))
56+
"""The main function."""
57+
# The setup_demo.py script directory.
58+
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
59+
60+
# Sets up the logging format and handler.
61+
logger = logger_setup()
62+
63+
# Directory paths.
64+
game_name = "tic_tac_toe_demo"
65+
game_resources_dir = os.path.join(ROOT_DIRECTORY, "game_resources")
66+
game_files_dir = os.path.join(ROOT_DIRECTORY, game_name)
67+
windows_proj_dir = os.path.join(game_files_dir, "proj.win32")
68+
mac_proj_dir = os.path.join(game_files_dir, "proj.ios_mac", "mac")
69+
linux_proj_dir = os.path.join(game_files_dir, "proj.linux")
70+
build_dir = os.path.join(game_files_dir, "build")
71+
executable_dir = os.path.join(build_dir, "bin", game_name, "Debug")
72+
73+
# Checks whether the google-services.json exists in the debug directory.
74+
if not os.path.isfile(
75+
os.path.join(ROOT_DIRECTORY, "google_services",
76+
"google-services.json")):
77+
# Runs the tic-tac-toe executable.
78+
logger.error("google_services/google-services.json is missing.")
79+
exit()
80+
81+
# Creating the cocos2d-x project.
82+
log_run(ROOT_DIRECTORY, logger,
83+
"cocos new {0} -p com.DemoApp.{0} -l cpp -d .".format(game_name))
84+
85+
# Removing the default cocos2d-x project files.
86+
log_run(
87+
ROOT_DIRECTORY, logger,
88+
"rm -r {0}/Classes {0}/Resources {0}/CMakeLists.txt".format(
89+
game_files_dir))
90+
91+
# Copies the google-services.json file into the correct directory to run the executable.
92+
log_run(
93+
ROOT_DIRECTORY, logger,
94+
"cp google_services/google-services.json {}".format(
95+
os.path.join(game_resources_dir, "build", "bin", game_name,
96+
"Debug")))
97+
98+
# Copies the tic-tac-toe game files into the cocos2d-x project files.
99+
log_run(ROOT_DIRECTORY, logger,
100+
"cp {} {} -TRv".format(game_resources_dir, game_files_dir))
101+
102+
# Changes the windows project main.cpp to include the new app_delegate header.
103+
modify_proj_file(windows_proj_dir)
104+
105+
# Runs cmake with the Visual Studio 2019 as the generator and windows as the target.
106+
log_run(build_dir, logger, 'cmake .. -G "Visual Studio 16 2019" -A Win32')
107+
108+
# Builds the tic_tac_toe_demo executable.
109+
log_run(build_dir, logger, "cmake --build .")
110+
111+
logger.info("Demo setup succeeded.")
112+
91113

92114
# Check to see if this script is being called directly.
93115
if __name__ == "__main__":
94-
exit(main())
116+
exit(main())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /