Main menu

This commit is contained in:
Matyáš Caras 2022-03-23 14:21:44 +01:00 committed by GitHub
parent 5ff4eb2b4a
commit a398bbd5dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,24 @@ from lib.game import *
from colorama import init, Back, Fore from colorama import init, Back, Fore
from os import mkdir, listdir from os import mkdir, listdir
def lang():
lang = "en"
if not (path.exists("./saves/lang")):
mkdir("./saves")
with open("./saves/lang","w") as f:
f.write("en")
else:
with open("./saves/lang","r") as f:
lang = f.read()
if lang == "cz":
lang = "cz"
data = ""
with open(f"./lib/lang/{lang}.yml",encoding="utf-8") as f:
data = yaml.load(f,Loader=SafeLoader)
return data
def main(): # TODO: Maybe a menu for available text games? def main(): # TODO: Maybe a menu for available text games?
l = lang()
init() init()
if(not isdir("./games")): if(not isdir("./games")):
mkdir("./games") mkdir("./games")
@ -14,11 +30,22 @@ def main(): # TODO: Maybe a menu for available text games?
# finds available games # finds available games
try: try:
# try parsing # try parsing
g = load(f"./games/{file}") g = load(f"./games/{file}",l)
games.append(g) games.append(g)
except Exception as e: except Exception as e:
print(f"{Back.RED}{Fore.RED}An exception has occured while loading {file}:") print(f"{Back.RED}{Fore.RED}{l['error_loading']} {file}:")
print(e) print(e)
# PRINT OUT GAME SELECT
# TODO SWITCH TO MENU MANAGER
print(" TEXTY ")
print(l['available'])
if len(games) < 1:
print(l['no_games'])
else:
for i,g in enumerate(games):
print(f"{i} - {g.name}")
print(f"{len(games)} - {l['quit']}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()