ecs #58
|
@ -2,7 +2,7 @@
|
|||
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 = (
|
||||
|
@ -11,5 +11,6 @@ PLUGIN = (
|
|||
+ assets.PLUGIN
|
||||
+ inputs.PLUGIN
|
||||
+ animation.PLUGIN
|
||||
+ text.PLUGIN
|
||||
+ render.PLUGIN
|
||||
)
|
||||
|
|
49
src/plugins/text.py
Normal file
49
src/plugins/text.py
Normal 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],
|
||||
[],
|
||||
)
|
Loading…
Reference in a new issue