forked from Hohenzoler/optyka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (50 loc) · 1.68 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
import cProfile
import pstats
import logging
import tkinter
from datetime import datetime
from classes import game
from gui import gui_main as gui
import pygame
import settingsSetup
from screens import startscreen as ss
import os
# Create a "logs" folder if it doesn't exist
if not os.path.exists("logs"):
os.makedirs("logs")
if not os.path.exists("saves"):
os.makedirs("saves")
if not os.path.exists("presets"):
os.makedirs("presets")
# Set up the logging configuration
log_file = f"logs/{datetime.now().strftime('%Y-%m-%d')}.log"
logging.basicConfig(filename=log_file, level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
version = '1.3-enhanced'
def new_game(save, preset):
try:
settings = settingsSetup.start()
width = settings['WIDTH']
height = settings['HEIGHT']
position = settings['HOTBAR_POSITION']
programIcon = pygame.image.load('images/torch_icon.png')
pygame.display.set_icon(programIcon)
game_instance = game.Game(save, preset)
GUI = gui.GUI(game_instance)
game_instance.loop()
except Exception as e:
# Log any unhandled exceptions
logging.error(e, exc_info=True)
raise
def main():
while True:
try:
startscreen = ss.StartScreen(version)
new_game(startscreen.save_to_load, startscreen.preset)
except Exception as e:
print(e)
break
if __name__ == "__main__":
profile_filename = 'profile_results.prof'
cProfile.run('main()', profile_filename)
p = pstats.Stats(profile_filename)
p.sort_stats('tottime').print_stats()