mirror of
https://github.com/csd4ni3l/connect-the-current.git
synced 2026-01-01 04:13:41 +01:00
update utils.py and run.py to latest template
This commit is contained in:
26
run.py
26
run.py
@@ -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)
|
||||||
|
|
||||||
@@ -46,8 +47,8 @@ if os.path.exists('settings.json'):
|
|||||||
antialiasing = 0
|
antialiasing = 0
|
||||||
|
|
||||||
# Wayland workaround (can be overridden with environment variable)
|
# Wayland workaround (can be overridden with environment variable)
|
||||||
if (platform.system() == "Linux" and
|
if (platform.system() == "Linux" and
|
||||||
os.environ.get("WAYLAND_DISPLAY") and
|
os.environ.get("WAYLAND_DISPLAY") and
|
||||||
not os.environ.get("ARCADE_FORCE_MSAA")):
|
not os.environ.get("ARCADE_FORCE_MSAA")):
|
||||||
logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)")
|
logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)")
|
||||||
antialiasing = 0
|
antialiasing = 0
|
||||||
@@ -59,22 +60,20 @@ if os.path.exists('settings.json'):
|
|||||||
else:
|
else:
|
||||||
resolution = get_closest_resolution()
|
resolution = get_closest_resolution()
|
||||||
antialiasing = 4
|
antialiasing = 4
|
||||||
|
|
||||||
# Wayland workaround (can be overridden with environment variable)
|
# Wayland workaround (can be overridden with environment variable)
|
||||||
if (platform.system() == "Linux" and
|
if (platform.system() == "Linux" and
|
||||||
os.environ.get("WAYLAND_DISPLAY") and
|
os.environ.get("WAYLAND_DISPLAY") and
|
||||||
not os.environ.get("ARCADE_FORCE_MSAA")):
|
not os.environ.get("ARCADE_FORCE_MSAA")):
|
||||||
logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)")
|
logging.info("Wayland detected - disabling MSAA (set ARCADE_FORCE_MSAA=1 to override)")
|
||||||
antialiasing = 0
|
antialiasing = 0
|
||||||
|
|
||||||
fullscreen = False
|
fullscreen = False
|
||||||
style = arcade.Window.WINDOW_STYLE_DEFAULT
|
style = arcade.Window.WINDOW_STYLE_DEFAULT
|
||||||
vsync = True
|
vsync = True
|
||||||
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,15 +85,12 @@ 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)
|
||||||
display_mode = window.display.get_default_screen().get_mode()
|
display_mode = window.display.get_default_screen().get_mode()
|
||||||
|
|||||||
@@ -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))}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user