Add dialog actions

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>
This commit is contained in:
2021-11-28 17:27:05 -08:00
parent def9b584a8
commit 2357757b23
5 changed files with 173 additions and 13 deletions

40
agame/dialog.py Normal file
View File

@@ -0,0 +1,40 @@
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.",
},
}