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
- Variables
- func AddClipEntry(f *animfile.File, name string) error
- func ClearBody(f *animfile.File) error
- func ClearDurations(f *animfile.File, clip string) error
- func Contains(r animfile.Rect, p gfx.Vec2) bool
- func DeleteBox(f *animfile.File, clip string, ref BoxRef) error
- func ExtendToFrame(f *animfile.File, clip string, ref BoxRef, frame int) error
- func Flip(r animfile.Rect) animfile.Rect
- func IsAsepriteExport(key string) bool
- func MoveRect(r animfile.Rect, dx, dy int32) animfile.Rect
- func New() toolshell.Tool
- func NewDefinition(sheetPath, defPath string) ([]byte, error)
- func RectBetween(a, b gfx.Vec2) animfile.Rect
- func ResizeRect(r animfile.Rect, h Handle, dx, dy int32) animfile.Rect
- func SetBoxRect(f *animfile.File, clip string, ref BoxRef, r animfile.Rect) error
- func SetClipPivot(f *animfile.File, clip string, p *animfile.Point) error
- func SetDefaultClip(f *animfile.File, name string) error
- func SetFPS(f *animfile.File, clip string, fps int) error
- func SetFilePivot(f *animfile.File, p *animfile.Point) error
- func SetFrameDuration(f *animfile.File, clip string, current []int, frame, ms int) error
- func SetLoop(f *animfile.File, clip string, mode int) error
- func SetShapeFrames(f *animfile.File, clip string, ref BoxRef, all bool, from int, to *int) error
- func SetShapeID(f *animfile.File, clip string, ref BoxRef, id string) error
- func SetShapeKind(f *animfile.File, clip string, ref BoxRef, kind string) error
- func SetSpeed(f *animfile.File, clip string, speed float64) error
- func Timeline(rc *animfile.ResolvedClip) *anim.Clip
- func ToRect(r animfile.Rect) gfx.Rect
- type Box
- type BoxRef
- type Drag
- type DragKind
- type Geom
- type Handle
- type Playback
- type State
- func (s *State) Boxes() []Box
- func (s *State) Cancel()
- func (s *State) ClipName() string
- func (s *State) DeleteSelected() error
- func (s *State) FrameDurationsMS() []int
- func (s *State) MarkStale(err error)
- func (s *State) NFrames() int
- func (s *State) Nudge(dx, dy int32) error
- func (s *State) Panel(title string, view toolshell.Section) toolshell.Panel
- func (s *State) Pivot() *animfile.Point
- func (s *State) PointerDown(p gfx.Vec2, tol float32) error
- func (s *State) PointerMove(p gfx.Vec2)
- func (s *State) PointerUp(p gfx.Vec2) error
- func (s *State) Ready() bool
- func (s *State) SelectClip(i int)
- func (s *State) Set(id string, v json.RawMessage) error
- func (s *State) SetFile(f *animfile.File)
- func (s *State) SetSheet(sh *animfile.Sheet, err error)
- type Tool
- func (*Tool) Check(key string) error
- func (t *Tool) Close(s *toolshell.Shell)
- func (t *Tool) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)
- func (t *Tool) Load(text []byte) error
- func (t *Tool) Open(s *toolshell.Shell, key string) error
- func (t *Tool) Panel() toolshell.Panel
- func (t *Tool) Set(id string, v json.RawMessage) error
- func (t *Tool) Sync(s *toolshell.Shell)
- func (t *Tool) Update(s *toolshell.Shell)
- type ToolKind
Constants ¶
const ( KindHit = "hit" KindHurt = "hurt" KindBody = "body" )
Shape kinds of a definition, and the kind name of body boxes.
const ( LoopSheet = iota LoopOn LoopOff )
Loop modes of the panel's dropdown, in order: the sheet's, "loop": true, "loop": false.
const TickDuration = time.Second / 60
TickDuration is how much playback time one tool tick adds. The engine runs at 60 ticks per second.
Variables ¶
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.
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 ¶
AddClipEntry lists the clip in the file ({}), if it is not.
func ClearDurations ¶
ClearDurations removes the clip's "durations".
func ExtendToFrame ¶
ExtendToFrame grows a shape's frame range to include frame. A shape over all frames already does.
func Flip ¶
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 ¶
IsAsepriteExport reports whether key names an Aseprite export by one of AsepriteSuffixes.
func NewDefinition ¶
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 ¶
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 ¶
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 ¶
SetBoxRect replaces the rect of a box.
func SetClipPivot ¶
SetClipPivot sets the clip's own pivot; nil removes it.
func SetDefaultClip ¶
SetDefaultClip sets "defaultClip"; an empty name removes it.
func SetFilePivot ¶
SetFilePivot sets the top-level pivot; nil removes it.
func SetFrameDuration ¶
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 SetShapeFrames ¶
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 ¶
SetShapeID sets a shape's id.
func SetShapeKind ¶
SetShapeKind sets a shape's kind to KindHit or KindHurt.
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 ¶
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 ¶
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 ¶
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 ¶
CopyToFrame adds a shape like the one at ref, on frame only, and returns it: the way to key a box per frame.
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 Geom ¶
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.
type Playback ¶
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 ¶
Advance moves time by dt while playing. A clip that does not loop stops on its last frame.
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 ¶
NewState returns a state that sends every edit to emit as the text of the new document version.
func (*State) DeleteSelected ¶
DeleteSelected removes the selected box.
func (*State) FrameDurationsMS ¶
FrameDurationsMS are the shown clip's durations in whole ms.
func (*State) MarkStale ¶
MarkStale keeps the shown file and notes that the document does not parse.
func (*State) 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 ¶
Pivot is the pivot of the shown clip: its own, else the file's, nil if neither.
func (*State) PointerDown ¶
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 ¶
PointerMove updates the gesture's preview.
func (*State) PointerUp ¶
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) SelectClip ¶
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.
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 ¶
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) Close ¶
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 ¶
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 ¶
Open implements toolshell.Tool.
func (*Tool) Set ¶
func (t *Tool) Set(id string, v json.RawMessage) error
Set implements toolshell.Tool.
func (*Tool) Sync ¶
Sync implements toolshell.Syncer: it advances playback, notices a reloaded sheet and puts the current frame's sprite on the entity.