ecs #58
|
@ -12,9 +12,12 @@ class Writing:
|
|||
Marque une entité comme un texte qui s'ecrit en fonction du clavier
|
||||
"""
|
||||
|
||||
def __init__(self, accepted_chars: str, max_chars: int = 10) -> None:
|
||||
def __init__(
|
||||
self, accepted_chars: str, max_chars: int = 10, base_text: str = ""
|
||||
) -> None:
|
||||
self.accepted_chars = accepted_chars
|
||||
self.max_chars = max_chars
|
||||
self.base_text = base_text
|
||||
|
||||
|
||||
def __update(world: World):
|
||||
|
@ -23,21 +26,22 @@ def __update(world: World):
|
|||
"""
|
||||
pressed = world[Pressed]
|
||||
for entity in world.query(Writing, Text):
|
||||
writing = entity[Writing]
|
||||
text = entity[Text]
|
||||
for key in pressed:
|
||||
if key == "backspace":
|
||||
text.text = text.text[:-1]
|
||||
if text.text == "":
|
||||
text.text = "..."
|
||||
if key.startswith("["): # pavé numerique
|
||||
key = key[1]
|
||||
if key in entity[Writing].accepted_chars and (
|
||||
text.text == "..." or len(text.text) < entity[Writing].max_chars
|
||||
if key in writing.accepted_chars and (
|
||||
text.text == writing.base_text or len(text.text) < writing.max_chars
|
||||
):
|
||||
if text.text == "...":
|
||||
if text.text == writing.base_text:
|
||||
text.text = key
|
||||
else:
|
||||
text.text += key
|
||||
if text.text == "":
|
||||
text.text = writing.base_text
|
||||
|
||||
|
||||
PLUGIN = Scene(
|
||||
|
|
|
@ -137,7 +137,7 @@ def __initialize_world(world: World):
|
|||
1.0,
|
||||
Vec2(0.5),
|
||||
),
|
||||
Writing("0123456789", 2),
|
||||
Writing("0123456789", 2, "..."),
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue