From 0d1646e0ff1ef39478d7145e80f45d4dfaa380b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Tue, 22 Mar 2022 11:22:50 +0100 Subject: [PATCH] Start main menu --- __main__.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/__main__.py b/__main__.py index 1ba0016..590f478 100644 --- a/__main__.py +++ b/__main__.py @@ -1,17 +1,24 @@ -from sys import argv +from genericpath import isdir from lib.game import * -from colorama import init +from colorama import init, Back, Fore +from os import mkdir, listdir + def main(): # TODO: Maybe a menu for available text games? init() - if len(argv)<2: - print("You need to specify a path to a YAML file") - exit(1) - else: - game = load(argv[1]) - if(game is None): - exit(1) - game.main_menu() + if(not isdir("./games")): + mkdir("./games") + games = [] + for file in listdir("./games"): + if file.endswith("yml") or file.endswith("yaml"): + # finds available games + try: + # try parsing + g = load(f"./games/{file}") + games.append(g) + except Exception as e: + print(f"{Back.RED}{Fore.RED}An exception has occured while loading {file}:") + print(e) if __name__ == "__main__": - main() \ No newline at end of file + main()