From 27c7e16e4bd808ce1176f18b7a78c02ff4fa88ee Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Thu, 28 Mar 2024 23:34:19 +0200 Subject: fonts under text, more sprite.Groups --- src/sliceitoff/images/__init__.py | 2 -- src/sliceitoff/images/fonts.py | 39 --------------------------------------- src/sliceitoff/images/images.py | 32 -------------------------------- 3 files changed, 73 deletions(-) delete mode 100644 src/sliceitoff/images/__init__.py delete mode 100644 src/sliceitoff/images/fonts.py delete mode 100644 src/sliceitoff/images/images.py (limited to 'src/sliceitoff/images') diff --git a/src/sliceitoff/images/__init__.py b/src/sliceitoff/images/__init__.py deleted file mode 100644 index c11d718..0000000 --- a/src/sliceitoff/images/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .images import Images -from .fonts import Fonts, Font diff --git a/src/sliceitoff/images/fonts.py b/src/sliceitoff/images/fonts.py deleted file mode 100644 index a1687b6..0000000 --- a/src/sliceitoff/images/fonts.py +++ /dev/null @@ -1,39 +0,0 @@ -import os -import pygame - -DEBUG = os.getenv("DEBUG") - -class Fonts: - fonts = {} - - @staticmethod - def load_fonts(base_path): - filename_fontlist = os.path.join(base_path, "assets", "fonts.lst") - with open( filename_fontlist ) as fontlist_file: - for line in fontlist_file: - name, *path = line.strip().split() - filename = os.path.join(base_path, *path) - __class__.fonts[name] = Font(filename) - return True - - -class Font: - def __init__(self, filename, height = 16): - if DEBUG: - print(f"Loading font {filename = }") - self.surfaces = [] - with open(filename, mode="rb") as fnt_file: - for _ in range(256): - surface = pygame.Surface((8,height), pygame.SRCALPHA) - for line in range(16): - byte = fnt_file.read(1)[0] - if line >= height: - continue - for bit in range(8): - if byte & 0x80: - surface.set_at((bit,line),"white") - byte <<= 1 - self.surfaces.append(surface) - - def get(self, ch): - return self.surfaces[ch%256] diff --git a/src/sliceitoff/images/images.py b/src/sliceitoff/images/images.py deleted file mode 100644 index 7ae1f6d..0000000 --- a/src/sliceitoff/images/images.py +++ /dev/null @@ -1,32 +0,0 @@ -import os -import pygame - -from display import Scaling - -DEBUG = os.getenv("DEBUG") - -class Images: - surfaces = {} - - @staticmethod - def reload_images(base_path): - __class__.surfaces = {} - filename_imagelist = os.path.join(base_path, "assets", "images.lst") - with open( filename_imagelist ) as imagelist_file: - for line in imagelist_file: - name, *path = line.strip().split() - filename = os.path.join(base_path, *path) - if DEBUG: - print(f"Loading images {name = }, {filename = }") - image = pygame.image.load(filename) - rgba = pygame.Surface.convert_alpha(image) - scaled = pygame.transform.smoothscale_by(rgba, Scaling.factor*10) - __class__.surfaces[name] = scaled - return True - - @staticmethod - def load_images(base_path): - if __class__.surfaces: - return False - return __class__.reload_images(base_path) - \ No newline at end of file -- cgit v1.2.3