forked from eanders-ms/microcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
71 lines (60 loc) · 1.93 KB
/
app.ts
File metadata and controls
71 lines (60 loc) · 1.93 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
namespace microcode {
// Auto-save slot
export const SAVESLOT_AUTO = "sa"
interface SavedState {
progdef: any
version?: string
}
export class App {
sceneManager: SceneManager
constructor() {
// One interval delay to ensure all static constructors have executed.
setTimeout(() => {
reportEvent("app.start")
controller.setRepeatDefault(250, 30)
keymap.setupKeys()
icons.init()
// start jacscript
jdc.setParameters(
0x3e92f825,
microcode.VERSION,
"MicroCode on micro:bit V2"
)
jdc.start()
this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
}, 1)
}
public saveSource(slot: string, s: string) {
reportEvent("app.save", { slot: slot, size: s.length })
settings.writeString(slot, s)
}
public save(slot: string, progdef: ProgramDefn) {
const saved: SavedState = {
progdef: progdef.toObj(),
version: microcode.VERSION,
}
const s = JSON.stringify(saved)
this.saveSource(slot, s)
}
public load(slot: string): ProgramDefn {
try {
const s = settings.readString(slot)
if (s) {
const saved: SavedState = JSON.parse(s)
if (saved) return ProgramDefn.FromObj(saved.progdef)
}
} catch (e) {
console.log(e)
}
return undefined
}
public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}
public popScene() {
this.sceneManager.popScene()
}
}
}