diff --git a/src/plugins/assets.py b/src/plugins/assets.py index ed17c92..835fd9e 100644 --- a/src/plugins/assets.py +++ b/src/plugins/assets.py @@ -3,6 +3,7 @@ Un plugin qui gère les assets du jeu. """ import glob +import random import pygame from engine import CurrentScene, GlobalPlugin, KeepAlive, Scene from engine.ecs import World @@ -177,6 +178,7 @@ def loading_scene(target: Scene, name: str, clear_cache: bool = True): def __init__(self): self.files = glob.glob(f"assets/{name}/**/*", recursive=True) + random.shuffle(self.files) self.total = len(self.files) @staticmethod @@ -188,18 +190,23 @@ def loading_scene(target: Scene, name: str, clear_cache: bool = True): assets = world[Assets] if clear_cache: assets.clear_cache() + asset_iterator = AssetIterator() world.set(AssetIterator()) - world.new_entity().set( - render.Sprite(assets.unloaded_texture, order=1000000000) - ) - world.new_entity().set( - ProgessBar(), - render.Sprite( - assets.loaded_texture, - order=1000000001, - area=(0, 0, 0, render.HEIGHT), - ), - ) + if asset_iterator.total <= 30: + for _ in range(asset_iterator.total): + asset_iterator.load_next(world) + else: + world.new_entity().set( + render.Sprite(assets.unloaded_texture, order=1000000000) + ) + world.new_entity().set( + ProgessBar(), + render.Sprite( + assets.loaded_texture, + order=1000000001, + area=(0, 0, 0, render.HEIGHT), + ), + ) @staticmethod def load_next(world: World): @@ -240,8 +247,8 @@ def loading_scene(target: Scene, name: str, clear_cache: bool = True): progress = file_loaded / asset_iterator.total # Affichage de la barre de progression - progress_bar = world.query(ProgessBar).pop() - progress_bar[render.Sprite].area = (0, 0, progress, 1.0) + for progress_bar in world.query(ProgessBar): + progress_bar[render.Sprite].area = (0, 0, progress, 1.0) return Scene( [AssetIterator.prepare_world],