feat(game): add Menu surface / main window

This commit is contained in:
Kristofers Solo 2024-01-03 23:33:30 +02:00
parent d299934e7c
commit 3b51a9a62f
11 changed files with 122 additions and 14 deletions

View File

@ -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__":

View File

@ -1,3 +1,3 @@
from .log import log
__all__ = [log]
__all__ = ["log"]

View File

@ -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",

View File

@ -1,3 +1,4 @@
from .log import log
from .menu import Menu
__all__ = [log]
__all__ = ["log", "Menu"]

View File

@ -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",

35
src/game/menu.py Normal file
View File

@ -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()

View File

@ -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"]

62
src/utils/colors.py Normal file
View File

@ -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"

View File

@ -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()

View File

@ -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",

View File

@ -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