Chargement des texture dans les sous dossiers #15

Merged
tipragot merged 2 commits from texture-manager into main 2023-10-27 08:37:10 +00:00
Showing only changes of commit 77c7b90806 - Show all commits

View file

@ -4,7 +4,7 @@ Définis un plugin permettant d'afficher des choses a l'écran.
from engine import * from engine import *
from engine.math import Vec2 from engine.math import Vec2
import pygame, os import pygame, glob
from engine.plugins.pygame import Display from engine.plugins.pygame import Display
@ -84,10 +84,12 @@ class TextureManager:
def __init__(self, display: Display) -> None: def __init__(self, display: Display) -> None:
self._textures: dict[str, pygame.Surface] = {} self._textures: dict[str, pygame.Surface] = {}
for file in os.listdir("textures"): for file in glob.iglob("textures/**/*.png", recursive=True):
self._textures[file] = pygame.image.load(f"textures/{file}").convert( self._textures[file] = pygame.image.load(file).convert_alpha(
display._surface display._surface
) )
for file in glob.iglob("textures/**/*.jpg", recursive=True):
self._textures[file] = pygame.image.load(file).convert(display._surface)
error_texture = pygame.Surface((256, 256)) error_texture = pygame.Surface((256, 256))
error_texture.fill((0, 0, 0)) error_texture.fill((0, 0, 0))
pygame.draw.rect(error_texture, (255, 0, 255), (0, 0, 128, 128)) pygame.draw.rect(error_texture, (255, 0, 255), (0, 0, 128, 128))