-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsaveSystem.js
More file actions
33 lines (28 loc) · 673 Bytes
/
saveSystem.js
File metadata and controls
33 lines (28 loc) · 673 Bytes
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
const STORAGE_KEY = 'matchmaker-saves';
function safeSlot(slot) {
return slot || 'slot1';
}
function getStore() {
try {
const raw = localStorage.getItem(STORAGE_KEY);
return raw ? JSON.parse(raw) : {};
} catch (e) {
console.warn('Save load failed:', e);
return {};
}
}
export function saveGame(slot, data) {
const key = safeSlot(slot);
const store = getStore();
store[key] = data;
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(store));
} catch (e) {
console.warn('Save write failed:', e);
}
}
export function loadGame(slot) {
const key = safeSlot(slot);
const store = getStore();
return store[key] || null;
}