brush

package
v0.0.0-...-6250647 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSelectionForm

func NewSelectionForm() form.Form

NewSelectionForm returns a new SelectionForm form.

func Perform

func Perform(pos cube.Pos, s Shape, a Action, w *world.World) (revert func())

Perform performs the world edit action passed in a specific shape, in the world that is passed. Perform will only ever edit blocks found within the shape passed. Perform returns a function which may be called to undo the modification.

func RegisterAction

func RegisterAction(name string, v func() Action)

RegisterAction registers a function that returns an act.Action with the name of the action passed.

func RegisterShape

func RegisterShape(name string, v func(r int) Shape)

RegisterShape registers a function that returns a geo.Shape with the name of the shape passed.

func Unbind

func Unbind(i item.Stack) item.Stack

Unbind unbinds any Brush bound to the item.Stack passed and returns an unbound version of the stack.

Types

type Action

type Action interface {
	// At returns the world.Block and world.Liquid behind it that should be placed at a specific x, y and z in the
	// *world.World passed.
	// At should use the *rand.Rand instance passed to produce random numbers and must only use the at function to
	// read blocks at a specific position in the world.
	// If At returns a nil world.Block, no block will be placed at that position.
	At(x, y, z int, r *rand.Rand, w *world.World, at func(x, y, z int) world.Block) (world.Block, world.Liquid)
	// Form returns a form that has to be submitted by a player in order to provide additional values for the
	// action. Actions that do not need additional data can return nil for this value. The geo.Shape selected by
	// the *player.Player is passed to the function.
	Form(s Shape) form.Form
}

Action is a brush action that may be performed on all blocks in a Shape through a call to Perform.

type BindCommand

type BindCommand struct {
	Sub cmd.SubCommand `cmd:"bind"`
	// contains filtered or unexported fields
}

BindCommand implements the binding of a Brush to an item in the player's inventory.

func (BindCommand) Allow

func (BindCommand) Allow(src cmd.Source) bool

Allow returns false if the cmd.Source passed is not of the type *player.Player.

func (BindCommand) Run

func (BindCommand) Run(src cmd.Source, o *cmd.Output)

Run implements the binding of a Brush to the held item by sending a brush selection form.

type Brush

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

func Lookup

func Lookup(id uuid.UUID) (*Brush, bool)

func New

func New(s Shape, a Action) Brush

func (Brush) Bind

func (b Brush) Bind(i item.Stack) item.Stack

Bind binds the Brush to the item.Stack i passed and returns a new item.Stack with the Brush bound to it.

func (Brush) UUID

func (b Brush) UUID() uuid.UUID

func (Brush) Use

func (b Brush) Use(p *player.Player)

type Handler

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

Handler implements the brushing of players. It enables activation of brushes and stores the data needed to undo/redo those actions.

func LookupHandler

func LookupHandler(p *player.Player) (*Handler, bool)

LookupHandler finds the Handler of a specific player.Player, assuming it is currently online.

func NewHandler

func NewHandler(p *player.Player) *Handler

NewHandler creates a new Handler for the *player.Player passed.

func (*Handler) HandleItemUse

func (h *Handler) HandleItemUse(ctx *event.Context)

HandleItemUse activates the brush on a player's item if present.

func (*Handler) HandleQuit

func (h *Handler) HandleQuit()

HandleQuit deletes the Handler from the handlers map.

func (*Handler) UndoLatest

func (h *Handler) UndoLatest() bool

UndoLatest undoes the latest brush action. If no action was left to undo, false is returned.

type SelectionForm

type SelectionForm struct {
	Shape  form.Dropdown
	Radius form.Slider
	Action form.Dropdown
}

SelectionForm is a form that is sent when the player binds a brush to an item. It will allow the user to select a brush shape and action, and will follow up with another form with specific buttons to alter the behaviour of the action.

func (SelectionForm) Submit

func (s SelectionForm) Submit(submitter form.Submitter)

Submit ...

type Shape

type Shape interface {
	// Inside checks if a specific X, Y and Z is within the shape with centre position (cx, cy, cz). If this is
	// the case, Inside returns true.
	Inside(cx, cy, cz, x, y, z int) bool
	// Dim returns the dimensions of the shape in blocks.
	Dim() [3]int
}

Shape represents a shape over which an Action may be performed through a call to Perform.

type UnbindCommand

type UnbindCommand struct {
	Sub cmd.SubCommand `cmd:"unbind"`
	// contains filtered or unexported fields
}

UnbindCommand implements unbinding of a Brush previously attached to an item in the player's inventory using /brush bind.

func (UnbindCommand) Allow

func (UnbindCommand) Allow(src cmd.Source) bool

Allow returns false if the cmd.Source passed is not of the type *player.Player.

func (UnbindCommand) Run

func (c UnbindCommand) Run(src cmd.Source, o *cmd.Output)

Run implements the unbinding of a Brush bound to the item held.

type UndoCommand

type UndoCommand struct {
	Sub cmd.SubCommand `cmd:"undo"`
	// contains filtered or unexported fields
}

UndoCommand implements the undoing of one of the most recent actions performed by a player using a Brush.

func (UndoCommand) Allow

func (UndoCommand) Allow(src cmd.Source) bool

Allow returns false if the cmd.Source passed is not of the type *player.Player.

func (UndoCommand) Run

func (c UndoCommand) Run(src cmd.Source, o *cmd.Output)

Run implements the undoing of an action performed with a Brush.

Jump to

Keyboard shortcuts

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