summaryrefslogtreecommitdiff
path: root/src/sliceitoff/images/images.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-16 12:53:03 +0200
committerViljami Ilola <+@hix.fi>2024-03-16 12:53:03 +0200
commit77d104cced553b8dfc9896cb456bd039807ed6c6 (patch)
tree834731b22475fe09ec61168ec220ff6ae98259bc /src/sliceitoff/images/images.py
parenta23b6647b0ca2cd9f2ccbbe12360c3fa0f96a554 (diff)
Images class
Diffstat (limited to 'src/sliceitoff/images/images.py')
-rw-r--r--src/sliceitoff/images/images.py22
1 files changed, 16 insertions, 6 deletions
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