From cca17b2ce3c017db2c01fc15b8492ce0a4145d97 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Sat, 13 Dec 2025 15:48:59 +0100 Subject: [PATCH] update utils.py and run.py to latest template --- run.py | 26 +++++++++++--------------- utils/utils.py | 29 +---------------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/run.py b/run.py index 9838911..f154e43 100644 --- a/run.py +++ b/run.py @@ -10,7 +10,6 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) pyglet.resource.path.append(script_dir) 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.constants import log_dir, menu_background_color from menus.main import Main @@ -18,6 +17,8 @@ from arcade.experimental.controller_window import ControllerWindow sys.excepthook = on_exception +__builtins__.print = lambda *args, **kwargs: logging.debug(" ".join(map(str, args))) + if not log_dir in os.listdir(): os.makedirs(log_dir) @@ -46,8 +47,8 @@ if os.path.exists('settings.json'): antialiasing = 0 # Wayland workaround (can be overridden with environment variable) - if (platform.system() == "Linux" and - os.environ.get("WAYLAND_DISPLAY") and + if (platform.system() == "Linux" and + os.environ.get("WAYLAND_DISPLAY") and not os.environ.get("ARCADE_FORCE_MSAA")): logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)") antialiasing = 0 @@ -59,22 +60,20 @@ if os.path.exists('settings.json'): else: resolution = get_closest_resolution() antialiasing = 4 - + # Wayland workaround (can be overridden with environment variable) - if (platform.system() == "Linux" and - os.environ.get("WAYLAND_DISPLAY") and + if (platform.system() == "Linux" and + os.environ.get("WAYLAND_DISPLAY") and not os.environ.get("ARCADE_FORCE_MSAA")): logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)") antialiasing = 0 - + fullscreen = False style = arcade.Window.WINDOW_STYLE_DEFAULT vsync = True fps_limit = 0 settings = { - "music": True, - "music_volume": 50, "resolution": f"{resolution[0]}x{resolution[1]}", "antialiasing": "4x MSAA", "window_mode": "Windowed", @@ -86,15 +85,12 @@ else: with open("settings.json", "w") as file: file.write(json.dumps(settings)) -# if settings.get("music", True): -# theme_sound.play(volume=settings.get("music_volume", 50) / 100, loop=True) - 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: 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: window.set_vsync(True) display_mode = window.display.get_default_screen().get_mode() diff --git a/utils/utils.py b/utils/utils.py index e2aa726..b2e2607 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -1,8 +1,4 @@ -import logging, arcade, arcade.gui, sys, traceback - -from utils.constants import menu_background_color - -import pyglet.info, pyglet.event +import logging, arcade, traceback, pyglet.display def dump_platform(): import platform @@ -38,29 +34,6 @@ def print_debug_info(): logging.debug('########################## DEBUG INFO ##########################') 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): logging.error(f"Unhandled exception:\n{''.join(traceback.format_exception(exc_info[1], limit=None))}")