dialoguebox

package
v0.0.0-...-07f8463 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 11 Imported by: ? modules, 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 dialoguebox is an Ebiten game that shows a dialogue: a dark screen with a box at the bottom, the speaker's name, the text typing out in the speaker's voice, and a hint. Space, Enter or a click skips the typing or goes on to the next line. It plays a dialogue.Script through a dialogue.Player.

The box knows nothing about the browser or the audio device: the caller makes the synth.Stream and plays it (for example with the parent package's Player), and runs the box with ebiten.RunGame.

Index

Constants

View Source
const (
	ScreenWidth  = 480
	ScreenHeight = 270
)

The size of the box's screen; Layout always returns it, and Ebiten scales it to the window.

Variables

This section is empty.

Functions

func Wrap

func Wrap(text string, width int) string

Wrap breaks text into lines of at most width bytes at spaces; a longer word stays whole on its own line.

Types

type Box

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

Box is an ebiten.Game around a dialogue player. Use it from Ebiten's goroutine only (Update, Draw, SetScript).

func New

func New(stream *synth.Stream, opts Options) *Box

New returns a box that speaks on stream. It shows nothing until Box.SetScript.

func (*Box) Draw

func (b *Box) Draw(screen *ebiten.Image)

Draw implements ebiten.Game.

func (*Box) Layout

func (b *Box) Layout(int, int) (int, int)

Layout implements ebiten.Game.

func (*Box) Player

func (b *Box) Player() *dialogue.Player

Player is the current player, nil before SetScript.

func (*Box) Script

func (b *Box) Script() *dialogue.Script

Script is the current script, nil before SetScript.

func (*Box) SetAutoAdvance

func (b *Box) SetAutoAdvance(on bool)

SetAutoAdvance changes hands-free play for the next SetScript.

func (*Box) SetLanguages

func (b *Box) SetLanguages(f func(name string) *voice.Language)

SetLanguages changes the language resolver for the next SetScript.

func (*Box) SetSamples

func (b *Box) SetSamples(l synth.SampleLoader)

SetSamples changes the sample loader for the next SetScript.

func (*Box) SetScript

func (b *Box) SetScript(s *dialogue.Script, voices map[string]*voice.Voice, start int) error

SetScript swaps the dialogue: the running player is closed (its notes released), the speakers' voices are set on the stream, and line start is played. It returns an error for a missing voice, an invalid start line or a voice the stream rejects, and then keeps the old dialogue.

func (*Box) Step

func (b *Box) Step(dt time.Duration)

Step advances the dialogue by dt without reading input: Update calls it every tick, and tests drive the box with it.

func (*Box) Update

func (b *Box) Update() error

Update implements ebiten.Game: input, then one tick of time.

type Options

type Options struct {
	// Languages resolves a voice's language name, see
	// [dialogue.Options].Languages.
	Languages func(name string) *voice.Language
	// AutoAdvance plays hands-free, see [dialogue.Options].AutoAdvance.
	AutoAdvance bool
	// Samples loads the sample files that voices name; nil means none, and a
	// voice with a sample instrument is then rejected by SetScript.
	Samples synth.SampleLoader
}

Options tune a Box.

Jump to

Keyboard shortcuts

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