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