diff --git a/main.py b/main.py index ae1059a..3a6f3d0 100755 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import argparse from loguru import logger -from utils import BASE_PATH, Config +from utils import BASE_PATH, CONFIG def pos_int(string: str) -> int: @@ -61,9 +61,9 @@ logger.add( @logger.catch def main(args: argparse.ArgumentParser) -> None: if args.debug: - Config.log_level = "debug" + CONFIG.log_level = "debug" elif args.verbose: - Config.log_level = "info" + CONFIG.log_level = "info" import ai import game @@ -72,6 +72,7 @@ def main(args: argparse.ArgumentParser) -> None: ai.log.debug("Training the AI") else: game.log.debug("Running the game") + game.Menu().run() if __name__ == "__main__": diff --git a/src/ai/__init__.py b/src/ai/__init__.py index 377ee47..466da48 100644 --- a/src/ai/__init__.py +++ b/src/ai/__init__.py @@ -1,3 +1,3 @@ from .log import log -__all__ = [log] +__all__ = ["log"] diff --git a/src/ai/log.py b/src/ai/log.py index 797301f..efbcf84 100644 --- a/src/ai/log.py +++ b/src/ai/log.py @@ -1,12 +1,12 @@ from loguru import logger -from utils import BASE_PATH, Config +from utils import BASE_PATH, CONFIG log = logger.bind(name="ai") log.add( BASE_PATH / ".logs" / "ai.log", format="{time} | {level} | {message}", - level=Config.log_level.upper(), + level=CONFIG.log_level.upper(), rotation="10 MB", compression="zip", filter=lambda record: record["extra"].get("name") == "ai", diff --git a/src/game/__init__.py b/src/game/__init__.py index 377ee47..bf86e0c 100644 --- a/src/game/__init__.py +++ b/src/game/__init__.py @@ -1,3 +1,4 @@ from .log import log +from .menu import Menu -__all__ = [log] +__all__ = ["log", "Menu"] diff --git a/src/game/log.py b/src/game/log.py index 0a827d1..a793b36 100644 --- a/src/game/log.py +++ b/src/game/log.py @@ -1,12 +1,13 @@ from loguru import logger -from utils import BASE_PATH, Config +from utils import BASE_PATH, CONFIG log = logger.bind(name="game") + log.add( BASE_PATH / ".logs" / "game.log", format="{time} | {level} | {message}", - level=Config.log_level.upper(), + level=CONFIG.log_level.upper(), rotation="10 MB", compression="zip", filter=lambda record: record["extra"].get("name") == "game", diff --git a/src/game/menu.py b/src/game/menu.py new file mode 100644 index 0000000..3ece16d --- /dev/null +++ b/src/game/menu.py @@ -0,0 +1,35 @@ +import sys + +import pygame +from utils import CONFIG + + +class Menu: + def __init__(self) -> None: + pygame.init() + pygame.display.set_caption(CONFIG.window.title) + self.surface = pygame.display.set_mode(CONFIG.window.size) + self.clock = pygame.time.Clock() + + def draw(self) -> None: + self.surface.fill(CONFIG.colors.bg) + pygame.display.update() + + def run(self) -> None: + while True: + self.draw() + self.handle_events() + pygame.display.update() + self.clock.tick(CONFIG.fps) + + def handle_events(self) -> None: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.exit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_q: + self.exit() + + def exit(self) -> None: + pygame.quit() + sys.exit() diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 79db405..25916c7 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,5 +1,5 @@ -from .config import Config +from .config import CONFIG from .log import log from .path import BASE_PATH -__all__ = [BASE_PATH, Config, log] +__all__ = ["BASE_PATH", "CONFIG", "log"] diff --git a/src/utils/colors.py b/src/utils/colors.py new file mode 100644 index 0000000..6cdcdbf --- /dev/null +++ b/src/utils/colors.py @@ -0,0 +1,62 @@ +from attr import define + + +@define +class TokyoNightNight: + bg = "#1a1b26" + bg_dark = "#16161e" + bg_float = "#16161e" + bg_highlight = "#292e42" + bg_popup = "#16161e" + bg_search = "#3d59a1" + bg_sidebar = "#16161e" + bg_statusline = "#16161e" + bg_visual = "#283457" + black = "#15161e" + blue = "#7aa2f7" + blue0 = "#3d59a1" + blue1 = "#2ac3de" + blue2 = "#0db9d7" + blue5 = "#89ddff" + blue6 = "#b4f9f8" + blue7 = "#394b70" + border = "#15161e" + border_highlight = "#27a1b9" + comment = "#565f89" + cyan = "#7dcfff" + dark3 = "#545c7e" + dark5 = "#737aa2" + delta_add = "#2c5a66" + delta_delete = "#713137" + diff_add = "#20303b" + diff_change = "#1f2231" + diff_delete = "#37222c" + diff_text = "#394b70" + error = "#db4b4b" + fg = "#c0caf5" + fg_dark = "#a9b1d6" + fg_float = "#c0caf5" + fg_gutter = "#3b4261" + fg_sidebar = "#a9b1d6" + git_add = "#449dab" + git_change = "#6183bb" + git_delete = "#914c54" + git_ignore = "#545c7e" + git_signs_add = "#266d6a" + git_signs_change = "#536c9e" + git_signs_delete = "#b2555b" + green = "#9ece6a" + green1 = "#73daca" + green2 = "#41a6b5" + hint = "#1abc9c" + info = "#0db9d7" + magenta = "#bb9af7" + magenta2 = "#ff007c" + orange = "#ff9e64" + purple = "#9d7cd8" + red = "#f7768e" + red1 = "#db4b4b" + teal = "#1abc9c" + terminal_black = "#414868" + warning = "#e0af68" + yellow = "#e0af68" diff --git a/src/utils/config.py b/src/utils/config.py index b568e35..68c2dc2 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -2,6 +2,8 @@ from typing import NamedTuple from attr import define +from .colors import TokyoNightNight + class Size(NamedTuple): width: int @@ -25,6 +27,7 @@ class SideBar: @define class Window: + title = "Tetris" padding: int = 20 size: Size = Size( Game().size.width + SideBar().size.width + padding * 3, @@ -39,3 +42,8 @@ class Config: game: Game = Game() sidebar: SideBar = SideBar() window: Window = Window() + colors = TokyoNightNight() + fps: int = 60 + + +CONFIG = Config() diff --git a/src/utils/log.py b/src/utils/log.py index f2fb2ca..84264ac 100644 --- a/src/utils/log.py +++ b/src/utils/log.py @@ -1,6 +1,6 @@ from loguru import logger -from .config import Config +from .config import CONFIG from .path import BASE_PATH log = logger.bind(name="utils") @@ -8,7 +8,7 @@ log = logger.bind(name="utils") log.add( BASE_PATH / ".logs" / "utils.log", format="{time} | {level} | {message}", - level=Config.log_level.upper(), + level=CONFIG.log_level.upper(), rotation="10 MB", compression="zip", filter=lambda record: record["extra"].get("name") == "utils", diff --git a/src/utils/path.py b/src/utils/path.py index 3308883..39bd6b7 100644 --- a/src/utils/path.py +++ b/src/utils/path.py @@ -1,3 +1,3 @@ from pathlib import Path -BASE_PATH = Path(__file__).resolve().parent.parent.parent.parent +BASE_PATH = Path(__file__).resolve().parent.parent.parent