dialogue

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// Text holds the text displayed on the button. It may use Minecraft
	// formatting codes.
	Text string
}

Button represents a button added to a dialogue menu and consists of just text.

func (Button) MarshalJSON

func (b Button) MarshalJSON() ([]byte, error)

MarshalJSON ...

type Closer

type Closer interface {
	// Close is called when the Submitter closes a dialogue.
	Close(submitter Submitter, tx *world.Tx)
}

Closer represents a dialogue which has special logic when being closed by a Submitter.

type Dialogue

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

Dialogue represents a dialogue menu. This menu can consist of a title, a body and up to 6 different buttons. The menu also shows a 3D render of the entity that is sending the dialogue.

func New

func New(submittable Submittable, title ...any) Dialogue

New creates a new Dialogue menu using the Submittable passed to handle the dialogue interactions. The title passed is formatted following the rules of fmt.Sprintln.

func (Dialogue) Body

func (m Dialogue) Body() string

Body returns the formatted text in the body passed to the menu using WithBody().

func (Dialogue) Buttons

func (m Dialogue) Buttons() []Button

Buttons returns a slice of buttons of the Submittable. It parses them from the fields using reflection and returns them.

func (Dialogue) Close

func (m Dialogue) Close(submitter Submitter, tx *world.Tx)

Close closes the dialogue, calling the Close method on the Submittable if it implements the Closer interface.

func (Dialogue) Display

func (m Dialogue) Display() DisplaySettings

Display returns the DisplaySettings of the Dialogue as specified using WithDisplay().

func (Dialogue) MarshalJSON

func (m Dialogue) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Dialogue) Submit

func (m Dialogue) Submit(index uint, submitter Submitter, tx *world.Tx) error

Submit submits an index of the pressed button to the Submittable. If the index is invalid, an error is returned.

func (Dialogue) Title

func (m Dialogue) Title() string

Title returns the formatted title passed to the dialogue upon construction using New().

func (Dialogue) WithBody

func (m Dialogue) WithBody(body ...any) Dialogue

WithBody creates a copy of the Dialogue and changes its body to the body passed, after which the new Dialogue is returned. The text is formatted following the rules of fmt.Sprintln.

func (Dialogue) WithButtons

func (m Dialogue) WithButtons(buttons ...Button) Dialogue

WithButtons creates a copy of the Dialogue and appends the buttons passed to the existing buttons, after which the new Dialogue is returned.

func (Dialogue) WithDisplay

func (m Dialogue) WithDisplay(display DisplaySettings) Dialogue

WithDisplay returns a new Dialogue with the DisplaySettings passed.

type DisplaySettings

type DisplaySettings struct {
	// EntityScale specifies the scale of the entity displayed in the dialogue.
	EntityScale mgl64.Vec3
	// EntityOffset specifies the offset of the entity shown in the dialogue.
	EntityOffset mgl64.Vec3
	// EntityRotation is the rotation of the entity shown in the dialogue. This
	// rotation functions a bit differently to the normal entity rotation in
	// Minecraft: The values are still degrees, but pitch (rot[1]) values are
	// whole-body pitch instead of head-specific, and rot[2] is whole-body roll.
	EntityRotation mgl64.Vec3
}

DisplaySettings holds optional fields that change the way the dialogue, particularly the entity shown in it, is displayed.

func (DisplaySettings) MarshalJSON

func (d DisplaySettings) MarshalJSON() ([]byte, error)

MarshalJSON encodes the DisplaySettings to JSON.

type Submittable

type Submittable interface {
	// Submit is called when the Submitter submits the dialogue sent to it. The
	// method is called with the button that was pressed. It may be compared
	// with buttons in the Submittable struct to check which button was pressed.
	// Additionally, the world.Tx of the Submitter is passed.
	Submit(submitter Submitter, pressed Button, tx *world.Tx)
}

Submittable is a structure which may be submitted by sending it as a dialogue using dialogue.New(). The struct will have its Submit method called with the button pressed. A struct that implements the Submittable interface must only have exported fields with the type dialogue.Button.

type Submitter

type Submitter interface {
	SendDialogue(d Dialogue, e world.Entity)
	CloseDialogue()
}

Submitter is an entity that is able to submit a dialogue sent to it. It is able to interact with the buttons in the dialogue. The Submitter is also able to close the dialogue.

Jump to

Keyboard shortcuts

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