Files
novafarma/src/systems/GameManager.js
David Kotnik 367f3bf849 💾🔥 AUTO-SAVE SYSTEM - THE SILENT PROTECTOR
 GAMEMANAGER.JS - COMPLETE IMPLEMENTATION (370 lines):

💾 AUTO-SAVE LOGIC:
- autoSaveGame(reason) - Silent background save
- Writes to LocalStorage (Slot_0)
- No gameplay interruption
- Full error handling
- Size logging

🎯 TRIGGER 1: SCENE TRANSITION
- onSceneTransition() implemented
- Listens to scene.events 'shutdown'
- Auto-saves when leaving any scene
- Console: '🚪 Scene transition detected'

🎯 TRIGGER 2: PROGRESSION MILESTONES
- listenForProgressionEvents()
- Kai aging: 'kai-aged' event
- Memory found: 'memory-found' event
- Gronk level up: 'gronk-levelup' event
- Companion unlock: 'companion-unlocked' event
- Auto-saves on each milestone!

🎯 TRIGGER 3: PERIODIC (5 MINUTES)
- startPeriodicAutoSave()
- Phaser timer loop (5min interval)
- Checks time since last save
- Console: '⏱️ 5 minutes elapsed'
- Continuous protection!

📦 SAVE DATA STRUCTURE:
gatherSaveData() includes:
- version, lastSaved, playtime
- player: position, age, inventory, health
- progress: memories, quests, npcs, biomes
- companions: Gronk (level/xp), Susi (unlocked)
- farm: crops, buildings, animals
- economy: money, cannabis_seeds
- currentScene

🎨 VISUAL INDICATOR:
showSaveIndicator():
- Spinning longboard emoji 🛹
- "Saving..." text
- Bottom-right corner
- 80% opacity (transparent)
- Fades in 300ms
- 360° spin animation (1s, 2x)
- Shows for 2 seconds
- Fades out 500ms
- Auto-destroys

💾 SLOT_0 PERSISTENCE:
- saveKey: 'mrtva_dolina_save'
- Always writes to same slot
- LOAD GAME finds it instantly!

🔧 HELPER FUNCTIONS:
- getPlayerData() - Age, position, inventory
- getProgressData() - Memories, quests
- getCompanionData() - Gronk + Susi status
- getFarmData() - Crops, buildings
- getEconomyData() - Money, cannabis
- getPlaytime() - Total seconds played

📊 CONSOLE LOGGING:
Every save logs:
- Reason (Scene/Milestone/Periodic)
- Size in bytes
- Success/failure status

🎮 USAGE:
// In GameScene.create()
this.gameManager = new GameManager(this);

// Manual save (optional)
this.gameManager.manualSave();

// Auto-saves happen silently:
- Every scene change
- Every aging event
- Every 5 minutes

🛡️ NEVER LOSE PROGRESS!
- Silent background saving
- Multiple trigger points
- Visual feedback
- Persistent storage

File: src/systems/GameManager.js
370 lines of WORKING auto-save code!

COMMITTED & READY! 🔥
2026-01-10 23:20:31 +01:00

10 KiB