dialog

package
v0.22.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dialog is conversations written as data: nodes of lines and answers a Stage loads from YAML files, held by its entities and answered by a player through a window pinned to the speaker. What a conversation changes in the game is the game's own components, changed and asked by name.

Nodes

A Node is who speaks, what is said and the answers offered, each a Choice: its words, when it is offered (If), what it changes (Then), where it leads (Next, or End) and the commands it gives (Do). Plugin.Load reads a file of them by name, Plugin.Define says one in code, both in the plugin's own section of a Stage, Conversations:

greet:
  speaker: Miller
  say: ["Hello, traveller!"]
  choices:
    - text: "Good to see you again!"
      if: friend
      next: glad
    - text: "Out of my way."
      then: [offend]
      next: end

Changes and conditions

Plugin.Changes are what answers change, by name: Alter a function of the speaker's component and the listener, AlterListener of the listener's and the speaker. Plugin.Conditions are when answers are offered, by name: When a function of the speaker's component and the listener. An answer's if may name an effect the speaker is under instead, "!" denying it. A rule changes the game the same way with Feel.

Conversations

An entity's conversations begin where its Script says, or at the node a Begin names; a Begin is the entity's own, about whom it talks with. The conversation is the speaker's Talk; TalkingEf is on the speaker while it talks and TalkedEf for a while after one talked to the end (Plugin.DefineEffects). A Choose answers, given by a button of Plugin.Window, by a player the listener obeys.

Window

Plugin.Window is one ui element for every speaker, pinned Under TalkingEf: its title the speaker, what is said, a button for each answer offered. Plugin.SpeakerText, Plugin.LineText and Plugin.ChoiceText lay out a window of a game's own.

Vocabulary

Commands: Begin, Feel (an entity's own, aimed at the moment's subject, host.Aimed); Choose (a player's, from the window's button, ui.About). Effects: TalkingEf, TalkedEf.

Index

Constants

View Source
const (
	TalkingEf = "dialog.talking"
	TalkedEf  = "dialog.talked"
)

The names of the plugin's effects: TalkingEf is on the speaker while it talks, and taken off the conversation is over; TalkedEf is on it for Config.Rest after one talked to the end.

View Source
const End = "end"

End is the Next of an answer that ends the conversation.

View Source
const MaxChoices = 6

MaxChoices is how many answers a node offers at most.

Variables

View Source
var ConversationsPart = section.Define("Conversations", section.Commands, section.Kinds)

ConversationsPart is the dialog plugin's part of a Stage's definition, after its commands and before its kinds.

Functions

func Conversations

func Conversations(
	f func(d *Plugin) error,
) section.Section

Conversations is the dialog plugin's section of a Stage, for stage.With: f defines the changes and conditions and loads the conversations.

Types

type Begin

type Begin struct {
	At string
	// contains filtered or unexported fields
}

Begin is the command by which an entity begins to talk with whom it is aimed at, at the node At or where its Script says. It is refused while either of them talks already.

func (*Begin) Aim

func (b *Begin) Aim(who uid.UID64)

Aim tells the command whom to talk with.

func (Begin) Command

func (Begin) Command()

type Change

type Change struct {
	// contains filtered or unexported fields
}

Change is what an answer changes in the game, made by Alter or AlterListener.

func Alter

func Alter[T any](fn func(v *T, listener uid.UID64)) Change

Alter is the change fn makes to the speaker's component T, told whom it talks with; a speaker without T is left as it is.

func AlterListener

func AlterListener[T any](fn func(v *T, speaker uid.UID64)) Change

AlterListener is the change fn makes to the listener's component T, told who speaks.

type Changes

type Changes struct {
	// contains filtered or unexported fields
}

Changes is the register of what answers change in the game, by name.

func (*Changes) Define

func (c *Changes) Define(name string, ch Change)

Define registers ch as name. A name defined twice, or a Change not made by Alter or AlterListener, panics.

type Choice

type Choice struct {
	Text string `yaml:"text"`
	// If is a condition the game defined or the name of an effect the speaker is under, "!"
	// before it denying; empty, the answer is always offered.
	If   string   `yaml:"if"`
	Then []string `yaml:"then"`
	Next string   `yaml:"next"`
	Do   []string `yaml:"do"`
}

Choice is one answer: its words, when it is offered, what it changes, where it leads and the commands it gives.

type Choose

type Choose struct {
	Index   int
	Speaker uid.UID64
}

Choose is the answer Index of those offered now in Speaker's conversation. Only a player the listener obeys may choose.

func (Choose) About

func (c Choose) About(of uid.UID64) command.Command

About is the answer for the conversation of the entity of.

func (Choose) Command

func (Choose) Command()

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

Condition is when an answer is offered, made by When.

func When

func When[T any](fn func(v *T, listener uid.UID64) bool) Condition

When holds while fn says so of the speaker's component T and whom it talks with; for a speaker without T it does not.

type Conditions

type Conditions struct {
	// contains filtered or unexported fields
}

Conditions is the register of when answers are offered, by name.

func (*Conditions) Define

func (c *Conditions) Define(name string, cond Condition)

Define registers cond as name. A name defined twice, one an effect bears, or a Condition not made by When panics.

type Config

type Config struct {
	Rest time.Duration // ten seconds when zero
}

Config is how long a speaker rests after a conversation.

type Feel

type Feel struct {
	Change string
	// contains filtered or unexported fields
}

Feel is the command by which an entity undergoes the game's change called Change towards whom it is aimed at, as if it spoke and that one answered.

func (*Feel) Aim

func (f *Feel) Aim(who uid.UID64)

Aim tells the command whom the change is towards.

func (Feel) Command

func (Feel) Command()

type Node

type Node struct {
	Speaker string   `yaml:"speaker"`
	Say     []string `yaml:"say"`
	Choices []Choice `yaml:"choices"`
}

Node is one place of a conversation: who speaks, what is said, and the answers offered, at most MaxChoices.

type Plugin

type Plugin struct {
	*world.Self
	// contains filtered or unexported fields
}

Plugin carries conversations: the nodes a Stage defines and the Talks its entities hold.

func NewPlugin

func NewPlugin(w *world.Plugin, cfg Config) *Plugin

NewPlugin builds the dialog plugin over w.

func (*Plugin) Changes

func (p *Plugin) Changes() *Changes

Changes are what answers change in the game, by name.

func (*Plugin) ChoiceText

func (p *Plugin) ChoiceText(index int) ui.Text

ChoiceText is the words of the answer offered at index in the conversation of the entity an element is pinned to; nothing past the last offered.

func (*Plugin) Conditions

func (p *Plugin) Conditions() *Conditions

Conditions are when answers are offered, by name.

func (*Plugin) DefaultBindings

func (p *Plugin) DefaultBindings() []control.Binding

DefaultBindings is none: a conversation is begun by rules and answered by the window's buttons.

func (*Plugin) Define

func (p *Plugin) Define(name string, n Node)

Define says the node called name in code. A name defined twice, an unknown change or condition, or too many answers panics.

func (*Plugin) DefineEffects

func (p *Plugin) DefineEffects()

DefineEffects defines TalkingEf and TalkedEf in the Stage's world. Call it where the Stage defines its effects.

func (*Plugin) EventHandler

func (p *Plugin) EventHandler() control.EventHandler

EventHandler is nil: the window's buttons give Choose.

func (*Plugin) Install

func (p *Plugin) Install(ctx plugin.Installer) error

func (*Plugin) LineText

func (p *Plugin) LineText() ui.Text

LineText is what is said in the conversation of the entity an element is pinned to.

func (*Plugin) Load

func (p *Plugin) Load(fsys fs.FS, path string) error

Load reads the nodes of the YAML file at path in fsys, a map of Nodes by name, and defines them.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Queues

func (p *Plugin) Queues() []command.CommandQueue

Queues are the plugin's command queues: Begin, Choose and Feel.

func (*Plugin) RunPlan

func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)

RunPlan carries the conversations on in the simulation. Call it after the plugins whose rules begin them.

func (*Plugin) Script

func (p *Plugin) Script(node string) Script

Script is the component of a kind whose conversations begin at the node called node. An unknown node panics.

func (*Plugin) Serializable

func (p *Plugin) Serializable() plugin.Serializable

Serializable is nil: the conversations are components, saved with their entities.

func (*Plugin) SpeakerText

func (p *Plugin) SpeakerText() ui.Text

SpeakerText is who speaks in the conversation of the entity an element is pinned to.

func (*Plugin) Window

func (p *Plugin) Window() *ui.Element

Window is the conversation of every entity that talks, pinned to it: the speaker as its title, what it says, and a button for each answer offered, giving Choose.

type Script

type Script struct{ Start uint64 }

Script is the component saying where an entity's conversations begin.

type Talk

type Talk struct {
	Node uint64
	With uid.UID64
}

Talk is the conversation an entity holds now as its speaker: the node it stands at and the listener; Node 0 for none.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL