Do not write to file or update code editor a ridiculous amount of times and update them both at the most appropriate moments. (#4479)
* Reapply "Deflake project settings override on desktop (#4370)" (#4450)
This reverts commit b11040c23c
.
* Refactor writeToFile and updateCodeEditor to happen at appropriate times
* Turn error into warning about out of date AST.
* Rename setUp to setup
* ONLY reload current file on changes.
* If value is falsey then don't try to executeAst
* Fix up code based selections after constraints
* Correct any last missing code mods
* Update src/clientSideScene/ClientSideSceneComp.tsx
Remove eslint rule no-floating-promises
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
* Fixups
* Fix FileTree failing
---------
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
This commit is contained in:
@ -18,6 +18,7 @@ import {
|
||||
sceneEntitiesManager,
|
||||
engineCommandManager,
|
||||
editorManager,
|
||||
codeManager,
|
||||
} from 'lib/singletons'
|
||||
import {
|
||||
horzVertInfo,
|
||||
@ -531,8 +532,10 @@ export const modelingMachine = setup({
|
||||
}
|
||||
}
|
||||
),
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
'hide default planes': () => kclManager.hidePlanes(),
|
||||
'hide default planes': () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
kclManager.hidePlanes()
|
||||
},
|
||||
'reset sketch metadata': assign({
|
||||
sketchDetails: null,
|
||||
sketchEnginePathId: '',
|
||||
@ -595,7 +598,6 @@ export const modelingMachine = setup({
|
||||
if (trap(extrudeSketchRes)) return
|
||||
const { modifiedAst, pathToExtrudeArg } = extrudeSketchRes
|
||||
|
||||
store.videoElement?.pause()
|
||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||
focusPath: [pathToExtrudeArg],
|
||||
zoomToFit: true,
|
||||
@ -604,11 +606,9 @@ export const modelingMachine = setup({
|
||||
type: 'path',
|
||||
},
|
||||
})
|
||||
if (!engineCommandManager.engineConnection?.idleMode) {
|
||||
store.videoElement?.play().catch((e) => {
|
||||
console.warn('Video playing was prevented', e)
|
||||
})
|
||||
}
|
||||
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
|
||||
if (updatedAst?.selections) {
|
||||
editorManager.selectRange(updatedAst?.selections)
|
||||
}
|
||||
@ -642,7 +642,6 @@ export const modelingMachine = setup({
|
||||
if (trap(revolveSketchRes)) return
|
||||
const { modifiedAst, pathToRevolveArg } = revolveSketchRes
|
||||
|
||||
store.videoElement?.pause()
|
||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||
focusPath: [pathToRevolveArg],
|
||||
zoomToFit: true,
|
||||
@ -651,11 +650,9 @@ export const modelingMachine = setup({
|
||||
type: 'path',
|
||||
},
|
||||
})
|
||||
if (!engineCommandManager.engineConnection?.idleMode) {
|
||||
store.videoElement?.play().catch((e) => {
|
||||
console.warn('Video playing was prevented', e)
|
||||
})
|
||||
}
|
||||
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
|
||||
if (updatedAst?.selections) {
|
||||
editorManager.selectRange(updatedAst?.selections)
|
||||
}
|
||||
@ -685,6 +682,7 @@ export const modelingMachine = setup({
|
||||
}
|
||||
|
||||
await kclManager.updateAst(modifiedAst, true)
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(modifiedAst)
|
||||
})().catch(reportRejection)
|
||||
},
|
||||
'AST fillet': ({ event }) => {
|
||||
@ -702,6 +700,9 @@ export const modelingMachine = setup({
|
||||
radius
|
||||
)
|
||||
if (err(applyFilletToSelectionResult)) return applyFilletToSelectionResult
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
},
|
||||
'set selection filter to curves only': () => {
|
||||
;(async () => {
|
||||
@ -758,25 +759,35 @@ export const modelingMachine = setup({
|
||||
'remove sketch grid': () => sceneEntitiesManager.removeSketchGrid(),
|
||||
'set up draft line': ({ context: { sketchDetails } }) => {
|
||||
if (!sketchDetails) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.setUpDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'line'
|
||||
)
|
||||
sceneEntitiesManager
|
||||
.setupDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'line'
|
||||
)
|
||||
.then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'set up draft arc': ({ context: { sketchDetails } }) => {
|
||||
if (!sketchDetails) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.setUpDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'tangentialArcTo'
|
||||
)
|
||||
sceneEntitiesManager
|
||||
.setupDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'tangentialArcTo'
|
||||
)
|
||||
.then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'listen for rectangle origin': ({ context: { sketchDetails } }) => {
|
||||
if (!sketchDetails) return
|
||||
@ -834,38 +845,53 @@ export const modelingMachine = setup({
|
||||
'set up draft rectangle': ({ context: { sketchDetails }, event }) => {
|
||||
if (event.type !== 'Add rectangle origin') return
|
||||
if (!sketchDetails || !event.data) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.setupDraftRectangle(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
event.data
|
||||
)
|
||||
sceneEntitiesManager
|
||||
.setupDraftRectangle(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
event.data
|
||||
)
|
||||
.then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'set up draft circle': ({ context: { sketchDetails }, event }) => {
|
||||
if (event.type !== 'Add circle origin') return
|
||||
if (!sketchDetails || !event.data) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.setupDraftCircle(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
event.data
|
||||
)
|
||||
sceneEntitiesManager
|
||||
.setupDraftCircle(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
event.data
|
||||
)
|
||||
.then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'set up draft line without teardown': ({ context: { sketchDetails } }) => {
|
||||
if (!sketchDetails) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.setUpDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'line',
|
||||
false
|
||||
)
|
||||
sceneEntitiesManager
|
||||
.setupDraftSegment(
|
||||
sketchDetails.sketchPathToNode,
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin,
|
||||
'line',
|
||||
false
|
||||
)
|
||||
.then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'show default planes': () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
@ -882,12 +908,17 @@ export const modelingMachine = setup({
|
||||
'add axis n grid': ({ context: { sketchDetails } }) => {
|
||||
if (!sketchDetails) return
|
||||
if (localStorage.getItem('disableAxis')) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sceneEntitiesManager.createSketchAxis(
|
||||
sketchDetails.sketchPathToNode || [],
|
||||
sketchDetails.zAxis,
|
||||
sketchDetails.yAxis,
|
||||
sketchDetails.origin
|
||||
)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
},
|
||||
'reset client scene mouse handlers': () => {
|
||||
// when not in sketch mode we don't need any mouse listeners
|
||||
@ -916,10 +947,13 @@ export const modelingMachine = setup({
|
||||
'Delete segment': ({ context: { sketchDetails }, event }) => {
|
||||
if (event.type !== 'Delete segment') return
|
||||
if (!sketchDetails || !event.data) return
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
deleteSegment({
|
||||
pathToNode: event.data,
|
||||
sketchDetails,
|
||||
}).then(() => {
|
||||
return codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
|
||||
})
|
||||
},
|
||||
'Reset Segment Overlays': () => sceneEntitiesManager.resetOverlays(),
|
||||
@ -984,6 +1018,9 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
|
||||
return {
|
||||
selectionType: 'completeSelection',
|
||||
selection: updateSelections(
|
||||
@ -1018,6 +1055,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
return {
|
||||
selectionType: 'completeSelection',
|
||||
selection: updateSelections(
|
||||
@ -1052,6 +1090,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
return {
|
||||
selectionType: 'completeSelection',
|
||||
selection: updateSelections(
|
||||
@ -1084,6 +1123,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1117,6 +1157,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1150,6 +1191,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1183,6 +1225,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1220,6 +1263,8 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1252,6 +1297,7 @@ export const modelingMachine = setup({
|
||||
)
|
||||
if (trap(updatedAst, { suppress: true })) return
|
||||
if (!updatedAst) return
|
||||
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
|
||||
const updatedSelectionRanges = updateSelections(
|
||||
pathToNodeMap,
|
||||
selectionRanges,
|
||||
@ -1556,7 +1602,7 @@ export const modelingMachine = setup({
|
||||
},
|
||||
},
|
||||
|
||||
entry: 'setup client side sketch segments',
|
||||
entry: ['setup client side sketch segments'],
|
||||
},
|
||||
|
||||
'Await horizontal distance info': {
|
||||
@ -1801,7 +1847,7 @@ export const modelingMachine = setup({
|
||||
onError: 'SketchIdle',
|
||||
onDone: {
|
||||
target: 'SketchIdle',
|
||||
actions: ['Set selection'],
|
||||
actions: 'Set selection',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user