Skip to content

Commit

Permalink
update model animation (goplus#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Jun 28, 2024
1 parent b349b7c commit 79140cd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions spx-gui/src/models/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const defaultFps = 25 // TODO

export type AnimationInits = {
duration?: number
anitype?: number
onStart?: ActionConfig

// not supported by builder:
Expand All @@ -37,6 +36,7 @@ export type AnimationInits = {
}

export type RawAnimationConfig = AnimationInits & {
anitype?: number
from?: number | string
to?: number | string
}
Expand Down Expand Up @@ -80,11 +80,24 @@ export class Animation {
costume.setParent(this)
}
this.costumes = costumes
if (this.duration == null) {
if (this.duration === 0) {
this.duration = costumes.length / defaultFps
}
}

/**
* Ungroup costumes, which will be added back to sprite.
* Typically called before the animation removed from the sprite.
*/
ungroup() {
if (this.sprite == null) throw new Error('sprite expected')
const costumes = this.costumes
this.setCostumes([])
for (const costume of costumes) {
this.sprite.addCostume(costume)
}
}

duration: number
setDuration(duration: number) {
this.duration = duration
Expand Down Expand Up @@ -112,7 +125,7 @@ export class Animation {
* Create instance with default inits
* Note that the "default" means default behavior for builder, not the default behavior of spx
*/
static async create(
static create(
nameBase: string,
sprite: Sprite,
costumes: Costume[],
Expand Down

0 comments on commit 79140cd

Please sign in to comment.