48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import yaml
|
|
import pygame
|
|
from typing import Tuple
|
|
|
|
"""
|
|
TODO description
|
|
"""
|
|
class ConfigurationManager:
|
|
|
|
CONFIG_FILE_LOCATION = "config.yaml"
|
|
configuration = []
|
|
|
|
@classmethod
|
|
def load(cls) -> None:
|
|
with open(cls.CONFIG_FILE_LOCATION, "r") as yaml_file:
|
|
cls.configuration = yaml.safe_load(yaml_file)
|
|
|
|
@classmethod
|
|
def get(cls, key: str, sub_key: str = None):
|
|
if sub_key:
|
|
return cls.configuration[key][sub_key]
|
|
else:
|
|
return cls.configuration[key]
|
|
|
|
class TextGenerator:
|
|
|
|
sheet = None
|
|
glyph_size = -1
|
|
letters = { }
|
|
numbers = { }
|
|
|
|
@classmethod
|
|
def load(cls, file: str, glyph_size: Tuple) -> None:
|
|
cls.sheet = pygame.image.load(file)
|
|
cls.glyph_size = glyph_size
|
|
|
|
cls.letters["S"] = (3 * glyph_size[0], 6 * glyph_size[1])
|
|
cls.letters["C"] = (3 * glyph_size[0], 4 * glyph_size[1])
|
|
cls.letters["O"] = (7 * glyph_size[0], 5 * glyph_size[1])
|
|
cls.letters["R"] = (2 * glyph_size[0], 6 * glyph_size[1])
|
|
cls.letters["E"] = (5 * glyph_size[0], 4 * glyph_size[1])
|
|
|
|
@classmethod
|
|
def draw(cls, text: str, position: Tuple, surface: pygame.Surface) -> None:
|
|
x_position = 0
|
|
for char_ in text:
|
|
surface.blit(cls.sheet, (position[0] + x_position, position[1]), pygame.Rect(cls.letters[char_.upper()], (cls.glyph_size[0], cls.glyph_size[1])))
|
|
x_position += cls.glyph_size[0] |