This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
67 lines (50 loc) · 2.36 KB
/
main.py
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
import pygame, logging
def parse_arguments(_args):
import argparse, util
debugChoices = util.UpperCaseList(["INFO","WARNING","ERROR","CRITICAL","DEBUG"])
parser = argparse.ArgumentParser(description="PWA Ping Pong Scoreboard")
# parser.add_argument("--fps", help="Override the default game FPS: 30", type=int, default=30)
parser.add_argument("-l", "--loglevel", help="Logging level", choices=debugChoices, default="INFO")
parser.add_argument("-f", "--logpath", help="The path to store the log file.")
parser.add_argument("--probe", help="For use on Raspberry PI, probes system for GPU.", action="store_true")
parser.add_argument("--http-server", help="Enable use of http server.", action="store_true", default=False)
parser.add_argument("--http-host", help="Override the default http host: localhost", default="localhost")
parser.add_argument("--http-port", help="Override the default http port: 1337", type=int, default=1337)
args = parser.parse_args(_args)
args.caption = "PWA Ping Pong Scoreboard"
args.target_score = 15
args.screen_width = 1024
args.screen_height = 768
args.logscreen = True
return args
def init_logging(args):
import logging.handlers
rootLogger = logging.getLogger()
rootLogger.setLevel(getattr(logging, args.loglevel.upper(), None))
if not args.logscreen:
lhStdout = rootLogger.handlers[0] # screen is only hanlder by default
rootLogger.removeHandler(lhStdout) # this will turn off screen logging
if args.logpath != None:
fileHandler = logging.FileHandler(args.logpath)
fileHandler.setLevel(getattr(logging, args.loglevel.upper(), None))
rootLogger.addHandler(fileHandler)
logging.debug("Logging Initialized")
logging.debug("Command Arguments: {}".format(args))
def main(_args):
from game import Runner, Scoreboard
from web import Server
# Parse Command Arguments
args = parse_arguments(_args)
# Intitialize Logging
init_logging(args)
# Create the scoreboard object.
scoreboard = Scoreboard(args)
# Stand up a small HTTP server for remote control (if enabled)
webserver = Server(scoreboard, args)
webserver.start()
# Start up game loop
runner = Runner(args)
runner.execute(scoreboard)
if __name__ == "__main__":
import sys
sys.exit(main(sys.argv[1:]))