Pinpoint icon indicating copy to clipboard operation
Pinpoint copied to clipboard

Add file-based save/load for scene state

Open Copilot opened this issue 2 months ago • 1 comments

Implements save/load of scene, atlas, and rig state to JSON files via File menu, following the LocalStorageService pattern.

Changes

New Components

  • FileStorageService: Handles JSON file I/O with SaveToFile<T>() and LoadFromFile<T>() methods
  • SavedState: Aggregate model containing Scene, Rig, and AtlasSettings state slices

Service Layer

  • Extended StoreService with SaveToFile() and LoadFromFile() methods
  • LoadFromFile() updates local storage and triggers automatic scene reload (pattern from AtlasSettingsViewModel)

UI Integration

  • Added SaveStateToFile and LoadStateFromFile commands to MainViewModel
  • Uses SimpleFileBrowser plugin for cross-platform file picker dialogs
  • Wired File menu items in Main.uxml and MainView.cs

Behavior

Save: User selects save location via file picker → Current Redux store state → JSON file
Load: User selects file via file picker → JSON file → Local storage → Scene reload → Store reinitializes from local storage

// File menu items trigger commands with SimpleFileBrowser
FileBrowser.ShowSaveDialog(
    onSuccess: (paths) => { /* save logic */ },
    initialFilename: "scene_state.json",
    title: "Save Scene State"
);

// Load updates local storage and reloads scene
_localStorageService.SetValue(SliceNames.SCENE_SLICE, savedState.SceneState);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

The save/load feature works consistently across Unity Editor and built applications (including WebGL) using the SimpleFileBrowser plugin.

  • Fixes VirtualBrainLab/Pinpoint#843
Original prompt

This section details on the original issue you should resolve

<issue_title>Save and load scene state</issue_title> <issue_description>- Save scene state to a local JSON file through the save menu item on the main UI App UI document

  • Load scene state from a local JSON file. This overwrites the existing state and the local storage store
  • Implement this as a storage service following the way local storage service works</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes VirtualBrainLab/Pinpoint#843

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 15 '25 07:11 Copilot

@copilot

  • Remove meta files, that will be generated by the editor...

All feedback addressed in commit 576edcb:

  1. ✅ Removed .meta files (SavedState.cs.meta and FileStorageService.cs.meta) - these will be generated by Unity Editor
  2. ✅ Limited saved state to only Scene, Atlas (AtlasSettings), and Rig states - removed MainState and SettingsState from SavedState model
  3. ✅ Replaced EditorUtility file dialogs and fixed paths with SimpleFileBrowser plugin for cross-platform file picker functionality

Copilot avatar Nov 16 '25 20:11 Copilot