ecs #58

Merged
raphael merged 70 commits from ecs into main 2023-11-03 15:29:36 +00:00
Showing only changes of commit 9dd925dd9f - Show all commits

View file

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