From cb2ecd9f7053ac307ccf04d8b08fc0d994c68f97 Mon Sep 17 00:00:00 2001 From: Pierre Jacquier Date: Fri, 14 Feb 2025 17:34:25 -0500 Subject: [PATCH] Clean upp --- .../modelingCommandConfig.ts | 12 ++--- src/lib/operations.ts | 45 +++++-------------- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index dc6be1158f..4573094d07 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -486,9 +486,10 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< counterClockWise: { inputType: 'options', required: true, + defaultValue: false, options: [ - { name: 'True', isCurrent: false, value: true }, - { name: 'False', isCurrent: true, value: false }, + { name: 'True', value: true }, + { name: 'False', value: false }, ], }, radius: { @@ -499,10 +500,11 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< axis: { inputType: 'options', required: true, + defaultValue: 'X', options: [ - { name: 'X Axis', isCurrent: true, value: 'X' }, - { name: 'Y Axis', isCurrent: false, value: 'Y' }, - { name: 'Z Axis', isCurrent: false, value: 'Z' }, + { name: 'X Axis', value: 'X' }, + { name: 'Y Axis', value: 'Y' }, + { name: 'Z Axis', value: 'Z' }, ], }, length: { diff --git a/src/lib/operations.ts b/src/lib/operations.ts index 9080c07335..5a3e023aa9 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -199,14 +199,13 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { return baseCommand } + // TODO: find a way to loop over the arguments while keeping it safe // revolutions kcl arg if ( !('revolutions' in operation.labeledArgs) || !operation.labeledArgs.revolutions - ) { + ) return baseCommand - } - const revolutions = await stringToKclExpression( codeManager.code.slice( operation.labeledArgs.revolutions.sourceRange[0], @@ -214,19 +213,14 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { ), {} ) - - if (err(revolutions) || 'errors' in revolutions) { - return baseCommand - } + if (err(revolutions) || 'errors' in revolutions) return baseCommand // angleStart kcl arg if ( !('angleStart' in operation.labeledArgs) || !operation.labeledArgs.angleStart - ) { + ) return baseCommand - } - const angleStart = await stringToKclExpression( codeManager.code.slice( operation.labeledArgs.angleStart.sourceRange[0], @@ -234,19 +228,14 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { ), {} ) - - if (err(angleStart) || 'errors' in angleStart) { - return baseCommand - } + if (err(angleStart) || 'errors' in angleStart) return baseCommand // counterClockWise options boolean arg if ( !('counterClockWise' in operation.labeledArgs) || !operation.labeledArgs.counterClockWise - ) { + ) return baseCommand - } - const counterClockWise = codeManager.code.slice( operation.labeledArgs.counterClockWise.sourceRange[0], @@ -254,10 +243,8 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { ) === 'true' // radius kcl arg - if (!('radius' in operation.labeledArgs) || !operation.labeledArgs.radius) { + if (!('radius' in operation.labeledArgs) || !operation.labeledArgs.radius) return baseCommand - } - const radius = await stringToKclExpression( codeManager.code.slice( operation.labeledArgs.radius.sourceRange[0], @@ -265,16 +252,11 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { ), {} ) - - if (err(radius) || 'errors' in radius) { - return baseCommand - } + if (err(radius) || 'errors' in radius) return baseCommand // axis options string arg - if (!('axis' in operation.labeledArgs) || !operation.labeledArgs.axis) { + if (!('axis' in operation.labeledArgs) || !operation.labeledArgs.axis) return baseCommand - } - const axis = codeManager.code .slice( operation.labeledArgs.axis.sourceRange[0], @@ -283,10 +265,8 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { .replaceAll("'", '') // TODO: fix this crap // length kcl arg - if (!('length' in operation.labeledArgs) || !operation.labeledArgs.length) { + if (!('length' in operation.labeledArgs) || !operation.labeledArgs.length) return baseCommand - } - const length = await stringToKclExpression( codeManager.code.slice( operation.labeledArgs.length.sourceRange[0], @@ -294,10 +274,7 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => { ), {} ) - - if (err(length) || 'errors' in length) { - return baseCommand - } + if (err(length) || 'errors' in length) return baseCommand // Assemble the default argument values for the Offset Plane command, // with `nodeToEdit` set, which will let the Offset Plane actor know