Skip to content

Commit

Permalink
Clean upp
Browse files Browse the repository at this point in the history
  • Loading branch information
pierremtb committed Feb 14, 2025
1 parent cc1667e commit cb2ecd9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
12 changes: 7 additions & 5 deletions src/lib/commandBarConfigs/modelingCommandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
45 changes: 11 additions & 34 deletions src/lib/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,82 +199,64 @@ 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],
operation.labeledArgs.revolutions.sourceRange[1]
),
{}
)

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],
operation.labeledArgs.angleStart.sourceRange[1]
),
{}
)

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],
operation.labeledArgs.counterClockWise.sourceRange[1]
) === '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],
operation.labeledArgs.radius.sourceRange[1]
),
{}
)

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],
Expand All @@ -283,21 +265,16 @@ 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],
operation.labeledArgs.length.sourceRange[1]
),
{}
)

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
Expand Down

0 comments on commit cb2ecd9

Please sign in to comment.