-
Notifications
You must be signed in to change notification settings - Fork 0
/
Progress.js
42 lines (39 loc) · 1.33 KB
/
Progress.js
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
class Progress {
constructor() {
this.mapId = "DemoRoom"
this.startingHeroX = 0
this.startingHeroY = 0
this.startingHeroDirection = "down"
this.saveFileKey = "PizzaLegends_SaveFile1"
}
save() {
window.localStorage.setItem(this.saveFileKey, JSON.stringify({
mapId: this.mapId,
startingHeroX: this.startingHeroX,
startingHeroY: this.startingHeroY,
startingHeroDirection: this.startingHeroDirection,
playerState: {
pizzas: playerState.pizzas,
lineUp: playerState.lineUp,
items: playerState.items,
storyFlags: playerState.storyFlags,
}
}))
}
getSaveFile() {
const file = window.localStorage.getItem(this.saveFileKey)
return file ? JSON.parse(file) : null
}
load() {
const file = this.getSaveFile()
if (file) {
this.mapId = file.mapId
this.startingHeroX = file.startingHeroX
this.startingHeroY = file.startingHeroY
this.startingHeroDirection = file.startingHeroDirection
Object.keys(file.playerState).forEach(key => {
playerState[key] = file.playerState[key]
})
}
}
}