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(2d): add save and restore methods to nodes #406

Merged
merged 2 commits into from Feb 24, 2023

Conversation

ksassnowski
Copy link
Contributor

Description

This PR introduces two new methods save and restore to the base Node class. These methods allow us to save a snapshot of a node's current state, so that we can then later revert the node to this state.

As part of implementing the save/restore feature, I have also extracted more general getState() and applyState() methods.

  • getState() returns a snapshot of the node's current state. The implementation is almost identical to how snapshotClone works, however, it does not include snapshots of the node's children.
  • applyState take a map of signal values and applies them to the current node. If the signal does not exist on the node, it gets ignore.

This also fixes an issue inside deepLerp so it deals with booleans properly.

Closes #403

Copy link
Contributor

@aarthificial aarthificial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also clear the stack in the dispose method just to be safe.

packages/docs/docs/getting-started/tweening.mdx Outdated Show resolved Hide resolved
@aarthificial aarthificial merged commit 870e194 into motion-canvas:main Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving and restoring node states
2 participants