diff --git a/src/plugins/typing.py b/src/plugins/typing.py index 6379dd3..2f5edb9 100644 --- a/src/plugins/typing.py +++ b/src/plugins/typing.py @@ -5,11 +5,15 @@ Definit un plugin qui crée un texte avec les touches frappées from engine import Keyboard, Scene, Sound, Text, World -class Typing(str): +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): """ @@ -24,7 +28,10 @@ def __update(world: World): text = text[:-1] if key.startswith("["): # pavé numerique key = key[1] - if key in entity[Typing]: + if ( + key in entity[Typing].accepted_chars + and len(text) < entity[Typing].max_chars + ): world.create_entity(Sound("click")) text += key entity[Text] = Text(text) diff --git a/src/scenes/classique.py b/src/scenes/classique.py index de6d51d..8a4bd8c 100644 --- a/src/scenes/classique.py +++ b/src/scenes/classique.py @@ -83,7 +83,7 @@ def __initialize_world(world: World): Position(Display.WIDTH / 2, 750), Order(2), Centered(), - typing.Typing("1234567890"), + typing.Typing("1234567890", 2), Text(""), COLOR_TEXT, TextSize(150), diff --git a/src/scenes/menteur.py b/src/scenes/menteur.py index 682b4cf..222e41d 100644 --- a/src/scenes/menteur.py +++ b/src/scenes/menteur.py @@ -84,7 +84,7 @@ def __initialize_world(world: World): Position(Display.WIDTH / 2, 750), Order(2), Centered(), - typing.Typing("1234567890"), + typing.Typing("1234567890", 2), Text(""), COLOR_TEXT, TextSize(150),