Skip to content

Commit

Permalink
fix: dilate static-value checker (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidosmf authored Jul 12, 2024
1 parent c53e35c commit 8c19bf1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-moose-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/relottie-extract-features': patch
---

fix: dilate is disabled and not used if its static-value is 0
Original file line number Diff line number Diff line change
Expand Up @@ -892,14 +892,14 @@ exports[`relottie-extract-features fixtures features Test in karting.json should
"y": 1,
},
"dilate" => {
"n": 0,
"n": 1,
"parents": Map {
"mask" => {
"n": 0,
"y": 1,
"n": 1,
"y": 0,
},
},
"y": 1,
"y": 0,
},
"shape-list" => {
"n": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,14 +1052,14 @@ exports[`relottie-extract-features fixtures features Test in slots-img.json shou
"y": 6,
},
"dilate" => {
"n": 0,
"n": 6,
"parents": Map {
"mask" => {
"n": 0,
"y": 6,
"n": 6,
"y": 0,
},
},
"y": 6,
"y": 0,
},
"start-time" => {
"n": 0,
Expand Down
24 changes: 23 additions & 1 deletion packages/relottie-extract-features/src/used-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
Root,
} from '@lottiefiles/last';

const { intBoolean: IBT, number: NT } = TITLES;
const { element: ET, intBoolean: IBT, number: NT, object: OT } = TITLES;

export type NodeWithTitle = Root | ArrayNode | ObjectNode | Attribute | Element | Collection;

Expand Down Expand Up @@ -116,6 +116,27 @@ export const timeStretchChecker: IsFeatureUsedChecker<Attribute> = (node): boole
}
};

/**
* If dilate's (aka Mask Expansion) non-animated static-value is set to 0 then it's disabled and not used.
*/
export const dilateChecker: IsFeatureUsedChecker<Element> = (node): boolean => {
const valueNode = node.children[0];

if (!valueNode) return false;

if (valueNode.title !== OT.animatedValueStatic) return objectNodeChecker(valueNode);

const staticValueNode = valueNode.children.find((child) => child.title === NT.staticValue);

const targetNode = staticValueNode?.children[0];

if (targetNode?.type !== 'primitive') return false;

if (targetNode.value === 0) return false;

return true;
};

export const FEATURE_CHECKERS = new Map<
AnyTitle,
| IsFeatureUsedChecker<Attribute>
Expand All @@ -136,6 +157,7 @@ export const FEATURE_CHECKERS = new Map<
[IBT.randomize, intBooleanNodeChecker],
[IBT.matteTarget, intBooleanNodeChecker],
[NT.timeStretch, timeStretchChecker],
[ET.dilate, dilateChecker],
]);

export const isFeatureUsed = (feature: AnyTitle, node: NodeWithTitle): boolean => {
Expand Down

0 comments on commit 8c19bf1

Please sign in to comment.