mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-20 16:45:10 +00:00
Scene State saving works.
This commit is contained in:
1 parent
a50c1a8c3d
commit
e99cacb040
2 files changed
+41
-3
No files matched your search
@@ -96,6 +96,10 @@ interface SceneState {
|
||||
importSceneFromJson: (jsonString: string) => boolean;
|
||||
saveSceneToFile: () => Promise<void>;
|
||||
loadSceneFromFile: (file: File) => Promise<boolean>;
|
||||
|
||||
// Add these two properties
|
||||
serializeSceneToString: () => Promise<string>;
|
||||
loadSceneFromString: (jsonString: string) => boolean;
|
||||
}
|
||||
|
||||
const generateId = (): string => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { create } from 'zustand';
|
||||
import { useSceneStore } from '../PageDraw/stores/SceneState';
|
||||
|
||||
export type TabId = '2D' | '3D' | 'VIDEO' | 'IMAGE';
|
||||
|
||||
@@ -10,7 +11,7 @@ interface TabState {
|
||||
[K in TabId]?: string;
|
||||
};
|
||||
// Actions
|
||||
setActiveTab: (tabId: TabId) => void;
|
||||
setActiveTab: (tabId: TabId) => Promise<boolean>;
|
||||
updateTabData: (tabId: TabId, data: unknown) => void;
|
||||
getTabData: <T>(tabId: TabId) => T | null;
|
||||
clearTabData: (tabId: TabId) => void;
|
||||
@@ -20,8 +21,41 @@ export const useTabStore = create<TabState>((set, get) => ({
|
||||
activeTabId: '2D',
|
||||
tabData: {},
|
||||
|
||||
setActiveTab: (tabId) => {
|
||||
set({ activeTabId: tabId });
|
||||
setActiveTab: async (newTabId) => {
|
||||
const currentTabId = get().activeTabId;
|
||||
|
||||
// Don't do anything if we're already on this tab
|
||||
if (currentTabId === newTabId) return true;
|
||||
|
||||
try {
|
||||
// Save current 2D state if we're leaving 2D tab
|
||||
if (currentTabId === '2D') {
|
||||
const sceneStore = useSceneStore.getState();
|
||||
const sceneState = await sceneStore.serializeSceneToString();
|
||||
set(state => ({
|
||||
tabData: {
|
||||
...state.tabData,
|
||||
'2D': sceneState
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Load 2D state if we're entering 2D tab
|
||||
if (newTabId === '2D') {
|
||||
const savedState = get().tabData['2D'];
|
||||
if (savedState) {
|
||||
const sceneStore = useSceneStore.getState();
|
||||
sceneStore.loadSceneFromString(savedState);
|
||||
}
|
||||
}
|
||||
|
||||
// Update active tab
|
||||
set({ activeTabId: newTabId });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error during tab change:', error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
updateTabData: (tabId, data) => {
|
||||
|
||||
Reference in new issue
Block a user