aseprite

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(ctx context.Context, input ImportInput) (*pb.AtlasFile, error)

Types

type AnimDirection

type AnimDirection string

AnimDirection represents Aseprite animation directions

const (
	// AnimForward forward animation
	AnimForward AnimDirection = "forward"
	// AnimReverse reverse animation
	AnimReverse AnimDirection = "reverse"
	// AnimPingPong goes forward and backwards endlessly
	AnimPingPong AnimDirection = "pingpong"
)

type AnimEventIO

type AnimEventIO struct {
	Frame      int    `json:"frame,omitempty"`
	EventName  string `json:"event_name"`
	EventValue string `json:"event_value"`
}

type Animation

type Animation struct {
	Name  string          `json:"name"`
	Clips []AnimationClip `json:"clips"`
}

type AnimationClip

type AnimationClip struct {
	Name       string        `json:"name"`
	ClipMode   string        `json:"clip_mode,omitempty"`
	Frames     []string      `json:"frames,omitempty"`
	Events     []AnimEventIO `json:"events"`
	EndedEvent *AnimEventIO  `json:"ended_event,omitempty"`
	FPS        int           `json:"fps"`
}

type AsepriteInput

type AsepriteInput struct {
	Filename  string
	FrameData *File
	ImageData []byte
}

type AtlasImporter

type AtlasImporter struct {
	Frames                []FrameIO `json:"frames"`
	AsepriteSheet         string    `json:"asesprite_sheet"`
	ExportUndefinedFrames bool      `json:"export_undefined_frames"`
}

AtlasImporter is a template used to import an Aseprite JSON (of a sprite sheet) to Primen.

func (AtlasImporter) FrameWithFilename

func (i AtlasImporter) FrameWithFilename(filename string) (frame FrameIO, exists bool)

FrameWithFilename returns the frame with the specified filename.

type AtlasImporterGroup

type AtlasImporterGroup struct {
	Templates   []AtlasImporter `json:"templates"`
	Output      string          `json:"output,omitempty"`
	ImageFilter string          `json:"image_filter,omitempty"`
	MaxWidth    int             `json:"max_width"`
	MaxHeight   int             `json:"max_height"`
	Padding     int             `json:"padding"`
	Animations  []Animation     `json:"animations"`
	Clips       []AnimationClip `json:"clips,omitempty"`
}

AtlasImporterGroup is the root of an import template

type File

type File struct {
	Frames []FrameInfo `json:"frames"`
	Meta   Metadata    `json:"meta"`
}

File represents an Aseprite sprite sheet file

func Parse

func Parse(jsonb []byte) (*File, error)

Parse an Aseprite sheet JSON file. Warning: export frams as ARRAY. Do not use the Map option. JSON maps are not guaranteed to be ordered, and Primen is made in Go, which doesn't preserve the order of a Map. The JSON spec states that relying on key ordered maps is abad idea. https://github.com/golang/go/issues/27179#issuecomment-415525033

func (*File) GetFrameByIndex

func (f *File) GetFrameByIndex(index int) (i FrameInfo, ok bool)

GetFrameByIndex returns the FrameInfo at the index position. It returns false if out of bounds.

func (*File) GetFrameByName

func (f *File) GetFrameByName(name string) (i FrameInfo, ok bool)

GetFrameByName returns the FrameInfo with the specified name.

func (*File) GetMetadata

func (f *File) GetMetadata() Metadata

GetMetadata retrieves Aseprite metadata

func (*File) GetSliceByName

func (f *File) GetSliceByName(name string) (slc Slice, index int)

func (*File) Length

func (f *File) Length() int

Length returns the amount of frames

func (*File) Walk

func (f *File) Walk(fn func(i FrameInfo) bool)

Walk iterates on every FrameInfo. It stops early if fn returns false.

type FrameIO

type FrameIO struct {
	Filename string `json:"filename"`
	Pivot    Vec2   `json:"pivot,omitempty"` //TODO: use
}

FrameIO is the template to import a sprite by the frame itself. This is used when the import strategy is set to Frames, or when it is set to Default and no frame tags or slices are available.

type FrameInfo

type FrameInfo struct {
	Filename         string    `json:"filename"`
	Frame            FrameRect `json:"frame"`
	Rotated          bool      `json:"rotated"`
	Trimmed          bool      `json:"trimmed"`
	SpriteSourceSize FrameRect `json:"spriteSourceSize"`
	SourceSize       ImSize    `json:"sourceSize"`
	Duration         int       `json:"duration"`
}

type FrameRect

type FrameRect struct {
	X int `json:"x"`
	Y int `json:"y"`
	W int `json:"w"`
	H int `json:"h"`
}

FrameRect is the frame bounds

func (FrameRect) String

func (r FrameRect) String() string

func (FrameRect) ToRect

func (r FrameRect) ToRect() image.Rectangle

type FrameTag

type FrameTag struct {
	Name      string        `json:"name"`
	From      int           `json:"from"`
	To        int           `json:"to"`
	Direction AnimDirection `json:"direction"`
}

"name": "lbar1", "from": 0, "to": 11, "direction": "forward"

type ImSize

type ImSize struct {
	W int `json:"w"`
	H int `json:"h"`
}

type ImportInput

type ImportInput struct {
	Template *AtlasImporterGroup
	Source   []AsepriteInput
	PackerI  atlaspacker.PackerInput
}

type Layer

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

type Metadata

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

type Slice

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

type SliceKeyframe

type SliceKeyframe struct {
	Frame  int       `json:"frame"`
	Bounds FrameRect `json:"bounds"`
	Pivot  Vec2      `json:"pivot"`
}

type Vec2

type Vec2 struct {
	X int `json:"x"`
	Y int `json:"y"`
}

Jump to

Keyboard shortcuts

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