-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoctopus.js
60 lines (49 loc) · 1.48 KB
/
octopus.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const octopus = {
setup() {
view.focusScreen();
view.addScreenListener();
view.addButtonsListener();
view.addColorPickerListener();
},
inputCheckExpressionUpdate(key) {
inputOutputModel.run(key);
let expressionString = inputOutputModel.expressionString();
if (inputOutputModel.expressionLengthOk(expressionString)) {
view.renderToScreen(colorPickerModel.prepColorString(expressionString));
}
else { view.digitLimitMet(); }
// TODO: check the below - does it make sense?
if (postfixEvalModel.error()) {
this.resetModels();
}
},
processInput(infixArray) {
shuntModel.run(infixArray);
postfixEvalModel.run(shuntModel.queue);
shuntModel.reset();
inputOutputModel.expression = [inputOutputModel.formatResult(postfixEvalModel.result)];
},
setWaitingForPick(bool) {
colorPickerModel.waitingForPick = bool;
},
isWaitingForPick() {
return colorPickerModel.waitingForPick;
},
pickColor(key) {
let color = view.getColor();
view.changeColor(key, color);
colorPickerModel.setColor(key, color);
this.setWaitingForPick(false);
},
resetModels() {
inputOutputModel.reset();
shuntModel.reset();
postfixEvalModel.reset();
},
clearAll() {
this.resetModels();
view.clear();
}
}
window.onload = octopus.setup;