fix: persist instance override mutations
This commit is contained in:
parent
c6e3baa68c
commit
cd2809a6e7
|
|
@ -453,7 +453,7 @@ function applyInstanceOverrides(
|
|||
}
|
||||
walk(instance.id)
|
||||
|
||||
const overrides = new Map<string, unknown>()
|
||||
let mutated = false
|
||||
for (const [key, value] of entries) {
|
||||
const sep = key.indexOf(':')
|
||||
if (sep === -1) continue
|
||||
|
|
@ -463,8 +463,9 @@ function applyInstanceOverrides(
|
|||
if (!child || !(prop in child)) continue
|
||||
graph.updateNode(child.id, { [prop]: value } as Partial<SceneNode>)
|
||||
setInstanceOverride(instance.instanceOverrides, instance.id, child.id, prop, value)
|
||||
mutated = true
|
||||
}
|
||||
if (overrides.size > 0) {
|
||||
if (mutated) {
|
||||
graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { cloneInstanceOverrideState } from '@open-pencil/scene-graph'
|
||||
import type { SceneNode, Vector } from '@open-pencil/scene-graph'
|
||||
import { getAxisAlignedWorldBounds, getWorldMatrix } from '@open-pencil/scene-graph/coordinate'
|
||||
import Matrix from '@open-pencil/scene-graph/matrix'
|
||||
|
|
@ -97,6 +98,7 @@ export function createComponentInstanceActions(ctx: EditorContext) {
|
|||
if (selectedNode?.type !== 'INSTANCE') return
|
||||
|
||||
const prevComponentId = selectedNode.componentId
|
||||
const previousOverrides = cloneInstanceOverrideState(selectedNode.instanceOverrides)
|
||||
|
||||
ctx.graph.detachInstance(selectedNode.id)
|
||||
ctx.setSelectedIds(new Set([selectedNode.id]))
|
||||
|
|
@ -111,10 +113,7 @@ export function createComponentInstanceActions(ctx: EditorContext) {
|
|||
ctx.graph.updateNode(selectedNode.id, {
|
||||
type: 'INSTANCE',
|
||||
componentId: prevComponentId,
|
||||
instanceOverrides: {
|
||||
self: new Map(),
|
||||
descendants: new Map()
|
||||
}
|
||||
instanceOverrides: cloneInstanceOverrideState(previousOverrides)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue