Skip to content

Commit

Permalink
feat: parallel animation
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Aug 14, 2024
1 parent d50ad10 commit f056329
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/json/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface WidgetFormat {
arguments: unknown[]
options: WidgetOptions
children: WidgetFormat[]
animations: AnimFormat[]
animations: AnimFormat[] | AnimFormat[][]
actions: ActionFormat[]
}

Expand Down
19 changes: 15 additions & 4 deletions packages/json/src/import-widget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Widget, WidgetOptions } from '@newcar/core'
import { parallel } from '@newcar/core'
import { Color, Shader, isString } from '@newcar/utils'
import type { WidgetFormat } from './format'
import type { AnimFormat, WidgetFormat } from './format'
import { processAction } from './process-action'
import { processResource } from './process-resource'

Expand Down Expand Up @@ -87,9 +88,19 @@ export function importWidget<T extends typeof Widget>(
}
if (widgetData.animations) {
widgetData.animations.forEach((animation) => {
widget.animate(anims[animation.type]().withAttr({
...processOptions(animation.parameters),
by: easingFunctions[animation.parameters.by as string],
if (Array.isArray(animation)) {
widget.animate(
parallel(...animation.map((ani) => {
return anims[ani.type]().withAttr({
...processOptions(ani.parameters),
by: easingFunctions[ani.parameters.by as string],
})
})),
)
}
widget.animate(anims[(animation as AnimFormat).type]().withAttr({
...processOptions((animation as AnimFormat).parameters),
by: easingFunctions[(animation as AnimFormat).parameters.by as string],
}))
})
}
Expand Down

0 comments on commit f056329

Please sign in to comment.