-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.ts
66 lines (55 loc) · 1.77 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
55
56
57
58
59
60
61
62
63
64
65
66
namespace microcode {
// Auto-save slot
export const SAVESLOT_AUTO = "sa"
export 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()
// 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 saveBuffer(slot: string, buf: Buffer) {
reportEvent("app.save", { slot: slot, size: buf.length })
console.log(`save to ${slot}: ${buf.length}b`)
profile()
settings.writeBuffer(slot, buf)
}
public save(slot: string, prog: ProgramDefn) {
this.saveBuffer(slot, prog.toBuffer())
}
public load(slot: string): ProgramDefn {
try {
let buf = settings.readBuffer(slot)
if (buf) {
return ProgramDefn.fromBuffer(new BufferReader(buf))
}
} catch (e) {
console.log(e)
}
return undefined
}
public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}
public popScene() {
this.sceneManager.popScene()
}
}
}