From 77d104cced553b8dfc9896cb456bd039807ed6c6 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 16 Mar 2024 12:53:03 +0200 Subject: Images class --- src/sliceitoff/images/images.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/sliceitoff/images/images.py') diff --git a/src/sliceitoff/images/images.py b/src/sliceitoff/images/images.py index b2d93a2..999d92b 100644 --- a/src/sliceitoff/images/images.py +++ b/src/sliceitoff/images/images.py @@ -5,10 +5,12 @@ from display import Scaling DEBUG = os.getenv("DEBUG") -images = {} +class Images: + surfaces = {} -def load_images(): - if not images: + @staticmethod + def reload_images(): + __class__.surfaces = {} with open("assets/images.lst") as image_list_file: for line in image_list_file: name, *path = line.strip().split() @@ -16,6 +18,14 @@ def load_images(): if DEBUG: print(f"Loading images {name = }, {filename = }") image = pygame.image.load(filename) - images[name] = pygame.transform.smoothscale_by( - pygame.Surface.convert_alpha(image), - Scaling.factor) + rgba = pygame.Surface.convert_alpha(image) + scaled = pygame.transform.smoothscale_by(rgba, Scaling.factor) + __class__.surfaces[name] = scaled + return True + + @staticmethod + def load_images(): + if __class__.surfaces: + return False + return __class__.reload_images() + \ No newline at end of file -- cgit v1.2.3