Documentation ¶
Overview ¶
Package ysgo defines a DialogueRunner type able to execute dialogues.
Index ¶
- Constants
- type DialogueElement
- type DialogueOption
- type DialogueRunner
- func (dr *DialogueRunner) AddCommand(commandID string, command YarnSpinnerCommand)
- func (dr *DialogueRunner) AddFunction(functionID string, function YarnSpinnerFunction)
- func (dr *DialogueRunner) ConvertAndAddCommand(commandID string, command any) error
- func (dr *DialogueRunner) ConvertAndAddFunction(functionID string, function any) error
- func (dr *DialogueRunner) JumpTo(nodeTitle string) error
- func (dr *DialogueRunner) Next(choice int) (*DialogueElement, error)
- type YarnSpinnerCommand
- type YarnSpinnerFunction
Constants ¶
const ErrWaitingForCommandCompletion errWaitingForCommandCompletion = "waiting for command completion"
ErrWaitingForCommandCompletion is returned when DialogueRunner#Next(...) is called when an ongoing command hasn't ended yet.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialogueElement ¶
type DialogueElement struct { Line *markup.ParseResult Options []DialogueOption }
DialogueElement represents a step of a dialogue as it is presented in a game. Either Line or Options holds a value.
type DialogueOption ¶
type DialogueOption struct { Line *markup.ParseResult Disabled bool }
DialogueOption holds the data about one possible choice the player is presented with.
type DialogueRunner ¶
type DialogueRunner struct {
// contains filtered or unexported fields
}
DialogueRunner is able to execute a YarnSpinner dialogue. It keeps track of the current state of the dialogue (variables, current and visited steps). It orchestrates the call of Commands and Functions.
func NewDialogueRunner ¶
func NewDialogueRunner(storer variable.Storer, rngSeed string, readers ...io.Reader) (*DialogueRunner, error)
NewDialogueRunner creates a new runner working on the dialogue that can be parsed from the given readers. The storer argument is optional and if provided, allows to store variables elsewhere than in the default in-memory store. The given rngSeed serves to create deterministic random values. It will be used when eg. the dice(6) function is called in a dialogue.
func (*DialogueRunner) AddCommand ¶
func (dr *DialogueRunner) AddCommand(commandID string, command YarnSpinnerCommand)
AddCommand adds a custom command to the library of commands that can be called from a dialogue.
func (*DialogueRunner) AddFunction ¶
func (dr *DialogueRunner) AddFunction(functionID string, function YarnSpinnerFunction)
AddFunction adds a custom function to the library of functions that can be called from a dialogue.
func (*DialogueRunner) ConvertAndAddCommand ¶
func (dr *DialogueRunner) ConvertAndAddCommand(commandID string, command any) error
ConvertAndAddCommand is a convenience wrapper around AddCommand so that manual conversion to YarnSpinnerCommand isn't needed. Refer to the unit tests of commandStorer to learn more about the limitations on the accepted functions.
func (*DialogueRunner) ConvertAndAddFunction ¶
func (dr *DialogueRunner) ConvertAndAddFunction(functionID string, function any) error
ConvertAndAddFunction is a convenience wrapper around AddFunction so that manual conversion to YarnSpinnerFunction isn't needed. Refer to the unit tests of functionStorer to learn more about the limitations on the accepted functions.
func (*DialogueRunner) JumpTo ¶
func (dr *DialogueRunner) JumpTo(nodeTitle string) error
JumpTo moves the dialogue to the beginning of the given node.
func (*DialogueRunner) Next ¶
func (dr *DialogueRunner) Next(choice int) (*DialogueElement, error)
Next advances the dialogue to the next step. If the previous step was a choice, then the selected option index should be given as an argument, else that argument is ignored. If an ongoing command (eg. <<wait 3>>) from the dialogue is still running, ErrWaitingForCommandCompletion is returned. Else, if no other error is encountered, the next DialogueElement to display is returned. If the Dialogue has ended, then both return values will be nil.
type YarnSpinnerCommand ¶
YarnSpinnerCommand is a Go function than can be called as a command from a YarnSpinner script. It can take zero, one or more input values, and returns a chan that must return either nil or an error when the command has finished its job.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
parser
Package parser contains code generated by Antlr based from the Lexer.g4 and Parser.g4 files, using the generateParser.sh file at the root of the git repository of the ysgo module.
|
Package parser contains code generated by Antlr based from the Lexer.g4 and Parser.g4 files, using the generateParser.sh file at the root of the git repository of the ysgo module. |
Package markup contains the code used to parse the markup tags in a line of dialogue, along with markup processors that can be used to eg.
|
Package markup contains the code used to parse the markup tags in a line of dialogue, along with markup processors that can be used to eg. |