From 18ccb090e14d42c738568bcb5b0143527a8bc697 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Sun, 12 Nov 2023 09:53:20 -0800 Subject: [PATCH] Fix constraints parameter parsing out of save files (#142) --- src/document/ConstraintStore.tsx | 3 +++ src/document/HolonomicPathStore.ts | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/document/ConstraintStore.tsx b/src/document/ConstraintStore.tsx index a16ff83c7a..d06dc0720d 100644 --- a/src/document/ConstraintStore.tsx +++ b/src/document/ConstraintStore.tsx @@ -319,6 +319,9 @@ const defineConstraintStore = ( .actions((self) => { let x: ModelActions = {}; Object.keys(definition.properties).forEach((key) => { + if (key.length == 0) { + return; + } let upperCaseName = key[0].toUpperCase() + key.slice(1); x[`set${upperCaseName}`] = (arg0: number) => { self[key] = arg0; diff --git a/src/document/HolonomicPathStore.ts b/src/document/HolonomicPathStore.ts index c63ad97638..f845004250 100644 --- a/src/document/HolonomicPathStore.ts +++ b/src/document/HolonomicPathStore.ts @@ -293,10 +293,24 @@ export const HolonomicPathStore = types return { uuid: self.waypoints[savedId].uuid as string }; } }; - self.addConstraint( + let constraint = self.addConstraint( constraintStore, saved.scope.map((id) => savedWaypointIdToWaypointId(id)) ); + + Object.keys(constraint?.definition.properties ?? {}).forEach( + (key) => { + if ( + Object.hasOwn(saved, key) && + typeof saved[key] === "number" && + key.length >= 1 + ) { + let upperCaseName = key[0].toUpperCase() + key.slice(1); + //@ts-ignore + constraint[`set${upperCaseName}`](saved[key]); + } + } + ); } }); self.generated.clear();