-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaseprite.ts
More file actions
63 lines (57 loc) · 1.12 KB
/
Copy pathaseprite.ts
File metadata and controls
63 lines (57 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export type AsepriteFrame = {
frame: {
x: number
y: number
w: number
h: number
}
rotated: boolean
trimmed: boolean
spriteSourceSize: {
x: number
y: number
w: number
h: number
}
sourceSize: {
w: number
h: number
}
duration: number
}
export type AsepriteLayer = {
name: string
opacity: number
blendMode: string
}
export type AsepriteFrameTag = {
name: string
from: number
to: number
direction: 'forward' | 'backward'
}
export type AsepriteJson = {
frames: { [name: string]: AsepriteFrame }
meta: {
app: string
version: string
image: string
format: string
size: {
w: number
h: number
}
frameTags: AsepriteFrameTag[]
layers: AsepriteLayer[]
slices: unknown[]
}
}
export function frameList(json: AsepriteJson): AsepriteFrame[] {
return Object.values(json.frames)
}
export function getAnimationFrames(json: AsepriteJson, name: string): AsepriteFrame[] {
const tag = json.meta.frameTags.find((t) => t.name === name)
if (!tag) return []
const allFrames = frameList(json)
return allFrames.slice(tag.from, tag.to)
}