Skip to content

Commit baad812

Browse files
committed
trying to lessen dead code in json export, as well as properly load frequency of some functions.
1 parent 210374c commit baad812

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

animationManager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ export class AnimationManager {
2020
if (!object.animations) {
2121
object.animations = [];
2222
}
23+
// Remove any existing animation for the same property and axis
24+
object.animations = object.animations.filter(anim =>
25+
!(anim.property === animationConfig.property && anim.axis === animationConfig.axis)
26+
);
27+
28+
// Remove from global animations list too
29+
this.animations = this.animations.filter(anim =>
30+
!(anim.object === object && anim.property === animationConfig.property && anim.axis === animationConfig.axis)
31+
);
2332

2433
// Add this animation to the object's animations
2534
object.animations.push(animationConfig);

projectManager.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,30 @@ export class ProjectManager {
232232
Object.keys(anim.functions).forEach(axis => {
233233
const func = anim.functions[axis];
234234
// Find the function name by checking parametricFunctions
235-
let functionName = null;
236-
for (const [name, definition] of Object.entries(parametricFunctions)) {
237-
if (definition.apply === func.apply) {
238-
functionName = name;
239-
break;
235+
let functionName = func.functionName;
236+
237+
// If functionName is not available, try to identify it
238+
if (!functionName) {
239+
for (const [name, definition] of Object.entries(parametricFunctions)) {
240+
if (definition.apply === func.apply) {
241+
functionName = name;
242+
break;
243+
}
240244
}
241245
}
242246

243247
if (functionName) {
248+
// Create a clean copy of parameters to avoid any reference issues
249+
const cleanParams = {};
250+
if (func.params) {
251+
Object.keys(func.params).forEach(paramName => {
252+
cleanParams[paramName] = func.params[paramName];
253+
});
254+
}
255+
244256
serializedAnim.functions[axis] = {
245257
type: functionName,
246-
params: { ...func.params }
258+
params: cleanParams
247259
};
248260
}
249261
});
@@ -269,10 +281,23 @@ export class ProjectManager {
269281
Object.keys(animData.functions).forEach(axis => {
270282
const funcData = animData.functions[axis];
271283
if (funcData.type && parametricFunctions[funcData.type]) {
284+
// Create a fresh copy of parameters to avoid reference issues
285+
const freshParams = {};
286+
287+
// Copy only the parameters that exist in the saved animation
288+
if (funcData.params) {
289+
Object.keys(funcData.params).forEach(paramName => {
290+
freshParams[paramName] = funcData.params[paramName];
291+
});
292+
}
293+
272294
reconstructed.functions[axis] = {
273295
apply: parametricFunctions[funcData.type].apply,
274-
params: { ...funcData.params }
296+
params: freshParams, // Use the fresh copy
297+
functionName: funcData.type
275298
};
299+
} else {
300+
console.error(`Function "${funcData.type}" not found in parametricFunctions`);
276301
}
277302
});
278303
}

0 commit comments

Comments
 (0)