diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-02-11 20:29:54 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-02-11 20:30:22 +0100 |
commit | 27edf9ced3b02529015ec4a0cf0bf61f390e0fbb (patch) | |
tree | fca079b6f442936a74f6f801de2ced94d6e12b59 | |
parent | c3b09543f50b49d6b91dfc93e6d84166cd4535f3 (diff) |
Move the argument parsing in the main function
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rwxr-xr-x | cameltris/__main__.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/cameltris/__main__.py b/cameltris/__main__.py index a3333c5..f007cca 100755 --- a/cameltris/__main__.py +++ b/cameltris/__main__.py @@ -13,22 +13,29 @@ from .screens.pause import Pause as PauseScreen from .misc import Pause, UnPause -def main(args: dict): - """ Main function to be called with option arguments already parsed """ +def main() -> None: + """ Main entry point. """ + parser = argparse.ArgumentParser() + + parser.add_argument("--starting-level", type=int, choices=list(range(1, 30)), default=1) + parser.add_argument("--joystick", type=int, dest="joystick_id", metavar="Joystick ID") + + args = parser.parse_args() + pygame.init() screen = pygame.display.set_mode((801, 1000)) controller: Controller - if args["joystick_id"] is not None: - joystick = pygame.joystick.Joystick(args["joystick_id"]) + if args.joystick_id is not None: + joystick = pygame.joystick.Joystick(args.joystick_id) joystick.init() controller = JoystickController(joystick) else: controller = KeyboardController(pygame.key) # Just one player - players = [Player(controller, args["starting_level"])] + players = [Player(controller, args.starting_level)] for player in players: player.refresh_piece_preview_canvas() @@ -53,9 +60,4 @@ def main(args: dict): if __name__ == "__main__": - PARSER = argparse.ArgumentParser() - - PARSER.add_argument("--starting-level", type=int, choices=list(range(1, 30)), default=1) - PARSER.add_argument("--joystick", type=int, dest="joystick_id", metavar="Joystick ID") - - main(vars(PARSER.parse_args())) + main() |