Repository navigation
Expand file tree
/
Copy pathkeyhandler.js
More file actions
114 lines (89 loc) · 2.56 KB
/
Copy pathkeyhandler.js
File metadata and controls
114 lines (89 loc) · 2.56 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class KeyboardHandler {
posx = 0;
posy = 0;
counter = 0;
inputDelay = 30;
keys = ["Space", "ArrowLeft", "ArrowRight", "ArrowDown", "ArrowUp"];
constructor(_board) {
this.board = _board;
this.size = _board.size;
$(document).keydown((e) => {
if (this.keys.includes(e.code)) {
e.preventDefault();
}
});
// Begin custom controls
kd.LEFT.down((e) => {
if (this.counter <= this.inputDelay) { this.counter++; return; }
else { this.counter = 0; }
this._left();
});
kd.LEFT.press((e) => {
this.counter = -15;
this._left();
});
kd.RIGHT.down((e) => {
if (this.counter <= this.inputDelay) { this.counter++; return; }
else { this.counter = 0; }
this._right();
});
kd.RIGHT.press((e) => {
this.counter = -15;
this._right();
});
kd.UP.down((e) => {
if (this.counter <= this.inputDelay) { this.counter++; return; }
else { this.counter = 0; }
this._up();
});
kd.UP.press((e) => {
this.counter = -15;
this._up();
});
kd.DOWN.down((e) => {
if (this.counter <= this.inputDelay) { this.counter++; return; }
else { this.counter = 0; }
this._down();
});
kd.DOWN.press((e) => {
this.counter = -15;
this._down();
});
kd.SPACE.press((e) => { // scrolling by spacebar
this.board.isCommenting = true;
this.board.isUserCommenting = true;
this.board.reveal(this.posx, this.posy, false);
this.board.isUserCommenting = false;
this.board.isCommenting = false;
});
kd.SPACE.up((e) => { e.preventDefault(); });
setInterval(function() {
kd.tick();
}, 0);
}
_down() {
if (this.posy < this.size - 1) {
this.focus(this.posx, ++this.posy);
}
}
_left() {
if (this.posx != 0) {
this.focus(--this.posx, this.posy);
}
}
_right() {
if (this.posx < this.size - 1) {
this.focus(++this.posx, this.posy);
}
}
_up() {
if (this.posy != 0) {
this.focus(this.posx, --this.posy);
}
}
focus(x, y) {
this.posx = x;
this.posy = y;
$("#" + x + "_" + y).focus();
}
}