Skip to content

Commit 5a6de3b

Browse files
switch scene
1 parent 89a768d commit 5a6de3b

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

editor/grida-canvas/editor.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,24 +2338,38 @@ export class Editor
23382338

23392339
const syncDocument = (
23402340
surface: Scene,
2341-
document: grida.program.document.Document
2341+
document: grida.program.document.Document,
2342+
sceneId?: string
23422343
) => {
2344+
const payloadDocument: grida.program.document.Document =
2345+
sceneId && document.entry_scene_id !== sceneId
2346+
? {
2347+
...document,
2348+
entry_scene_id: sceneId,
2349+
}
2350+
: document;
2351+
23432352
const p = JSON.stringify({
23442353
version: "0.0.1-beta.1+20250728",
2345-
document,
2354+
document: payloadDocument,
23462355
});
23472356
surface.loadScene(p);
23482357
surface.redraw();
23492358
};
23502359

23512360
// setup hooks
23522361
// - state.document
2362+
// - state.scene_id
23532363
// - state.debug
23542364
// - state.transform
23552365
// - [state.hovered_node_id, state.selection]
23562366

23572367
// once
2358-
syncDocument(this._m_wasm_canvas_scene!, this.doc.state.document);
2368+
syncDocument(
2369+
this._m_wasm_canvas_scene!,
2370+
this.doc.state.document,
2371+
this.doc.state.scene_id
2372+
);
23592373
syncTransform(
23602374
this._m_wasm_canvas_scene!,
23612375
this.doc.state.transform,
@@ -2396,14 +2410,28 @@ export class Editor
23962410
]);
23972411

23982412
if (!result || result.some((report) => !report.success)) {
2399-
syncDocument(this._m_wasm_canvas_scene, document);
2413+
syncDocument(
2414+
this._m_wasm_canvas_scene,
2415+
document,
2416+
this.doc.state.scene_id
2417+
);
24002418
this.log("falling back to direct sync", result);
24012419
} else {
24022420
this._m_wasm_canvas_scene.redraw();
24032421
}
24042422
}
24052423
);
24062424

2425+
this.doc.subscribeWithSelector(
2426+
(state) => state.scene_id,
2427+
(_, scene_id) => {
2428+
if (!this._m_wasm_canvas_scene) return;
2429+
2430+
const document = this.doc.state.document;
2431+
syncDocument(this._m_wasm_canvas_scene, document, scene_id);
2432+
}
2433+
);
2434+
24072435
this.doc.subscribeWithSelector(
24082436
(state) => state.debug,
24092437
(_, v) => {

0 commit comments

Comments
 (0)