ecs #58

Merged
raphael merged 70 commits from ecs into main 2023-11-03 15:29:36 +00:00
2 changed files with 51 additions and 1 deletions
Showing only changes of commit 763430a632 - Show all commits

View file

@ -2,7 +2,7 @@
Plugin qui rassemple tous les plugins globaux. Plugin qui rassemple tous les plugins globaux.
""" """
from plugins import animation, assets, display, inputs, render, timing from plugins import animation, assets, display, inputs, render, text, timing
PLUGIN = ( PLUGIN = (
@ -11,5 +11,6 @@ PLUGIN = (
+ assets.PLUGIN + assets.PLUGIN
+ inputs.PLUGIN + inputs.PLUGIN
+ animation.PLUGIN + animation.PLUGIN
+ text.PLUGIN
+ render.PLUGIN + render.PLUGIN
) )

49
src/plugins/text.py Normal file
View file

@ -0,0 +1,49 @@
"""
Un plugin permettant d'afficher du texte à l'écran.
"""
import pygame
from engine import GlobalPlugin
from engine.ecs import World
from plugins.assets import Assets
from plugins.render import Sprite
class Text:
"""
Composant donnant le texte d'une entité, sa taille et sa couleur.
"""
def __init__(
self,
text: str,
size: int = 50,
color: pygame.Color = pygame.Color(255, 255, 255),
):
self.text = text
self.size = size
self.color = color
def __render_texts(world: World):
"""
Rend les textes à l'écran.
"""
assets = world[Assets]
for entity in world.query(Text):
text = entity[Text]
texture = assets.get_text(text.size, text.text, text.color)
if Sprite in entity:
entity[Sprite].texture = texture
else:
entity[Sprite] = Sprite(texture)
PLUGIN = GlobalPlugin(
[],
[],
[__render_texts],
[],
)