aseprite

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

aseprite

Aseprite JSON loader

README not finished yet. To see examples please see examples/. There are examples using various visual engines.

Documentation

Overview

Package aseprite is the primary package to interface with the parsed aseprite files and its animations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	// Name of the animation.
	Name string `json:"name"`
	// The beginning frame of the animation.
	From int `json:"from"`
	// The ending frame of the animation.
	To int `json:"to"`
	// Animation's playback direction.
	// Example:
	//  - PlayForward
	//  - PlayReverse
	//  - PlayPingPong
	Direction Direction `json:"direction"`
}

Animation holds the metadata about the playing animation including its beginning frame (From) and ending frame (To).

type AnimationInfo

type AnimationInfo struct {
	CurrentAnimation *Animation

	PlaySpeed float32

	Playing bool

	PrevFrame        int
	PrevCurrentFrame int // what?
	CurrentFrame     int
	// contains filtered or unexported fields
}

AnimationInfo stores essential information used when using the update game loop.

func (*AnimationInfo) AnimationFinished

func (i *AnimationInfo) AnimationFinished() bool

AnimationFinished returns a boolean if the currently used animation being used for the Game Loop is finished playing.

func (*AnimationInfo) IsPlaying

func (i *AnimationInfo) IsPlaying(animation string) bool

IsPlaying returns a boolean if the provided animation is currently being used for the Game Loop.

type Boundary

type Boundary struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"w"`
	Height int `json:"h"`
}

Boundary is a basic object to store position coordinates, width, and height.

func (Boundary) Rectangle

func (b Boundary) Rectangle() image.Rectangle

Rectangle returns a basic rectangle of the belonging coordinates.

type Direction

type Direction uint8

Direction represents the playback directions for an animation.

const (
	// PlayForward playsback frames in incremental order.
	// Frames [0, 1, 2, 3, 4, 5]
	// Order  [0, 1, 2, 3, 4, 5]
	PlayForward Direction = iota // forward
	// PlayReverse playsback frames in decremental order.
	// Frames [0, 1, 2, 3, 4, 5]
	// Order  [5, 4, 3, 2, 1, 0]
	PlayReverse // reverse
	// PlayPingPong plays frames in incremental order, then once reaching the
	// last frame the animation will play in decremental order.
	// Frames [0, 1, 2, 3, 4, 5]
	// Order  [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, ...]
	PlayPingPong // pingpong
)

func DirectionFromString

func DirectionFromString(str string) Direction

DirectionFromString returns a Direction based on the value of the string. Note: This function assumes that the string is lowercased correctly.

func (Direction) String

func (i Direction) String() string

func (*Direction) UnmarshalJSON

func (d *Direction) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a byte slice representing the string values of the data and then sets the value to a Direction.

type Error

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

Error is used as a custom error for the aseprite package.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap unwraps and returns the original error if one exists. Note: Go 1.13 change

type File

type File struct {
	Frames FrameData `json:"frames"`
	Meta   MetaData  `json:"meta"`
	AnimationInfo
}

File is the final parsed aseprite file. This includes helpful methods to interact and get information about the animations and its frames.

func NewFile

func NewFile(data []byte) (*File, error)

NewFile takes the file's data and unmarshals it into a new File. What's the point in using this? Maybe saving an extra import? I'm not really sure at this point.

func Open added in v0.3.0

func Open(filePath string) (*File, error)

Open will remove some of the pain of reading the data from the aseprite JSON file and loading it into memory then giving it over here to turn into a file. Instead this will open the filepath and then read the bytes and return an aseprite File.

func (*File) Animation added in v0.3.0

func (f *File) Animation(animation string) *Animation

Animation will search the slices in the aseprite file and return any animation that matches the name provided. Note: Animation is a duplicate of GetSlice is almost every way. This is because of the limitations of Golang that I cannot address. There are no generics in the language yet that would allow me to prevent this code duplication.

func (*File) FrameBoundaries added in v0.3.0

func (f *File) FrameBoundaries() Boundary

FrameBoundaries will return the current frame's bounding box.

func (*File) HasAnimation

func (f *File) HasAnimation(animation string) bool

HasAnimation returns a boolean value that represents whether the provided animation is contained in the aseprite file.

func (*File) HasSlice

func (f *File) HasSlice(slice string) bool

HasSlice returns a boolean value that represents whether the provided slice is contained in the aseprite file.

func (*File) Play

func (f *File) Play(animation string) error

Play will mark an animation in the list of animations listed in the aseprite file to be used for the Update method.

func (*File) Slice added in v0.3.0

func (f *File) Slice(slice string) *Slice

Slice will search the slices in the aseprite file and return any slice that matches the name provided. Note: Slice is a duplicate of GetAnimation is almost every way. This is because of the limitations of Golang that I cannot address. There are no generics in the language yet that would allow me to prevent this code duplication.

func (*File) Update

func (f *File) Update(dt float32)

Update is used for a Game Loop in such an OpenGL style workflow. This can be helpful for tracking the frame of the animation.

type Frame

type Frame struct {
	FileName         string      `json:"filename,omitempty"`
	FrameBoundaries  Boundary    `json:"frame"`
	Rotated          bool        `json:"rotated"`
	Trimmed          bool        `json:"trimmmed"`
	SpriteSourceSize Boundary    `json:"spriteSourceSize"`
	SourceSize       WidthHeight `json:"sourceSize"`
	Duration         float32     `json:"duration"`
}

Frame contains the data about a frame.

type FrameData

type FrameData struct {
	IsMap bool `json:"-"`
	// contains filtered or unexported fields
}

FrameData contains all the frames in the animation and their data.

func (*FrameData) FrameAtIndex

func (d *FrameData) FrameAtIndex(index int) Frame

FrameAtIndex uses the local copy of the sliced frames and searches for the frame on the nth index.

func (*FrameData) FrameAtKey

func (d *FrameData) FrameAtKey(key string) Frame

FrameAtKey uses the local copy of the mapped frames and searches for the frame assigned to the given key.

func (*FrameData) FrameMap

func (d *FrameData) FrameMap() map[string]Frame

FrameMap returns a reference to the mapped version of the frames.

func (*FrameData) FrameSlice

func (d *FrameData) FrameSlice() []Frame

FrameSlice returns a reference to the sliced version of the frames.

func (*FrameData) LenFrames

func (d *FrameData) LenFrames() int

LenFrames return the length of the number of frames in the aseprite file.

func (*FrameData) UnmarshalJSON

func (d *FrameData) UnmarshalJSON(data []byte) error

UnmarshalJSON handles the problem of different layouts in the JSON file. Sometimes the file can be a map for the frames and sometimes it can be a slice.

type Layer

type Layer struct {
	Name      string `json:"name"`
	Opacity   int    `json:"opacity"`
	BlendMode string `json:"blendMode"`
}

Layer contains the data about the individual animation layer including its name, opacity, and blending mode. Layers can be used to stack on top of each other to create unique affects on the animation itself.

type MetaData

type MetaData struct {
	App        string      `json:"app"`
	Version    string      `json:"version"`
	Image      string      `json:"image"`
	Format     string      `json:"format"`
	Size       WidthHeight `json:"size"`
	Scale      string      `json:"scale"`
	Animations []Animation `json:"frameTags,omitempty"`
	Layers     []Layer     `json:"layers,omitempty"`
	Slices     []Slice     `json:"slices,omitempty"`
}

MetaData is the data about the overall animation including animation playback directions, layer opacity, and pivot points.

func (*MetaData) LenAnimations

func (m *MetaData) LenAnimations() int

LenAnimations returns the length of the Animations slice.

func (*MetaData) LenLayers

func (m *MetaData) LenLayers() int

LenLayers returns the length of the Layers slice.

func (*MetaData) LenSlices

func (m *MetaData) LenSlices() int

LenSlices returns the length of the Slices slice.

type Slice

type Slice struct {
	Name  string     `json:"name"`
	Color string     `json:"color"`
	Keys  []SliceKey `json:"keys"`
}

Slice is used for slicing up an image in a layer or animation in aseprite. In this struct it contains the information about the slice itself including its keys, color, and the name of the slice.

type SliceKey

type SliceKey struct {
	FrameNum int         `json:"frame"`
	Bounds   Boundary    `json:"bounds"`
	Center   Boundary    `json:"center"`
	Pivot    image.Point `json:"pivot"`
}

SliceKey stores the information about each slice including its frame number, the boundaries of the slice, and more.

type WidthHeight

type WidthHeight struct {
	Width  int `json:"w"`
	Height int `json:"h"`
}

WidthHeight is a basic object to store width and height.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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