Refactor writeToFile and updateCodeEditor to happen at appropriate times

This commit is contained in:
49lf
2024-11-13 01:09:17 -05:00
parent a4b7dd5182
commit 6c2d06c2c6
6 changed files with 106 additions and 63 deletions

View File

@ -18,6 +18,7 @@ import {
sceneEntitiesManager,
engineCommandManager,
editorManager,
codeManager,
} from 'lib/singletons'
import {
horzVertInfo,
@ -512,6 +513,13 @@ export const modelingMachine = setup({
},
// end guards
actions: {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
'update code editor and write to file': async () => {
const newCode = recast(kclManager.ast)
if (err(newCode)) return
await codeManager.updateCodeEditor(newCode)
await codeManager.writeToFile()
},
'assign tool in context': assign({
currentTool: ({ event }) =>
'data' in event && event.data && 'tool' in event.data
@ -599,7 +607,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,
@ -608,11 +615,11 @@ export const modelingMachine = setup({
type: 'path',
},
})
if (!engineCommandManager.engineConnection?.idleMode) {
store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e)
})
}
const newCode = recast(updatedAst.newAst)
if (err(newCode)) return
await codeManager.updateCodeEditor(newCode)
if (updatedAst?.selections) {
editorManager.selectRange(updatedAst?.selections)
}
@ -646,7 +653,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,
@ -655,11 +661,11 @@ export const modelingMachine = setup({
type: 'path',
},
})
if (!engineCommandManager.engineConnection?.idleMode) {
store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e)
})
}
const newCode = recast(updatedAst.newAst)
if (err(newCode)) return
await codeManager.updateCodeEditor(newCode)
if (updatedAst?.selections) {
editorManager.selectRange(updatedAst?.selections)
}
@ -689,6 +695,10 @@ export const modelingMachine = setup({
}
await kclManager.updateAst(modifiedAst, true)
const newCode = recast(modifiedAst)
if (err(newCode)) return
await codeManager.updateCodeEditor(newCode)
})().catch(reportRejection)
},
'AST fillet': ({ event }) => {
@ -1560,7 +1570,10 @@ export const modelingMachine = setup({
},
},
entry: 'setup client side sketch segments',
entry: [
'setup client side sketch segments',
'update code editor and write to file',
],
},
'Await horizontal distance info': {