diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sliceitoff/text/fonts.py | 8 | ||||
-rw-r--r-- | src/sliceitoff/text/text.py | 15 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/sliceitoff/text/fonts.py b/src/sliceitoff/text/fonts.py index a1687b6..af9aefb 100644 --- a/src/sliceitoff/text/fonts.py +++ b/src/sliceitoff/text/fonts.py @@ -1,15 +1,17 @@ +""" text.fonts - .FNT file loading and storing """ import os import pygame DEBUG = os.getenv("DEBUG") class Fonts: + """ Fonts - static class to store loaded 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: + with open(filename_fontlist, "r", encoding="utf-8") as fontlist_file: for line in fontlist_file: name, *path = line.strip().split() filename = os.path.join(base_path, *path) @@ -18,6 +20,7 @@ class Fonts: class Font: + """ Font - font surfaces to be loaded from file """ def __init__(self, filename, height = 16): if DEBUG: print(f"Loading font {filename = }") @@ -34,6 +37,7 @@ class Font: surface.set_at((bit,line),"white") byte <<= 1 self.surfaces.append(surface) - + def get(self, ch): + """ Just get surface of the font size 8x16 max """ return self.surfaces[ch%256] diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py index 85958e0..83367e0 100644 --- a/src/sliceitoff/text/text.py +++ b/src/sliceitoff/text/text.py @@ -1,9 +1,10 @@ """ text.text - letters, texts and scaling and coloring of fonts """ -import pygame from random import randrange -from .fonts import Fonts +import pygame + from display import Scaling, CGA_COLORS +from .fonts import Fonts scaled_fonts = {} @@ -20,7 +21,7 @@ class LetterSprite(pygame.sprite.Sprite): self.dead = True if font_key not in scaled_fonts: scaled_fonts[font_key]=[None for _ in range(256)] - if scaled_fonts[font_key][ch] == None: + if scaled_fonts[font_key][ch] is None: font, w, color = font_key scaled_fonts[font_key][ch] = pygame.transform.scale_by( Fonts.fonts[font].get(ch), @@ -35,6 +36,7 @@ class LetterSprite(pygame.sprite.Sprite): Scaling.factor * (1_000 - randrange(2_000))) def update(self, dt = 0, explode = 0, **kwargs): + """ All the movements for letters """ if explode and dt: self.rect = pygame.Rect( self.rect.x + self.direction[0] * dt, @@ -64,12 +66,10 @@ class TextPage(pygame.sprite.Group): grid = None, font = 'lcd'): super().__init__() - if grid == None: + if grid is None: grid = size color = 0xf col, row = 0, 0 - x, y = pos - w, h = grid for ch_txt in text: if ch_txt == '\n': row += 1 @@ -83,7 +83,8 @@ class TextPage(pygame.sprite.Group): color = ch - 0xe0 continue font_key = (font, size[0], color) - sprite_pos = Scaling.scale_to_display( (x+col*w, y+row*h) ) + sprite_pos = Scaling.scale_to_display( + (pos[0]+col*grid[0], pos[1]+row*grid[1]) ) self.add(LetterSprite(font_key, ch, sprite_pos)) col += 1
\ No newline at end of file |