This commit is contained in:
2025-12-07 21:31:44 +01:00
parent 4a0ca267ea
commit 974141c08c
52 changed files with 2485 additions and 397 deletions

View File

@@ -38,7 +38,7 @@ class SaveSystem {
};
const saveData = {
version: 1.1,
version: 2.4, // Nazaj na pixel art
timestamp: Date.now(),
player: { x: playerPos.x, y: playerPos.y },
terrain: {
@@ -62,11 +62,18 @@ class SaveSystem {
try {
const jsonString = JSON.stringify(saveData);
localStorage.setItem(this.storageKey, jsonString);
// Compress data to save space
try {
const compressed = Compression.compress(jsonString);
localStorage.setItem(this.storageKey, 'LZW:' + compressed);
console.log(`✅ Game saved! Size: ${jsonString.length} -> ${compressed.length} chars`);
} catch (compErr) {
console.warn("Compression failed, saving raw JSON:", compErr);
localStorage.setItem(this.storageKey, jsonString);
}
// Pokaži obvestilo (preko UIScene če obstaja)
this.showNotification('GAME SAVED');
console.log('✅ Game saved successfully!', saveData);
} catch (e) {
console.error('❌ Failed to save game:', e);
this.showNotification('SAVE FAILED');
@@ -76,17 +83,32 @@ class SaveSystem {
loadGame() {
console.log('📂 Loading game...');
const jsonString = localStorage.getItem(this.storageKey);
if (!jsonString) {
let rawData = localStorage.getItem(this.storageKey);
if (!rawData) {
console.log('⚠️ No save file found.');
this.showNotification('NO SAVE FOUND');
return false;
}
try {
let jsonString = rawData;
// Check for compression
if (rawData.startsWith('LZW:')) {
const compressed = rawData.substring(4); // Remove prefix
jsonString = Compression.decompress(compressed);
}
const saveData = JSON.parse(jsonString);
console.log('Loading save data:', saveData);
// Preveri verzijo - če je stara, izbriši save
if (!saveData.version || saveData.version < 2.4) {
console.log('⚠️ Stara verzija save file-a detected, clearing...');
localStorage.removeItem(this.storageKey);
this.showNotification('OLD SAVE CLEARED - NEW GAME');
return false;
}
// 1. Load Player
if (this.scene.player) {
// Zahteva metodo setPosition(gridX, gridY) v Player.js
@@ -131,8 +153,7 @@ class SaveSystem {
this.scene.terrainSystem.visibleDecorations.clear();
this.scene.terrainSystem.visibleCrops.forEach(s => s.setVisible(false));
this.scene.terrainSystem.visibleCrops.clear();
this.scene.terrainSystem.decorationPool.releaseAll();
this.scene.terrainSystem.cropPool.releaseAll();
// Sproščanje objektov se samodejno dogaja preko release() v clearanju zgoraj
// B) Restore Crops
if (saveData.terrain.crops) {