mirror of
https://github.com/csd4ni3l/shatterstack.git
synced 2026-01-01 04:23:48 +01:00
Initial version
This commit is contained in:
50
utils/constants.py
Normal file
50
utils/constants.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import arcade.color
|
||||
from arcade.types import Color
|
||||
from arcade.gui.widgets.buttons import UITextureButtonStyle
|
||||
|
||||
menu_background_color = Color(28, 28, 28)
|
||||
log_dir = 'logs'
|
||||
CELL_SIZE = 48
|
||||
ROWS = 14
|
||||
COLS = 14
|
||||
OUTLINE_WIDTH = 2
|
||||
|
||||
button_style = {'normal': UITextureButtonStyle(font_name="Protest Strike", font_color=arcade.color.BLACK), 'hover': UITextureButtonStyle(font_name="Protest Strike", font_color=arcade.color.BLACK),
|
||||
'press': UITextureButtonStyle(font_name="Protest Strike", font_color=arcade.color.BLACK), 'disabled': UITextureButtonStyle(font_name="Protest Strike", font_color=arcade.color.BLACK)}
|
||||
|
||||
SHAPES = {
|
||||
"I": [(0, 0), (1, 0), (2, 0), (3, 0)],
|
||||
"I_R1": [(0, 0), (0, 1), (0, 2), (0, 3)],
|
||||
"O": [(0, 0), (1, 0), (0, 1), (1, 1)],
|
||||
"T": [(0, 0), (1, 0), (2, 0), (1, 1)],
|
||||
"T_R1": [(1, 0), (1, 1), (1, 2), (0, 1)],
|
||||
"T_R2": [(0, 1), (1, 1), (2, 1), (1, 0)],
|
||||
"T_R3": [(0, 0), (0, 1), (0, 2), (1, 1)],
|
||||
"L": [(0, 0), (0, 1), (0, 2), (1, 2)],
|
||||
"L_R1": [(0, 1), (1, 1), (2, 1), (2, 0)],
|
||||
"L_R2": [(1, 0), (1, 1), (1, 2), (0, 0)],
|
||||
"L_R3": [(0, 0), (1, 0), (2, 0), (0, 1)],
|
||||
"J": [(1, 0), (1, 1), (1, 2), (0, 2)],
|
||||
"J_R1": [(0, 0), (0, 1), (1, 1), (2, 1)],
|
||||
"J_R2": [(0, 0), (1, 0), (0, 1), (0, 2)],
|
||||
"J_R3": [(0, 0), (1, 0), (2, 0), (2, 1)],
|
||||
"S": [(1, 0), (2, 0), (0, 1), (1, 1)],
|
||||
"S_R1": [(0, 0), (0, 1), (1, 1), (1, 2)],
|
||||
"Z": [(0, 0), (1, 0), (1, 1), (2, 1)],
|
||||
"Z_R1": [(1, 0), (0, 1), (1, 1), (0, 2)],
|
||||
"BLOB": [
|
||||
(0, 0), (1, 0), (2, 0),
|
||||
(0, 1), (1, 1), (2, 1),
|
||||
(0, 2), (1, 2), (2, 2)
|
||||
],
|
||||
}
|
||||
|
||||
COLORS = {
|
||||
"red": (255, 90, 90, 255),
|
||||
"blue": (100, 180, 255, 255),
|
||||
"green": (100, 255, 160, 255),
|
||||
"yellow": (255, 230, 100, 255),
|
||||
"purple": (200, 100, 255, 255),
|
||||
"orange": (255, 160, 90, 255),
|
||||
"teal": (100, 255, 255, 255),
|
||||
}
|
||||
4
utils/preload.py
Normal file
4
utils/preload.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import arcade.gui, arcade
|
||||
|
||||
button_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button.png"))
|
||||
button_hovered_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button_hovered.png"))
|
||||
90
utils/utils.py
Normal file
90
utils/utils.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import logging, arcade, arcade.gui, sys, traceback
|
||||
|
||||
from utils.constants import menu_background_color
|
||||
|
||||
import pyglet.info, pyglet.event
|
||||
|
||||
def dump_platform():
|
||||
import platform
|
||||
logging.debug(f'Platform: {platform.platform()}')
|
||||
logging.debug(f'Release: {platform.release()}')
|
||||
logging.debug(f'Machine: {platform.machine()}')
|
||||
logging.debug(f'Architecture: {platform.architecture()}')
|
||||
|
||||
def dump_gl(context=None):
|
||||
if context is not None:
|
||||
info = context.get_info()
|
||||
else:
|
||||
from pyglet.gl import gl_info as info
|
||||
logging.debug(f'gl_info.get_version(): {info.get_version()}')
|
||||
logging.debug(f'gl_info.get_vendor(): {info.get_vendor()}')
|
||||
logging.debug(f'gl_info.get_renderer(): {info.get_renderer()}')
|
||||
|
||||
def print_debug_info():
|
||||
logging.debug('########################## DEBUG INFO ##########################')
|
||||
logging.debug('')
|
||||
dump_platform()
|
||||
dump_gl()
|
||||
logging.debug('')
|
||||
logging.debug(f'Number of screens: {len(pyglet.display.get_display().get_screens())}')
|
||||
logging.debug('')
|
||||
for n, screen in enumerate(pyglet.display.get_display().get_screens()):
|
||||
logging.debug(f"Screen #{n+1}:")
|
||||
logging.debug(f'DPI: {screen.get_dpi()}')
|
||||
logging.debug(f'Scale: {screen.get_scale()}')
|
||||
logging.debug(f'Size: {screen.width}, {screen.height}')
|
||||
logging.debug(f'Position: {screen.x}, {screen.y}')
|
||||
logging.debug('')
|
||||
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('ShatterStack - 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))}")
|
||||
|
||||
def get_closest_resolution():
|
||||
allowed_resolutions = [(800, 600), (1024, 768), (1280, 720), (1366, 768), (1440, 900), (1600,900), (1920,1080), (2560,1440), (3840,2160)]
|
||||
screen_width, screen_height = arcade.get_screens()[0].width, arcade.get_screens()[0].height
|
||||
if (screen_width, screen_height) in allowed_resolutions:
|
||||
if not allowed_resolutions.index((screen_width, screen_height)) == 0:
|
||||
closest_resolution = allowed_resolutions[allowed_resolutions.index((screen_width, screen_height))-1]
|
||||
else:
|
||||
closest_resolution = (screen_width, screen_height)
|
||||
else:
|
||||
target_width, target_height = screen_width // 2, screen_height // 2
|
||||
|
||||
closest_resolution = min(
|
||||
allowed_resolutions,
|
||||
key=lambda res: abs(res[0] - target_width) + abs(res[1] - target_height)
|
||||
)
|
||||
return closest_resolution
|
||||
|
||||
class FakePyPresence():
|
||||
def __init__(self):
|
||||
...
|
||||
def update(self, *args, **kwargs):
|
||||
...
|
||||
def close(self, *args, **kwargs):
|
||||
...
|
||||
Reference in New Issue
Block a user