fix(editor): strip placement metadata on commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
import { describe, expect, test } from 'bun:test'
|
||||||
|
import { stripTransient } from './placement-math'
|
||||||
|
|
||||||
|
describe('stripTransient', () => {
|
||||||
|
test('removes placement-only metadata flags before commit', () => {
|
||||||
|
expect(stripTransient({ isNew: true, isTransient: true, label: 'copy' })).toEqual({
|
||||||
|
label: 'copy',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -111,13 +111,13 @@ export function isValidWallSideFace(normal: [number, number, number] | undefined
|
|||||||
return Math.abs(normal[2]) > 0.7
|
return Math.abs(normal[2]) > 0.7
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Strip placement-only metadata flags before committing a draft. */
|
||||||
* Strip the `isTransient` flag from node metadata before committing.
|
|
||||||
*/
|
|
||||||
export function stripTransient(meta: any): any {
|
export function stripTransient(meta: any): any {
|
||||||
if (!isObject(meta)) return meta
|
if (!isObject(meta)) return meta
|
||||||
const { isTransient, ...rest } = meta as Record<string, any>
|
const nextMeta = { ...(meta as Record<string, any>) }
|
||||||
return rest
|
delete nextMeta.isNew
|
||||||
|
delete nextMeta.isTransient
|
||||||
|
return nextMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
const _up = new Vector3(0, 1, 0)
|
const _up = new Vector3(0, 1, 0)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
EDITOR_LAYER,
|
EDITOR_LAYER,
|
||||||
getSideFromNormal,
|
getSideFromNormal,
|
||||||
isValidWallSideFace,
|
isValidWallSideFace,
|
||||||
|
stripPlacementMetadataFlags,
|
||||||
triggerSFX,
|
triggerSFX,
|
||||||
useEditor,
|
useEditor,
|
||||||
} from '@pascal-app/editor'
|
} from '@pascal-app/editor'
|
||||||
@@ -275,6 +276,7 @@ const MoveDoorTool: React.FC<{ node: DoorNode }> = ({ node: movingDoorNode }) =>
|
|||||||
|
|
||||||
const cloned = structuredClone(movingDoorNode) as any
|
const cloned = structuredClone(movingDoorNode) as any
|
||||||
delete cloned.id
|
delete cloned.id
|
||||||
|
cloned.metadata = stripPlacementMetadataFlags(cloned.metadata)
|
||||||
const node = DoorNode.parse({
|
const node = DoorNode.parse({
|
||||||
...cloned,
|
...cloned,
|
||||||
position: [target.clampedX, target.clampedY, 0],
|
position: [target.clampedX, target.clampedY, 0],
|
||||||
|
|||||||
Reference in New Issue
Block a user