Session 13: Save Slot Preview (footer shows each slot's stardust, buildings, achievements, last-saved; hover to preview)
This commit is contained in:
@@ -359,3 +359,30 @@ Headless test at /opt/data/idle-game-test/golden-bloom-test.mjs — **22/22 pass
|
||||
- Consider adding "Buy Max" to upgrades too.
|
||||
- Potential new building tiers or prestige milestones.
|
||||
- Sound variations or background music.
|
||||
|
||||
---
|
||||
|
||||
### Session 13 - 2026-08-23 (Morning)
|
||||
**Status:** ✅ Save Slot Preview Added
|
||||
|
||||
#### What was done:
|
||||
- Followed up on Session 12's stated next goal by adding a **save-slot preview** so players can tell their save slots apart at a glance.
|
||||
- Added `Game.getSlotPreview(slot)` — a read-only helper that reads a given slot's data from localStorage WITHOUT mutating the live game state. It returns: `present` (has any saved data), `stardust`, `totalStardust`, `buildings` (sum of all building counts), `achievements` [count/total], `prestigeCount`, and a human-readable `lastSaved` "time ago" string.
|
||||
- Added `Game.formatTimeAgo(secs)` — formats a second-count into compact relative labels ("just now", "1m ago", "3h ago", "2d ago", "7mo ago", etc.).
|
||||
- Wired the preview into the footer: a monospace `.slot-preview` span now shows the active slot's live summary every tick (`Slot N: 1.2K ✨ · 8 plants · 2/33 · just now`). Hovering any slot button swaps the preview to that slot's contents; leaving falls back to the active slot.
|
||||
- Added CSS for `.slot-preview` (monospace, ellipsis-truncated, dims until hover) and a `.empty` style for unreadable slots ("Slot N: empty").
|
||||
- All display logic is read-only — `getSlotPreview()` calls the existing `loadSlot()` and never touches `Game.state`, verified by a dedicated test.
|
||||
|
||||
#### Files modified:
|
||||
- `js/game.js` - added `getSlotPreview(slot)` + `formatTimeAgo(secs)` methods (inserted before `switchSlot()`)
|
||||
- `index.html` - added `<span id="slot-preview">` inside the footer Slot section
|
||||
- `js/ui.js` - added `updateSlotPreview()`; called it from `UI.update()` each tick and wired per-slot hover/leave listeners (re-cloning slot buttons each render to avoid duplicate listeners)
|
||||
- `css/game.css` - `.slot-preview`, `.slot-preview.empty`, and hover-brightening rules
|
||||
|
||||
#### Verification:
|
||||
Wrote a headless Node.js test (`/opt/data/idle-game-test/slot-preview-test.mjs`) evaluating the real game.js in-process with localStorage + UI stubs. **22/22 checks pass**, covering: empty-slot handling (present:false, zeroed), populated-slot field reads (stardust, totalStardust, summed buildings, achievement count/total, prestigeCount), formatTimeAgo buckets (just now / m / h / d), relative lastSaved strings, read-only guarantee (live state unchanged after previews), and graceful handling of malformed/missing fields (minimal object → present:true zeroed; non-numeric building count coerced to 0 with no crash). Existing golden-bloom test re-ran clean (22/22, no regression). All modified JS files pass `node --check`.
|
||||
|
||||
#### Next goals:
|
||||
- Consider adding a "Buy Max" button to upgrades too (one-time purchases — less critical).
|
||||
- Potential new building tiers or prestige milestones.
|
||||
- Sound variations or background music.
|
||||
|
||||
Reference in New Issue
Block a user