package dialog
import "git.teletypegames.org/engines/inkwell/dialog"
Package dialog holds dialog trees: the conversations a game opens with RunDialog and the DialogBox widget shows.
A Dialog is a set of named DialogNode values. Each node is a few DialogLine values, spoken one at a time, followed by the DialogChoice values the player picks from. A line's Speaker is any inkbase.Talker — a character or a bodiless speaker — and its Text is an inkbase.Text, so a dialog is written in every language it is played in. The Manager holds the registered dialogs.
var Dex = DialogManager.Register(&inkwell.Dialog{
Name: "dex",
Nodes: []inkwell.DialogNode{{
Name: "hello",
Lines: []inkwell.DialogLine{{Speaker: dex, Text: hello}},
Choices: []inkwell.DialogChoice{
{Text: askTape, Show: inkwell.Given{Item: tape}, Once: true,
Actions: []inkwell.Action{inkwell.GotoNode("tape")}},
{Text: bye, Actions: []inkwell.Action{inkwell.EndDialog()}},
},
}, …},
})
The flow
- RunDialog starts the dialog at its Start node (the first node when Start is empty); the runner keeps the script running until the dialog closes.
- The DialogBox renders the node's lines one at a time; a click advances.
- After the last line, the choices whose Show holds are offered.
- Picking a choice runs its Actions in sequence. A Once choice is then hidden for good; it is remembered by its node and its position in Choices rather than its wording, so it stays used up across a save and a change of language.
- EndDialog closes the conversation; GotoNode moves it to another node of the same dialog.
Index
Types
type Dialog
type Dialog struct { // Name is the key the dialog is registered and started by. Name string // Start is the node the dialog opens on. Empty opens on the first of // Nodes. Start string // Nodes are the dialog's nodes, looked up by their Name. Nodes []DialogNode }
Dialog is a conversation: a set of named nodes, each a few lines spoken in turn followed by the choices the player picks from. A choice's Actions move it on — to another node, out of the dialog, or anywhere else an inkbase.Action can go.
func (Dialog) GetName
func (d Dialog) GetName() string
GetName returns the dialog's Name, the key it is registered under.
func (Dialog) Node
func (d Dialog) Node(name string) (DialogNode, bool)
Node returns the node called name and true, or the zero DialogNode and false when the dialog has none by that name. When two nodes share a name the first wins.
func (Dialog) TypeLabel
func (d Dialog) TypeLabel() string
TypeLabel returns "dialog", the kind that tells a dialog apart from other entities of the same Name in saved state and in panic messages.
type DialogChoice
type DialogChoice struct { // Text is what the choice reads. Text inkbase.Text // Show, when set, hides the choice while it evaluates false. Nil shows // it always. Show inkbase.Condition // Once hides the choice for good after the player has picked it. It is // remembered by node name and position in Choices, so it survives a // save and a change of language. Once bool // Actions run, one after the other, when the choice is picked. Actions []inkbase.Action }
DialogChoice is an answer the player can pick at the end of a DialogNode. Picking it runs its Actions in sequence.
type DialogLine
type DialogLine struct { Speaker inkbase.Talker Text inkbase.Text }
DialogLine is one line of a DialogNode: who says it and what, in every language the game speaks.
type DialogNode
type DialogNode struct { // Name is the node's key within its dialog, used by Start and by a // choice that goes to it. Name string Lines []DialogLine Choices []DialogChoice }
DialogNode is one step of a Dialog: Lines are shown one per click, and once they run out the Choices the player may currently see are offered.
type Manager
type Manager = inkbase.Manager[*Dialog]
Manager is the registry of dialogs, keyed by Dialog.Name and kept in registration order; see inkbase.Manager.
func NewManager
func NewManager() *Manager
NewManager returns an empty Manager of dialogs.