Skip to content

Persist robot state across page refreshes via localStorage#5

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-localstorage-robot-work
Draft

Persist robot state across page refreshes via localStorage#5
Copilot wants to merge 2 commits intomainfrom
copilot/fix-localstorage-robot-work

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Robot configuration, position, and block layout were lost on every page refresh. This adds full localStorage persistence to home.html.

What's saved

  • Robot parts, position, angle, color, held block
  • Motor power and turn speed settings
  • All block positions, shapes, and colors

Implementation

saveState() — serializes state to localStorage under robotics_playground_state.

loadState() — called once before the game loop starts; restores all state and syncs UI elements (sliders, color picker, parts list, camera feed visibility, lidar panel).

Save triggers:

  • Immediately on discrete actions: addPart, removePart, updatePower, updateTurn, updateColor, handlePickDrop
  • Periodically (≤1s interval) inside loop() to capture position/angle during movement

ResetresetAll() calls localStorage.removeItem(STORAGE_KEY) so a reset stays reset after refresh.

Restored x/y are clamped to current canvas bounds to handle viewport size changes between sessions. All localStorage calls are wrapped in try/catch to gracefully handle unavailability (e.g. private browsing, storage quota).


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: A1L13N <193832434+A1L13N@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix page refresh issue with robot work persistence Persist robot state across page refreshes via localStorage Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants