update utils.py and run.py to latest template

This commit is contained in:
csd4ni3l
2025-12-13 15:48:59 +01:00
parent 373d94a603
commit cca17b2ce3
2 changed files with 12 additions and 43 deletions

12
run.py
View File

@@ -10,7 +10,6 @@ script_dir = os.path.dirname(os.path.abspath(__file__))
pyglet.resource.path.append(script_dir) pyglet.resource.path.append(script_dir)
pyglet.font.add_directory(os.path.join(script_dir, 'assets', 'fonts')) pyglet.font.add_directory(os.path.join(script_dir, 'assets', 'fonts'))
from utils.utils import get_closest_resolution, print_debug_info, on_exception from utils.utils import get_closest_resolution, print_debug_info, on_exception
from utils.constants import log_dir, menu_background_color from utils.constants import log_dir, menu_background_color
from menus.main import Main from menus.main import Main
@@ -18,6 +17,8 @@ from arcade.experimental.controller_window import ControllerWindow
sys.excepthook = on_exception sys.excepthook = on_exception
__builtins__.print = lambda *args, **kwargs: logging.debug(" ".join(map(str, args)))
if not log_dir in os.listdir(): if not log_dir in os.listdir():
os.makedirs(log_dir) os.makedirs(log_dir)
@@ -73,8 +74,6 @@ else:
fps_limit = 0 fps_limit = 0
settings = { settings = {
"music": True,
"music_volume": 50,
"resolution": f"{resolution[0]}x{resolution[1]}", "resolution": f"{resolution[0]}x{resolution[1]}",
"antialiasing": "4x MSAA", "antialiasing": "4x MSAA",
"window_mode": "Windowed", "window_mode": "Windowed",
@@ -86,14 +85,11 @@ else:
with open("settings.json", "w") as file: with open("settings.json", "w") as file:
file.write(json.dumps(settings)) file.write(json.dumps(settings))
# if settings.get("music", True):
# theme_sound.play(volume=settings.get("music_volume", 50) / 100, loop=True)
try: try:
window = ControllerWindow(width=resolution[0], height=resolution[1], title='Connect the Current', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) window = ControllerWindow(width=resolution[0], height=resolution[1], title='GameName', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False)
except (FileNotFoundError, PermissionError) as e: except (FileNotFoundError, PermissionError) as e:
logging.warning(f"Controller support unavailable: {e}. Falling back to regular window.") logging.warning(f"Controller support unavailable: {e}. Falling back to regular window.")
window = arcade.Window(width=resolution[0], height=resolution[1], title='Connect the Current', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) window = arcade.Window(width=resolution[0], height=resolution[1], title='GameName', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False)
if vsync: if vsync:
window.set_vsync(True) window.set_vsync(True)

View File

@@ -1,8 +1,4 @@
import logging, arcade, arcade.gui, sys, traceback import logging, arcade, traceback, pyglet.display
from utils.constants import menu_background_color
import pyglet.info, pyglet.event
def dump_platform(): def dump_platform():
import platform import platform
@@ -38,29 +34,6 @@ def print_debug_info():
logging.debug('########################## DEBUG INFO ##########################') logging.debug('########################## DEBUG INFO ##########################')
logging.debug('') logging.debug('')
class ErrorView(arcade.gui.UIView):
def __init__(self, message, title):
super().__init__()
self.message = message
self.title = title
def exit(self):
logging.fatal('Exited with error code 1.')
sys.exit(1)
def on_show_view(self):
super().on_show_view()
self.window.set_caption('Connect the Current - Error')
self.window.set_mouse_visible(True)
self.window.set_exclusive_mouse(False)
arcade.set_background_color(menu_background_color)
msgbox = arcade.gui.UIMessageBox(width=self.window.width / 2, height=self.window.height / 2, message_text=self.message, title=self.title)
msgbox.on_action = lambda _: self.exit()
self.add_widget(msgbox)
def on_exception(*exc_info): def on_exception(*exc_info):
logging.error(f"Unhandled exception:\n{''.join(traceback.format_exception(exc_info[1], limit=None))}") logging.error(f"Unhandled exception:\n{''.join(traceback.format_exception(exc_info[1], limit=None))}")