Merge pull request 'Réglage des problèmes de chargements' (#29) from fix-loading into main
Reviewed-on: #29
This commit is contained in:
commit
df33433569
|
@ -281,16 +281,8 @@ class Assets:
|
|||
pygame.draw.rect(error_texture, (255, 0, 255), (128, 128, 128, 128))
|
||||
self.__error_texture = error_texture.convert(surface)
|
||||
|
||||
# Chargement des textures
|
||||
# Cache des ressources
|
||||
self.__textures: dict[str, pygame.Surface] = {}
|
||||
for file in glob.iglob("assets/textures/**/*.png", recursive=True):
|
||||
if file.startswith("assets/textures/animations/"):
|
||||
continue
|
||||
self.__textures[file[16:].replace("\\", "/")] = pygame.image.load(
|
||||
file
|
||||
).convert_alpha(surface)
|
||||
|
||||
# Création du cache pour les polices
|
||||
self.__fonts: dict[int, pygame.font.Font] = {}
|
||||
|
||||
def get_texture(self, name: str) -> pygame.Surface:
|
||||
|
@ -303,9 +295,16 @@ class Assets:
|
|||
Retourne:
|
||||
La texture qui correspond au nom *name*.
|
||||
"""
|
||||
if name.startswith("animations/"):
|
||||
return pygame.image.load(f"assets/textures/{name}")
|
||||
return self.__textures.get(name, self.__error_texture)
|
||||
texture = self.__textures.get(name)
|
||||
if texture is None:
|
||||
if os.path.exists(f"assets/textures/{name}"):
|
||||
texture = pygame.image.load(f"assets/textures/{name}")
|
||||
if not name.startswith("animations/"):
|
||||
texture = texture.convert_alpha()
|
||||
self.__textures[name] = texture
|
||||
return texture
|
||||
return self.__error_texture
|
||||
return texture
|
||||
|
||||
def get_texture_size(self, name: str) -> Vec2:
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue