Rudimentary user input for dialogs has been added. * Displays must add support for showing dialog options, and receiving user input for dialog selections. * A selected dialog can optionally perform actions, and then directs the game into the next dialog state. * Dialog options may be conditionally shown with variables. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
41 lines
969 B
Python
41 lines
969 B
Python
import dataclasses
|
|
from typing import Mapping, Optional, Sequence, TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from agame.action import Action
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class DialogOption:
|
|
# The text for this dialog option.
|
|
text: str
|
|
# The actions that get executed upon choosing this dialog option.
|
|
actions: Sequence["Action"] = dataclasses.field(default_factory=list)
|
|
# The variable required for being able to display this dialog option.
|
|
#
|
|
# This variable must not be equal to `False`.
|
|
required_var: Optional[str] = None
|
|
# The next dialog that is chosen.
|
|
next: Optional[str] = None
|
|
|
|
|
|
{
|
|
"main": {
|
|
"type": "reply",
|
|
"options": [
|
|
{
|
|
"text": "What happened here?",
|
|
"next": "main",
|
|
"actions": [],
|
|
},
|
|
{
|
|
"text": "Bye.",
|
|
},
|
|
],
|
|
},
|
|
"bye": {
|
|
"type": "print",
|
|
"text": "Mhm.",
|
|
},
|
|
}
|