-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.ts
More file actions
90 lines (72 loc) · 2.5 KB
/
app.ts
File metadata and controls
90 lines (72 loc) · 2.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
namespace microcode {
import AppInterface = user_interface_base.AppInterface
import Scene = user_interface_base.Scene
import SceneManager = user_interface_base.SceneManager
// Auto-save slot
export const SAVESLOT_AUTO = "sa"
export interface SavedState {
progdef: any
version?: string
}
export class App implements AppInterface {
private sceneManager: SceneManager
constructor() {
// One interval delay to ensure all static constructors have executed.
basic.pause(500)
// Application configuration
user_interface_base.getIcon = id => icons.get(id)
user_interface_base.resolveTooltip = (ariaId: string) =>
resolveTooltip(ariaId)
const buf = this.load(SAVESLOT_AUTO)
if (buf) {
const prog = ProgramDefn.fromBuffer(new BufferReader(buf))
runProgram(prog)
}
controller.setRepeatDefault(250, 30)
// keymap.setupKeys()
this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
}
public save(slot: string, buf: Buffer) {
// console.log(`save to ${slot}: ${buf.length}b`)
profile()
settings.writeBuffer(slot, buf)
return true
}
public load(slot: string): Buffer {
try {
return settings.readBuffer(slot)
} catch (e) {
console.log(e)
}
return undefined
}
public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}
public popScene() {
this.sceneManager.popScene()
}
public runFromEditor() {
const topIndex = this.sceneManager.scenes.length - 1
const topScene = this.sceneManager.scenes[topIndex]
if (topScene instanceof Editor) {
const editor: Editor = topScene
editor.runProgram()
}
}
}
let theInterpreter: Interpreter = undefined
export function runProgram(prog: ProgramDefn) {
if (theInterpreter) theInterpreter.stop()
theInterpreter = new Interpreter(prog, runtimeHost)
}
export function stopProgram() {
if (theInterpreter) theInterpreter.stop()
theInterpreter = undefined
}
export function isProgramRunning() {
return theInterpreter != undefined
}
}