forked from microsoft/microcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
54 lines (47 loc) · 1.44 KB
/
app.ts
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
namespace microcode {
// Auto-save slot
export const SAVESLOT_AUTO = "sa"
// Save slots
export const SAVESLOT_1 = "s1"
export const SAVESLOT_2 = "s2"
export const SAVESLOT_3 = "s3"
type SavedState = {
progdef: any
}
export class App {
sceneManager: SceneManager
constructor() {
// One interval delay to ensure all static constructors have executed.
setTimeout(() => {
controller.setRepeatDefault(250, 30)
icons.init()
this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
}, 1)
}
public save(slot: string, progdef: ProgramDefn) {
const saved: SavedState = {
progdef: progdef.toObj(),
}
const s = JSON.stringify(saved)
settings.writeString(slot, s)
}
public load(slot: string): ProgramDefn {
const s = settings.readString(slot)
if (s) {
const saved: SavedState = JSON.parse(s)
if (saved) {
return ProgramDefn.FromObj(saved.progdef)
}
}
return undefined
}
public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}
public popScene() {
this.sceneManager.popScene()
}
}
}