fix: clear collections in setScene and apply cloned collections in test button
- setScene now clears collections to avoid stale references - Test clone button applies cloned collections after setScene Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
parent
de9eb6fa78
commit
a87fe56d53
@@ -136,6 +136,7 @@ const useScene: UseSceneStore = create<SceneState>()(
|
|||||||
nodes: patchedNodes,
|
nodes: patchedNodes,
|
||||||
rootNodeIds,
|
rootNodeIds,
|
||||||
dirtyNodes: new Set<AnyNodeId>(),
|
dirtyNodes: new Set<AnyNodeId>(),
|
||||||
|
collections: {},
|
||||||
})
|
})
|
||||||
// Mark all nodes as dirty to trigger re-validation
|
// Mark all nodes as dirty to trigger re-validation
|
||||||
Object.values(patchedNodes).forEach((node) => {
|
Object.values(patchedNodes).forEach((node) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { emitter, useScene } from '@pascal-app/core'
|
import { cloneSceneGraph, emitter, useScene } from '@pascal-app/core'
|
||||||
import { useViewer } from '@pascal-app/viewer'
|
import { useViewer } from '@pascal-app/viewer'
|
||||||
import { TreeView, VisualJson } from '@visual-json/react'
|
import { TreeView, VisualJson } from '@visual-json/react'
|
||||||
import { Camera, Download, Save, Trash2, Upload } from 'lucide-react'
|
import { Camera, Copy, Download, Save, Trash2, Upload } from 'lucide-react'
|
||||||
import {
|
import {
|
||||||
type KeyboardEvent,
|
type KeyboardEvent,
|
||||||
type SyntheticEvent,
|
type SyntheticEvent,
|
||||||
@@ -250,6 +250,29 @@ export function SettingsPanel({
|
|||||||
setPhase('site')
|
setPhase('site')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleTestClone = () => {
|
||||||
|
const collections = useScene.getState().collections
|
||||||
|
const sceneGraph = { nodes, rootNodeIds, ...(collections && { collections }) }
|
||||||
|
const cloned = cloneSceneGraph(sceneGraph)
|
||||||
|
|
||||||
|
// Show before/after comparison
|
||||||
|
const oldIds = Object.keys(nodes).slice(0, 5)
|
||||||
|
const newIds = Object.keys(cloned.nodes).slice(0, 5)
|
||||||
|
const comparison = oldIds.map((oldId, i) => `${oldId} → ${newIds[i]}`).join('\n')
|
||||||
|
|
||||||
|
// Apply cloned scene (setScene clears collections, so apply them after)
|
||||||
|
setScene(cloned.nodes, cloned.rootNodeIds)
|
||||||
|
if (cloned.collections) {
|
||||||
|
useScene.setState({ collections: cloned.collections })
|
||||||
|
}
|
||||||
|
resetSelection()
|
||||||
|
setPhase('site')
|
||||||
|
|
||||||
|
alert(
|
||||||
|
`Scene cloned successfully!\n\nNode count: ${Object.keys(nodes).length} → ${Object.keys(cloned.nodes).length}\n\nSample ID mapping:\n${comparison}\n\nCheck the Scene Graph explorer to verify new IDs.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const handleGenerateThumbnail = () => {
|
const handleGenerateThumbnail = () => {
|
||||||
if (!projectId) return
|
if (!projectId) return
|
||||||
setIsGeneratingThumbnail(true)
|
setIsGeneratingThumbnail(true)
|
||||||
@@ -358,6 +381,11 @@ export function SettingsPanel({
|
|||||||
Load Build
|
Load Build
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button className="w-full justify-start gap-2" onClick={handleTestClone} variant="outline">
|
||||||
|
<Copy className="size-4" />
|
||||||
|
Test Clone Scene
|
||||||
|
</Button>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
accept="application/json"
|
accept="application/json"
|
||||||
className="hidden"
|
className="hidden"
|
||||||
|
|||||||
Reference in New Issue
Block a user