animedit

package
v0.0.0-...-94fff03 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 20 Imported by: 1 module, 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 animedit is the "anim" tool of wpix-editor: an editor for *.anim.json animation definitions (doc/guide/engine/animation.md). It plays a clip of the definition's sheet and shows the pivot, the body and the hit and hurt boxes of the current frame; boxes are drawn, moved, resized and deleted with the mouse, everything else the format has is edited in the panel.

The model is the animfile.File itself. Every change is a function on the File (edit.go), then animfile.Encode, then one Shell.Edit, so the file the tool writes is one the loader and "wpix anim validate" accept. The files without Ebiten (edit, geometry, playback, panel) hold the logic and are tested without a display; tool.go is the glue.

Index

Constants

View Source
const (
	KindHit  = "hit"
	KindHurt = "hurt"
	KindBody = "body"
)

Shape kinds of a definition, and the kind name of body boxes.

View Source
const (
	LoopSheet = iota
	LoopOn
	LoopOff
)

Loop modes of the panel's dropdown, in order: the sheet's, "loop": true, "loop": false.

View Source
const TickDuration = time.Second / 60

TickDuration is how much playback time one tool tick adds. The engine runs at 60 ticks per second.

Variables

View Source
var AsepriteSuffixes = []string{".aseprite.json", ".ase.json"}

AsepriteSuffixes are the name suffixes of an Aseprite export that the tool opens read-only to play its clips.

View Source
var ErrReadOnly error = asepriteReadOnly{}

ErrReadOnly is returned by every edit of a read-only view, an Aseprite export opened in the anim tool: it is somebody else's file, shown to play its clips. It matches toolshell.ErrReadOnly with errors.Is.

Functions

func AddClipEntry

func AddClipEntry(f *animfile.File, name string) error

AddClipEntry lists the clip in the file ({}), if it is not.

func ClearBody

func ClearBody(f *animfile.File) error

ClearBody removes every "body" rect.

func ClearDurations

func ClearDurations(f *animfile.File, clip string) error

ClearDurations removes the clip's "durations".

func Contains

func Contains(r animfile.Rect, p gfx.Vec2) bool

Contains reports whether the world point p is inside r.

func DeleteBox

func DeleteBox(f *animfile.File, clip string, ref BoxRef) error

DeleteBox removes a box.

func ExtendToFrame

func ExtendToFrame(f *animfile.File, clip string, ref BoxRef, frame int) error

ExtendToFrame grows a shape's frame range to include frame. A shape over all frames already does.

func Flip

func Flip(r animfile.Rect) animfile.Rect

Flip mirrors r around x = 0, as Box.World does for a flipped sprite. It is its own inverse, so it also maps a mouse position back.

func IsAsepriteExport

func IsAsepriteExport(key string) bool

IsAsepriteExport reports whether key names an Aseprite export by one of AsepriteSuffixes.

func MoveRect

func MoveRect(r animfile.Rect, dx, dy int32) animfile.Rect

MoveRect moves r by dx, dy.

func New

func New() toolshell.Tool

New returns the anim tool.

func NewDefinition

func NewDefinition(sheetPath, defPath string) ([]byte, error)

NewDefinition returns the text of the starter definition of the Aseprite export at sheetPath, to be saved as defPath (the same text "wpix anim create" writes). The "sheet" value is the export's path relative to the definition's folder.

func RectBetween

func RectBetween(a, b gfx.Vec2) animfile.Rect

RectBetween returns the pixel rect spanned by two world points, each rounded to the nearest pixel corner. It may be empty (a click without a drag): the caller drops anything under 1×1.

func ResizeRect

func ResizeRect(r animfile.Rect, h Handle, dx, dy int32) animfile.Rect

ResizeRect moves the edges of r that handle h controls by dx, dy and keeps the size at least 1×1: the edge opposite to the handle stays where it is.

func SetBoxRect

func SetBoxRect(f *animfile.File, clip string, ref BoxRef, r animfile.Rect) error

SetBoxRect replaces the rect of a box.

func SetClipPivot

func SetClipPivot(f *animfile.File, clip string, p *animfile.Point) error

SetClipPivot sets the clip's own pivot; nil removes it.

func SetDefaultClip

func SetDefaultClip(f *animfile.File, name string) error

SetDefaultClip sets "defaultClip"; an empty name removes it.

func SetFPS

func SetFPS(f *animfile.File, clip string, fps int) error

SetFPS sets the clip's "fps"; 0 removes it.

func SetFilePivot

func SetFilePivot(f *animfile.File, p *animfile.Point) error

SetFilePivot sets the top-level pivot; nil removes it.

func SetFrameDuration

func SetFrameDuration(f *animfile.File, clip string, current []int, frame, ms int) error

SetFrameDuration sets the duration in ms of one frame (play order) of the clip. The first change writes the whole "durations" array from current, the durations the clip has now in ms, since the format wants one value per frame.

func SetLoop

func SetLoop(f *animfile.File, clip string, mode int) error

SetLoop sets the clip's "loop" from a LoopSheet, LoopOn or LoopOff.

func SetShapeFrames

func SetShapeFrames(f *animfile.File, clip string, ref BoxRef, all bool, from int, to *int) error

SetShapeFrames sets a shape's frame range: all is every frame; otherwise from, and to unless it is nil (the single frame from).

func SetShapeID

func SetShapeID(f *animfile.File, clip string, ref BoxRef, id string) error

SetShapeID sets a shape's id.

func SetShapeKind

func SetShapeKind(f *animfile.File, clip string, ref BoxRef, kind string) error

SetShapeKind sets a shape's kind to KindHit or KindHurt.

func SetSpeed

func SetSpeed(f *animfile.File, clip string, speed float64) error

SetSpeed sets the clip's "speed"; 0 removes it.

func Timeline

func Timeline(rc *animfile.ResolvedClip) *anim.Clip

Timeline builds the clip to play from the definition's resolved clip: frames with the final durations and its loop mode. Only the durations and the loop mode are set; sprites come from the sheet's own clip.

func ToRect

func ToRect(r animfile.Rect) gfx.Rect

ToRect converts a pixel rect to a world rect.

Types

type Box

type Box struct {
	Ref  BoxRef
	Kind string // KindBody, KindHit or KindHurt
	ID   string
	Rect animfile.Rect
	// Replaced is set on a body box that a hurt shape replaces on this
	// frame: it is drawn dimmed and cannot be picked.
	Replaced bool
}

Box is a box of the current frame with where it comes from in the file.

func ActiveBoxes

func ActiveBoxes(f *animfile.File, clip string, frame, n int) []Box

ActiveBoxes returns the boxes on frame of a clip with n frames in the order of animfile.Resolve: the body boxes, then the shapes that cover the frame in file order. If a hurt shape covers the frame the body boxes are still listed but marked Replaced.

type BoxRef

type BoxRef struct {
	Body  bool
	Index int
}

BoxRef names a box of a clip: a rect of the file's "body" (Body true, Index into it) or a shape of the clip (Index into its "shapes").

func AddBox

func AddBox(f *animfile.File, clip, kind string, frame int, r animfile.Rect) (BoxRef, error)

AddBox adds a box and returns its reference. kind is KindBody (appended to "body"), KindHit or KindHurt (a shape of clip over frame only).

func CopyToFrame

func CopyToFrame(f *animfile.File, clip string, ref BoxRef, frame int) (BoxRef, error)

CopyToFrame adds a shape like the one at ref, on frame only, and returns it: the way to key a box per frame.

func Pick

func Pick(boxes []Box, p gfx.Vec2) (BoxRef, bool)

Pick returns the topmost box at p: later boxes over earlier ones, so shapes over the body. Replaced boxes cannot be picked.

type Drag

type Drag struct {
	Kind   DragKind
	Ref    BoxRef
	Handle Handle
	// Rect is the box as the gesture has it now (for DragDraw the box
	// being drawn; Box is its tool kind). Pivot is the pivot being placed.
	Rect animfile.Rect
	Box  string
	// At is the pivot being placed as a world point (pixels from the
	// current pivot); Pivot is the same in trimmed-image pixels.
	At, Pivot animfile.Point
	// contains filtered or unexported fields
}

Drag is a mouse gesture in progress. A drag only previews: the file is written once, on release, so one gesture is one undo step.

type DragKind

type DragKind int

DragKind is what a mouse gesture does.

const (
	DragMove DragKind = iota
	DragResize
	DragDraw
	DragPivot
)

Gestures.

type Geom

type Geom struct {
	Size, Offset, Trim, Origin gfx.Vec2
}

Geom is what the tool needs to know of the shown sprite: its untrimmed size, where the trimmed image starts in it and how big that image is, and the default pivot the sprite is drawn around when the file has none (a fraction of Size).

type Handle

type Handle uint8

Handle is one of the eight resize handles of a rect, or none.

const (
	HandleNone Handle = iota
	HandleNW
	HandleN
	HandleNE
	HandleE
	HandleSE
	HandleS
	HandleSW
	HandleW
)

Handles, clockwise from the top-left corner.

func HandleAt

func HandleAt(r animfile.Rect, p gfx.Vec2, tol float32) Handle

HandleAt returns the handle of r within tol world units of p, corners before edges.

type Playback

type Playback struct {
	Playing bool
	Time    time.Duration
	Frame   int
}

Playback is the clock of the clip being shown. The shell ticks paused with no animation system, and the editor needs stepping and scrubbing, so it keeps its own time and asks anim.Clip.FrameAt for the frame: one implementation of loop, once and ping-pong for the game and the editor.

func (*Playback) Advance

func (p *Playback) Advance(c *anim.Clip, dt time.Duration)

Advance moves time by dt while playing. A clip that does not loop stops on its last frame.

func (*Playback) Seek

func (p *Playback) Seek(c *anim.Clip, frame int)

Seek shows frame (clamped to the clip) and sets the time to its start.

func (*Playback) Step

func (p *Playback) Step(c *anim.Clip, delta int)

Step pauses and moves by delta frames, wrapping around the clip.

type State

type State struct {
	// Model holds the decoded definition (File), its stale mark and the
	// edit path. ReadOnly is set when the file is an Aseprite export (File
	// is then an empty definition of it): clips play, nothing can be edited.
	toolshell.Model[*animfile.File]
	// Sheet is what File refers to (nil when the sheet cannot be read, then
	// SheetErr says why).
	Sheet    *animfile.Sheet
	SheetErr string
	// Res is File resolved against Sheet, nil when Resolve found errors;
	// Findings are the errors, warnings and notes of animfile.Diagnose.
	Res      *animfile.Resolved
	Findings []animfile.Finding

	// Clip indexes Sheet.Tags.
	Clip int
	Play Playback
	Flip bool
	Tool ToolKind
	// Sel is the selected box of the clip, if any.
	Sel *BoxRef
	// Drag is the mouse gesture in progress.
	Drag *Drag
	// Geom is the sprite of the shown frame, set by the tool each tick; the
	// pivot tool needs it to turn a point into trimmed-image pixels.
	Geom Geom
}

State is everything the tool knows: the definition (the model), its sheet, what is selected and played. It has no Ebiten in it, so tests drive it directly; the tool in tool.go feeds it the mouse and the keys.

func NewState

func NewState(emit func(text []byte)) *State

NewState returns a state that sends every edit to emit as the text of the new document version.

func (*State) Boxes

func (s *State) Boxes() []Box

Boxes are the boxes on the current frame.

func (*State) Cancel

func (s *State) Cancel()

Cancel drops a gesture without writing it.

func (*State) ClipName

func (s *State) ClipName() string

ClipName is the name of the tag being shown, "" without a sheet.

func (*State) DeleteSelected

func (s *State) DeleteSelected() error

DeleteSelected removes the selected box.

func (*State) FrameDurationsMS

func (s *State) FrameDurationsMS() []int

FrameDurationsMS are the shown clip's durations in whole ms.

func (*State) MarkStale

func (s *State) MarkStale(err error)

MarkStale keeps the shown file and notes that the document does not parse.

func (*State) NFrames

func (s *State) NFrames() int

NFrames is the number of frames of the shown clip.

func (*State) Nudge

func (s *State) Nudge(dx, dy int32) error

Nudge moves the selected box by dx, dy pixels.

func (*State) Panel

func (s *State) Panel(title string, view toolshell.Section) toolshell.Panel

Panel is the panel of the tool as it is now, without the view section the shell adds: the tool puts it in at the place it wants (before the problems).

func (*State) Pivot

func (s *State) Pivot() *animfile.Point

Pivot is the pivot of the shown clip: its own, else the file's, nil if neither.

func (*State) PointerDown

func (s *State) PointerDown(p gfx.Vec2, tol float32) error

PointerDown starts a gesture at world point p (in file space, so already mirrored when the view is flipped). tol is the handle size in world units.

func (*State) PointerMove

func (s *State) PointerMove(p gfx.Vec2)

PointerMove updates the gesture's preview.

func (*State) PointerUp

func (s *State) PointerUp(p gfx.Vec2) error

PointerUp ends the gesture and writes it as one edit. A box that is not 1×1 yet, or a move that moved nothing, writes nothing.

func (*State) Ready

func (s *State) Ready() bool

Ready reports whether there is a definition and a sheet with tags to show.

func (*State) SelectClip

func (s *State) SelectClip(i int)

SelectClip shows tag i and clears the selection.

func (*State) Set

func (s *State) Set(id string, v json.RawMessage) error

Set applies a changed widget. It returns an error for a value the format refuses; the file is not written then.

func (*State) SetFile

func (s *State) SetFile(f *animfile.File)

SetFile replaces the definition (a new document version) and clears a stale mark. The selection and the clip survive when they are still valid.

func (*State) SetSheet

func (s *State) SetSheet(sh *animfile.Sheet, err error)

SetSheet replaces the sheet, or records why there is none.

type Tool

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

Tool is the anim tool. It implements toolshell.DocumentTool, toolshell.Syncer and toolshell.Checker.

func NewPreview

func NewPreview(scope *asset.Scope) *Tool

NewPreview returns the tool for the preview of an Aseprite export, which switches files: it loads the clip set into scope, which the caller releases, and Tool.Close removes its entity.

func (*Tool) Check

func (*Tool) Check(key string) error

Check reports whether the tool can open the file at asset key.

func (*Tool) Close

func (t *Tool) Close(s *toolshell.Shell)

Close removes the entity Open spawned. The preview calls it before it switches files; the editor never does, since its window or page shows one document.

func (*Tool) Draw

func (t *Tool) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)

Draw implements toolshell.Tool: the overlay in window pixels.

func (*Tool) Load

func (t *Tool) Load(text []byte) error

Load implements toolshell.DocumentTool: a new version of the document. One that does not parse leaves the shown file as it is and marks it stale.

func (*Tool) Open

func (t *Tool) Open(s *toolshell.Shell, key string) error

Open implements toolshell.Tool.

func (*Tool) Panel

func (t *Tool) Panel() toolshell.Panel

Panel implements toolshell.Tool.

func (*Tool) Set

func (t *Tool) Set(id string, v json.RawMessage) error

Set implements toolshell.Tool.

func (*Tool) Sync

func (t *Tool) Sync(s *toolshell.Shell)

Sync implements toolshell.Syncer: it advances playback, notices a reloaded sheet and puts the current frame's sprite on the entity.

func (*Tool) Update

func (t *Tool) Update(s *toolshell.Shell)

Update implements toolshell.Tool: the keys and the mouse in the viewport.

type ToolKind

type ToolKind int

ToolKind is the tool the mouse uses in the viewport.

const (
	ToolSelect ToolKind = iota
	ToolPivot
	ToolHit
	ToolHurt
	ToolBody
)

The tools, in the order of the panel's dropdown.

Jump to

Keyboard shortcuts

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