Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated state machine format #75

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ releases/

.output/
.next/
.nuxt/
.nuxt/

apps/node/
196 changes: 194 additions & 2 deletions apps/node/script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,196 @@ import fs from 'fs';

import { DotLottie } from '@dotlottie/dotlottie-js/node';

async function createDotLottieForTests() {
const dotLottie = new DotLottie();

await dotLottie
.setAuthor('Joe')
.setVersion('1.0')
.addAnimation({
id: 'pigeon',
url: 'https://lottie.host/071a2de9-52ca-4ce4-ba2f-a5befd220bdd/ECzVp4eaMa.json',
})
.addStateMachine({
descriptor: {
id: 'exploding_pigeon',
initial: 0,
},
states: [
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
loop: false,
marker: "bird"
},
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
speed: 0.8,
loop: false,
marker: 'explosion',
},
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
speed: 0.8,
loop: false,
marker: 'feathers',
}
],
transitions: [
{
type: "Transition",
from_state: 0,
to_state: 1,
on_complete_event: {},
},
{
type: "Transition",
from_state: 1,
to_state: 2,
on_complete_event: {},
},
{
type: "Transition",
from_state: 2,
to_state: 0,
on_complete_event: {},
},
],
context_variables: [],
listeners: []
})
.addStateMachine({
descriptor: {
id: 'pigeon_without_explosion',
initial: 0,
},
states: [
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
loop: false,
marker: "bird"
},
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
speed: 0.8,
loop: false,
marker: 'feathers',
}
],
transitions: [
{
type: "Transition",
from_state: 0,
to_state: 1,
on_complete_event: {},
},
{
type: "Transition",
from_state: 1,
to_state: 0,
on_complete_event: {},
},
],
context_variables: [],
listeners: []
})
.build()
.then((value) => {
return value.toArrayBuffer();
})
.then((value) => {
fs.writeFileSync('exploding-pigeons-test-file.lottie', Buffer.from(value));
});
}

async function createExplodingPigeon() {
const dotLottie = new DotLottie();

await dotLottie
.setAuthor('Joe')
.setVersion('1.0')
.addAnimation({
id: 'pigeon',
url: 'https://lottie.host/071a2de9-52ca-4ce4-ba2f-a5befd220bdd/ECzVp4eaMa.json',
})
.addStateMachine({
descriptor: {
id: 'exploding_pigeon',
initial: 0,
},
states: [
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
loop: false,
marker: "bird"
},

{
animation_d: "pigeon",
type: "PlaybackState",
autoplay: true,
speed: 0.8,
loop: false,
marker: 'explosion',
},
{
animation_id: "pigeon",
type: "PlaybackState",
autoplay: true,
speed: 0.8,
loop: false,
marker: 'feathers',
}
],
transitions: [
{
type: "Transition",
from_state: 0,
to_state: 1,
on_complete_event: {},
},
{
type: "Transition",
from_state: 1,
to_state: 2,
on_complete_event: {},
},
{
type: "Transition",
from_state: 2,
to_state: 0,
on_complete_event: {},
},
],
listeners: [],
context_variables: [
{
type: "Numeric",
key: "counter_6",
value: 6
}
]
})
.build()
.then((value) => {
return value.toArrayBuffer();
})
.then((value) => {
fs.writeFileSync('exploding_pigeon.zip', Buffer.from(value));
});
}

async function createDotLottie() {
const dotLottie = new DotLottie();

Expand All @@ -21,7 +211,7 @@ async function createDotLottie() {
url: 'https://lottie.host/cf7b43d1-3d6b-407a-970b-6305b18bebfa/uB1Jboo1o1.json',
autoplay: true,
})
.addState({
.addStateMachine({
id: 'state_1',
state: {
descriptor: {
Expand Down Expand Up @@ -52,4 +242,6 @@ async function createDotLottie() {
});
}

createDotLottie();
// createDotLottie();
// createExplodingPigeon();
createDotLottieForTests();
5 changes: 5 additions & 0 deletions packages/dotlottie-js/src/common/dotlottie-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright 2023 Design Barn Inc.
*/

/* eslint-disable @typescript-eslint/naming-convention */

import type { Animation as AnimationType } from '@lottiefiles/lottie-types';
import type { ZipOptions } from 'fflate';

Expand Down Expand Up @@ -611,6 +613,9 @@ export class DotLottieCommon {
const stateOption = {
states: stateMachine.states,
descriptor: { id: stateMachine.id, initial: stateMachine.initial },
transitions: stateMachine.transitions,
listeners: stateMachine.listeners,
context_variables: stateMachine.contextVariables,
zipOptions: stateMachine.zipOptions,
};

Expand Down
Loading
Loading