ecs #58

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

43
src/plugins/typing.py Normal file
View file

@ -0,0 +1,43 @@
"""
Definit un plugin qui crée un texte avec les touches frappées
"""
from engine import Scene, World
from plugins.inputs import Pressed
from plugins.text import Text
class Typing:
"""
Marque une entité comme un texte qui s'ecrit en fonction du clavier
"""
def __init__(self, accepted_chars: str, max_chars: int = 10) -> None:
self.accepted_chars = accepted_chars
self.max_chars = max_chars
def __update(world: World):
"""
Met a jour les entitées contenant le composant Typing
"""
pressed = world[Pressed]
for entity in world.query(Typing, Text):
text = entity[Text]
for key in pressed:
if key == "backspace":
text.text = text.text[:-1]
if key.startswith("["): # pavé numerique
key = key[1]
if (
key in entity[Typing].accepted_chars
and len(text.text) < entity[Typing].max_chars
):
text.text += key
PLUGIN = Scene(
[],
[__update],
[],
)