Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command interface { // Do performs the action. // An error is returned if the action could not be performed. Do(trans Transaction) error // Undo reverses its action to restore the environment to the previous state. // An error is returned if the action could not be successfully undone. The // environment may not be in the state as before in an error occurred. Undo(trans Transaction) error }
Command describes an action that can be performed, undone, and redone.
type Commander ¶
type Commander interface {
Queue(command Command)
}
Commander tries to execute the given command.
type List ¶ added in v0.5.0
type List []Command
List is a sequence of commands, which are executed as one step.
func (List) Do ¶ added in v0.5.0
func (list List) Do(trans Transaction) error
Do performs the entries in the list in ascending order. If an entry returns an error, the iteration is aborted and that error is returned.
func (List) Undo ¶ added in v0.5.0
func (list List) Undo(trans Transaction) error
Undo performs the entries in the list in descending order. If an entry returns an error, the iteration is aborted and that error is returned.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack describes a list of commands. The stack allows to sequentially undo and redo stacked commands. It essentially stores two lists: a list of commands to undo, and another of commands to redo. Modifying stack functions will panic if they are called while already in use.
func (*Stack) CanRedo ¶
CanRedo returns true if there is at least one more command that can be redone.
func (*Stack) CanUndo ¶
CanUndo returns true if there is at least one more command that can be undone.
func (*Stack) Perform ¶
func (stack *Stack) Perform(cmd Command, trans Transaction) error
Perform executes the given command and puts it on the stack if the command was successful. This function also clears the list of commands to be redone.
func (*Stack) Redo ¶
func (stack *Stack) Redo(trans Transaction) error
Redo attempts to perform the next command on the redo list. If there is no further command to redo, nothing happens. An error is returned if the command failed. In this case, the stack is unchanged and a further attempt to redo will try the same command again.
func (*Stack) Undo ¶
func (stack *Stack) Undo(trans Transaction) error
Undo attempts to undo the previous command on the list. If there is no further command to undo, nothing happens. An error is returned if the command failed. In this case, the stack is unchanged and a further attempt to undo will try the same command again.
type Transaction ¶
type Transaction interface { // SetResource changes the meta information about a resource. // Should the resource exist in multiple languages, all are modified. SetResource(id resource.ID, compound bool, contentType resource.ContentType, compressed bool) // SetResourceBlock changes the block data of a resource. // // If the block data is not empty, then: // If the resource does not exist, it will be created with default meta information. // If the block does not exist, the resource is extended to allow its addition. // // If the block data is empty (or nil), then the block is cleared. // If the resource is a compound list, then the underlying data will become visible again. SetResourceBlock(lang resource.Language, id resource.ID, index int, data []byte) // PatchResourceBlock modifies an existing block. // This modification assumes the block already exists and can take the given patch data. // The patch data is expected to be produced by rle.Compress(). (see also: Mod.CreateBlockPatch) PatchResourceBlock(lang resource.Language, id resource.ID, index int, expectedLength int, patch []byte) // SetResourceBlocks sets the entire list of block data of a resource. // This method is primarily meant for compound non-list resources (e.g. text pages). SetResourceBlocks(lang resource.Language, id resource.ID, data [][]byte) // DelResource removes a resource from the mod in the given language. // // After the deletion, all the underlying data of the world will become visible again. DelResource(lang resource.Language, id resource.ID) // SetTextureProperties updates the properties of a specific texture. SetTextureProperties(textureIndex level.TextureIndex, properties texture.Properties) }
Transaction describes actions meant to modify resources.