This repository has been archived on 2022-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
texty/__main__.py

62 lines
1.8 KiB
Python
Raw Normal View History

2022-03-22 11:22:50 +01:00
from genericpath import isdir
2022-05-16 15:56:11 +02:00
import sys
2022-01-25 17:16:07 +01:00
from lib.game import *
2022-03-22 11:22:50 +01:00
from colorama import init, Back, Fore
2022-03-24 18:20:39 +01:00
from os import mkdir, listdir, path
2022-03-22 11:22:50 +01:00
2022-03-23 14:21:44 +01:00
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
2021-11-02 17:40:54 +01:00
2022-04-06 10:03:21 +02:00
def main():
2022-03-23 14:21:44 +01:00
l = lang()
init()
2022-03-22 11:22:50 +01:00
if(not isdir("./games")):
mkdir("./games")
games = []
for file in listdir("./games"):
if file.endswith("yml") or file.endswith("yaml"):
2022-05-16 15:56:11 +02:00
# hledá hry
if len(sys.argv) > 1 and (sys.argv[1] == "-v" or sys.argv[1] == "--verbose"): # nepoužívá try/except pro vypsání celé chybové hlášky (debugování)
2022-03-23 14:21:44 +01:00
g = load(f"./games/{file}",l)
2022-05-16 15:56:11 +02:00
if g is not None:
games.append(g)
else:
try:
# parsuje
g = load(f"./games/{file}",l)
if g is not None:
games.append(g)
except Exception as e:
print(f"{Back.RED}{Fore.WHITE}{l['error_loading']} {file}{Fore.RESET}{Back.RESET}:")
print(e)
print(l['enter'])
input()
2022-03-24 18:20:39 +01:00
2022-05-16 15:56:11 +02:00
# výpis menu
2022-03-23 14:21:44 +01:00
if len(games) < 1:
print(l['no_games'])
else:
2022-03-24 18:20:39 +01:00
names = []
2022-04-06 10:03:21 +02:00
for n in games:
2022-04-19 12:36:05 +02:00
if(n is not None):
names.append(n.name)
2022-03-24 18:20:39 +01:00
m = MenuManager(names,f" TEXTY \n{l['available']}")
games[m.selected].main_menu()
2022-03-23 14:21:44 +01:00
2021-11-02 17:40:54 +01:00
if __name__ == "__main__":
2022-03-22 11:22:50 +01:00
main()