blob: 07a8bcd819b8fda4ad6da05c57e1cc8a8f70c74c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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)
__class__.surfaces[name] = scaled
return True
@staticmethod
def load_images(base_path):
if __class__.surfaces:
return False
return __class__.reload_images(base_path)
|