-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveManager.js
More file actions
226 lines (197 loc) · 6.83 KB
/
Copy pathsaveManager.js
File metadata and controls
226 lines (197 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// ECLIPSE RISING - LocalStorage Save & Achievements Manager
const SAVE_KEY = "eclipse_rising_save_v1";
const DEFAULT_SAVE = {
character: null, // 'knight' or 'sorceress'
level: 1,
xp: 0,
xpNeeded: 100,
unlockedBosses: [1], // Boss IDs unlocked: 1, 2, 3, 4
completedLevels: [],
achievements: [], // Achievement IDs unlocked
stats: {
totalExercises: 0,
totalDamageTaken: 0,
highestCombo: 0,
totalCalories: 0,
bossesDefeated: 0
}
};
export const Achievements = [
{
id: "first_blood",
title: "First Blood",
desc: "Defeat The Bone Warden (Level 1)",
icon: "☠️"
},
{
id: "untouchable",
title: "Untouchable",
desc: "Complete any boss duel without taking damage",
icon: "🛡️"
},
{
id: "combo_lord",
title: "Combo Lord",
desc: "Reach a 15x Combo count in combat",
icon: "🔥"
},
{
id: "eclipse_savior",
title: "Eclipse Savior",
desc: "Defeat The Eclipse King and restore the dawn",
icon: "☀️"
}
];
class SaveManager {
constructor() {
this.currentData = this.loadSave();
}
loadSave() {
try {
const data = localStorage.getItem(SAVE_KEY);
if (data) {
// Merge with defaults to ensure newer fields exist
const parsed = JSON.parse(data);
return {
...DEFAULT_SAVE,
...parsed,
stats: { ...DEFAULT_SAVE.stats, ...parsed.stats },
unlockedBosses: parsed.unlockedBosses || [1],
achievements: parsed.achievements || [],
completedLevels: parsed.completedLevels || []
};
}
} catch (e) {
console.error("Error loading save file, using default data.", e);
}
return JSON.parse(JSON.stringify(DEFAULT_SAVE));
}
save() {
try {
localStorage.setItem(SAVE_KEY, JSON.stringify(this.currentData));
} catch (e) {
console.error("Failed to write save to LocalStorage.", e);
}
}
reset() {
this.currentData = JSON.parse(JSON.stringify(DEFAULT_SAVE));
this.save();
return this.currentData;
}
setCharacter(charId) {
this.currentData.character = charId;
this.save();
}
unlockBoss(bossId) {
const id = parseInt(bossId);
if (!this.currentData.unlockedBosses.includes(id)) {
this.currentData.unlockedBosses.push(id);
this.save();
return true;
}
return false;
}
completeLevel(bossId) {
const id = parseInt(bossId);
if (!this.currentData.completedLevels.includes(id)) {
this.currentData.completedLevels.push(id);
}
// Auto unlock next boss
const nextBoss = id + 1;
if (nextBoss <= 4) {
this.unlockBoss(nextBoss);
}
this.currentData.stats.bossesDefeated = this.currentData.completedLevels.length;
// Award achievements
if (id === 1) this.unlockAchievement("first_blood");
if (id === 4) this.unlockAchievement("eclipse_savior");
this.save();
}
addXP(amount) {
this.currentData.xp += amount;
let leveledUp = false;
while (this.currentData.xp >= this.currentData.xpNeeded) {
this.currentData.xp -= this.currentData.xpNeeded;
this.currentData.level++;
this.currentData.xpNeeded = Math.floor(this.currentData.xpNeeded * 1.5);
leveledUp = true;
}
this.save();
return leveledUp;
}
updateStats(statsDelta) {
if (statsDelta.exercises) this.currentData.stats.totalExercises += statsDelta.exercises;
if (statsDelta.damageTaken) this.currentData.stats.totalDamageTaken += statsDelta.damageTaken;
if (statsDelta.calories) this.currentData.stats.totalCalories += statsDelta.calories;
if (statsDelta.highestCombo && statsDelta.highestCombo > this.currentData.stats.highestCombo) {
this.currentData.stats.highestCombo = statsDelta.highestCombo;
if (this.currentData.stats.highestCombo >= 15) {
this.unlockAchievement("combo_lord");
}
}
this.save();
}
unlockAchievement(achId) {
if (!this.currentData.achievements.includes(achId)) {
this.currentData.achievements.push(achId);
this.save();
this.showAchievementBanner(achId);
return true;
}
return false;
}
showAchievementBanner(achId) {
const ach = Achievements.find(a => a.id === achId);
if (!ach) return;
// Build DOM notification overlay
const banner = document.createElement("div");
banner.className = "achievement-banner";
banner.style.cssText = `
position: absolute;
top: 25px;
left: 50%;
transform: translateX(-50%) translateY(-50px);
background: rgba(18, 12, 12, 0.95);
border: 1px solid #ffdfad;
box-shadow: 0 0 20px rgba(179, 143, 84, 0.8);
border-radius: 4px;
padding: 12px 24px;
display: flex;
align-items: center;
gap: 15px;
z-index: 9999;
opacity: 0;
transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
pointer-events: none;
`;
banner.innerHTML = `
<div style="font-size: 2rem;">${ach.icon}</div>
<div>
<div style="font-family: 'Cinzel', serif; color: #ffdfad; font-weight: bold; font-size: 0.85rem; letter-spacing: 1px;">ACHIEVEMENT UNLOCKED</div>
<div style="color: #fff; font-weight: bold; font-size: 1.05rem; margin-top: 2px;">${ach.title}</div>
<div style="color: #8c8276; font-size: 0.75rem; margin-top: 2px;">${ach.desc}</div>
</div>
`;
document.body.appendChild(banner);
// Play chime SFX
try {
import("./audioManager.js").then(({ audio }) => {
audio.playHealAura();
});
} catch (e) { }
// Animate in, then out
setTimeout(() => {
banner.style.transform = "translateX(-50%) translateY(0)";
banner.style.opacity = "1";
}, 100);
setTimeout(() => {
banner.style.transform = "translateX(-50%) translateY(-50px)";
banner.style.opacity = "0";
setTimeout(() => {
banner.remove();
}, 500);
}, 4500);
}
}
export const saveManager = new SaveManager();
export default saveManager;