Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Virashu committed Feb 15, 2024
1 parent 865e182 commit b802a63
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion danmaku/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_saved_game() -> dict:
return game


def get_game_history() -> list:
def get_game_history() -> list[dict[str, int]]:
"""Get game history from database
Returns list: [{"score", "level", "time"}]
"""
Expand Down
21 changes: 14 additions & 7 deletions danmaku/ui/button.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Menu button class declaration."""

from dataclasses import dataclass
from typing import Any

import pygame
import vgame
from vgame.graphics import Graphics, Sprite


class ClickableButton(vgame.graphics.Sprite):
class ClickableButton(Sprite):
"""Menu button class clickable by mouse"""

def __init__(
Expand All @@ -24,7 +25,7 @@ def __init__(
self.text = text
self.font_size = font_size

def draw(self, graphics: vgame.graphics.Graphics):
def draw(self, graphics: Graphics):
graphics.rectangle(self.rect.topleft, self.rect.size, self.button_color)
graphics.text(f" {self.text} ", self.rect.topleft, self.text_color)

Expand All @@ -43,10 +44,10 @@ class Button:
codename: str


class Cursor(vgame.graphics.Sprite):
class Cursor(Sprite):
"""Cursor class"""

def __init__(self, xy):
def __init__(self, xy: tuple[int, int]):
super().__init__()
self.x, self.y = xy
self.width, self.height = 42, 40
Expand All @@ -61,22 +62,28 @@ def update(self, delta: int | float):
int(self.height),
)

def draw(self, graphics: vgame.graphics.Graphics):
def draw(self, graphics: Graphics):
graphics.draw_sprite(self)


class SettingsValue:
def __init__(self, name: str, display_name: str, possible_values, value) -> None:
"""An interactive value bar for settings"""

def __init__(
self, name: str, display_name: str, possible_values: tuple[Any], value: Any
) -> None:
self.codename = name
self.text = display_name
self.possible_values = possible_values
self.value = value
self.selection_index = self.possible_values.index(self.value)

def increase(self):
"""Select next value"""
self.selection_index = (self.selection_index + 1) % len(self.possible_values)
self.value = self.possible_values[self.selection_index]

def decrease(self):
"""Select previous value"""
self.selection_index = (self.selection_index - 1) % len(self.possible_values)
self.value = self.possible_values[self.selection_index]
5 changes: 3 additions & 2 deletions danmaku/ui/game_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ def load(self):
pygame.mixer.music.play()

def set(self, text: str, background: tuple[int, int, int], music: str):
"""Set end screen attributes"""
self.text = text
if "win" in text:
self.delta_color = 2
else:
self.delta_color = 0
self.background_color = background
self.text_color = list(background)
self.v = (255 - self.text_color[self.delta_color]) / 500
self.text_color: list[int] = list(background)
self.v = (255 - self.text_color[self.delta_color]) // 500
self.music = music

def update(self):
Expand Down
2 changes: 1 addition & 1 deletion danmaku/ui/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class History(vgame.Scene):
def load(self):
self.selection_index = 0

self.history = get_game_history()
self.history: list[dict[str, int]] = get_game_history()
self.record_count = len(self.history)

def update(self):
Expand Down
2 changes: 2 additions & 0 deletions danmaku/ui/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def update(self):
case "quit":
# Maybe rework to quit through exit status
pygame.event.post(pygame.event.Event(pygame.constants.QUIT))
case _:
pass
self.cursor.y = 100 + self.selection_index * 50
self.cursor.update(self.delta)

Expand Down

0 comments on commit b802a63

Please sign in to comment.