feat: multiple scenes
This commit is contained in:
@@ -12,11 +12,16 @@ import {
|
||||
getLogosContent,
|
||||
setLogosContent,
|
||||
upsertRenderOutputEntry,
|
||||
getFluxSceneTree,
|
||||
setFluxSceneTree,
|
||||
getSceneGraph,
|
||||
setSceneGraph,
|
||||
RECOLLECTION_FILE_EXT,
|
||||
RECOLLECTION_VERSION,
|
||||
type StoredGraphState,
|
||||
type StoredLogosContent,
|
||||
type RenderOutputCacheEntry,
|
||||
type FluxSceneMeta,
|
||||
} from '../state/recollectionStore'
|
||||
|
||||
export type { RenderOutputCacheEntry }
|
||||
@@ -31,6 +36,8 @@ export type RecollectionFilePayload = {
|
||||
version?: number
|
||||
graph?: { nodes: unknown[]; edges: unknown[] }
|
||||
logos?: StoredLogosContent
|
||||
/** Flux scenes (Phase 2+). Each entry has scene metadata + graph. */
|
||||
scenes?: Array<{ id: string; title: string; position: number; graph: { nodes: unknown[]; edges: unknown[] } }>
|
||||
}
|
||||
|
||||
export type FluxSlot = {
|
||||
@@ -104,6 +111,26 @@ function validateAndWritePayload(
|
||||
result.logos = payload.logos as StoredLogosContent
|
||||
}
|
||||
}
|
||||
// Import scenes
|
||||
if (payload.scenes && Array.isArray(payload.scenes)) {
|
||||
const sceneMetas: FluxSceneMeta[] = []
|
||||
for (const s of payload.scenes) {
|
||||
if (!s || typeof s.id !== 'string' || typeof s.title !== 'string') continue
|
||||
sceneMetas.push({ id: s.id, title: s.title, position: s.position ?? 0 })
|
||||
if (s.graph && Array.isArray(s.graph.nodes) && Array.isArray(s.graph.edges)) {
|
||||
const nodes = s.graph.nodes as AppNode[]
|
||||
const edges = backfillEdges(nodes, s.graph.edges as AppEdge[])
|
||||
setSceneGraph(recollectionId, s.id, {
|
||||
version: payload.version ?? RECOLLECTION_VERSION,
|
||||
nodes,
|
||||
edges,
|
||||
})
|
||||
}
|
||||
}
|
||||
if (sceneMetas.length > 0) {
|
||||
setFluxSceneTree(recollectionId, sceneMetas)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -151,10 +178,17 @@ export function RecollectionActionsProvider({ children }: { children: React.Reac
|
||||
if (!recollectionId) return
|
||||
const graph = getGraph(recollectionId)
|
||||
const logosContent = getLogosContent(recollectionId)
|
||||
// Export scenes
|
||||
const sceneTree = getFluxSceneTree(recollectionId)
|
||||
const scenes = sceneTree.map((s) => {
|
||||
const sg = getSceneGraph(recollectionId, s.id)
|
||||
return { ...s, graph: sg ? { nodes: sg.nodes, edges: sg.edges } : { nodes: [], edges: [] } }
|
||||
})
|
||||
const payload: RecollectionFilePayload = {
|
||||
version: RECOLLECTION_VERSION,
|
||||
...(graph && { graph: { nodes: graph.nodes, edges: graph.edges } }),
|
||||
...(logosContent && { logos: logosContent }),
|
||||
...(scenes.length > 0 && { scenes }),
|
||||
}
|
||||
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
|
||||
Reference in New Issue
Block a user