Projex cloud saves with Continue/New game and autosave
PM Pull request #17 needs review. The fresh verification workspace could not be prepared. · 16d
Idea by John
PM Pull request #17 needs review. The fresh verification workspace could not be prepared. · 16d
Idea by John
Save Tower Works progress through window.projex cloud saves. The game already has save/load state, so this connects it to projex.save(state, slot) and projex.load(slot), which take JSON up to 256 KB. - **Startup:** if window.projex exists, check the slot for a save. If one exists, show Continue and New game. Continue restores the tower: floors, units, elevators (car counts, express stops), hotel state, rating and unlocks, burned/repair state, basements and money/day. Celebrations already earned don't replay. - **Autosave:** save at natural moments: placing or upgrading a unit, buying an elevator car, building a floor, earning a star, finishing a repair, and about every 30 seconds of play. Never save every frame. Calls are debounced, and a short "Saved" indicator appears without crowding the top bar. - **Backup:** any existing export/import moves into a menu as a backup option only. - **Fallback:** without window.projex, the game runs with no errors and just doesn't use cloud saves. - **Safety:** the saved state is sized to fit within 256 KB. Older or missing fields load with safe defaults. This covers the same goal as the earlier "Blueprint Vault: Autosave & Continue" idea, now using Projex cloud saves.
Save the player's progress to Projex cloud saves. On Projex, window.projex now keeps progress for the player: await projex.save(state, slot) stores JSON (up to 256 KB) and await projex.load(slot) returns it, or null. Signed-in players' saves follow them to any device; guests' stay in their browser. Acceptance criteria: - On startup, when window.projex exists, load the saved game and continue where the player left off (offer Continue and New game when a save exists). - Autosave at natural moments (finishing a level or match, a purchase, placing or upgrading something, or about every 30 seconds of play), never every frame, with a brief "Saved" indicator. - If the game has export/import save files, keep them only as a backup option in a menu, not the main way to save. - The game still works without window.projex (local tests): no errors, just no cloud saves. - Tests cover saving and restoring the game state.
I've scoped this as one change, nothing built yet. The game will save your tower to Projex cloud saves when it opens, offer Continue or New game when a save exists, and autosave when you build, buy or upgrade, earn a star, and about every 30 seconds, with a brief "Saved" indicator. If the game has save file export/import, it moves into a menu as a backup. Without Projex it runs normally, just without cloud saves. This also covers the earlier "Blueprint Vault: Autosave & Continue" idea. Queued for implementation in an isolated workspace. I’ll report the checks and a pull request here.
Implemented in pull request #17. The project build and tests passed in the isolated workspace. Tower Works now saves to Projex cloud saves and offers Continue or New game at startup. `npm run build` and `npm test` both pass: 95 tests, 0 failures. Nothing is committed or pushed; the platform handles that. **What changed** - **Startup:** when `window.projex` exists, the game checks the save slot (the start button reads "Checking for a saved tower…" meanwhile). If there's a save, a **Welcome back** card shows its stars, day, funds, floors and people, with the saved tower visible behind it. **Continue** restores everything: floors, units, shops, hotel rooms and guests, elevator cars and express stops, basements and garages, rating and unlocks, burned units, money, day and time of day. Celebrations already earned don't replay. **New game** asks once more before starting over. - **Autosave:** building, placing, buying a car, changing a shaft, repairing, earning a star and each day's end all trigger a save. The save is written about 1.2 s later, at most once every 4 s, and after every 30 s of unpaused play. Since a day lasts 24 s at 1×, idle saves land about 24 s apart. Nothing saves while paused or before the player picks Continue or New game, so a fresh tower can't overwrite the saved one. Switching tabs saves right away. A small "Saved" chip appears in the top-right of the tower view, not the top bar. A failed save shows "Not saved" and retries. - **Size:** a maxed 20-floor, 5★ tower with three basements saves at about 10 KB, far under the 256 KB limit. If a save ever got too big, it drops rebuildable logs first, and refuses to save rather than store a cut-off file. Older saves, or saves missing newer fields, load with safe defaults. - **Menu:** Export and Import moved out of the side panel into a new **Menu**, alongside the save status, **Save now** and **Start a new tower**. - **Restart now confirms in the menu.** It used `window.confirm`, which a sandboxed iframe like Projex's may block, so Restart could silently do nothing there. - **Without Projex:** the game uses browser storage if it can, otherwise it plays normally with no saves, no errors and no cloud calls. - Updated the README with a Saving section. **Tests added** - A maxed tower's save size and full round trip, oversized saves, and old or junk saves. - In the built page with a mocked `window.projex`: - Continue and New game, and Continue restoring the tower without a celebration. - Delayed saves after a build, one save for a burst of clicks, saves after a repair, a star, a tab switch and Save now. - Save timing over two minutes of play, and no saves while paused. - Failed saves, broken or unreachable save slots, and browser storage standing in. - The no-Projex fallback, and Export/Import appearing only in the menu. **Screenshots reviewed** (Projex was simulated in a real browser; all ran with no console errors) - Welcome back card, with and without the New game confirm, at 1440×900 and 390×844. - The Saved chip mid-game, and the menu at both sizes. - The intro without Projex, and a fresh game's first save. Fixes from that review: - The menu's close and Save now buttons were stretched full width. - On mobile the chip covered the floor-19 label, so I moved it to the top-right. I saved the cover shot, a busy full tower at midday, with `projex-shot --name cover --sizes 1440x900`. Verification and merge follow the project’s auto-merge setting. You can follow the pull request in the Code tab.
Pull request #17 needs review. The fresh verification workspace could not be prepared.
Log in to add to the discussion.