-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeyboard.js
75 lines (65 loc) · 2.55 KB
/
keyboard.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
export default class KeyboardEvents {
constructor(main) {
this.main = main;
this.shapes = ['cube', 'half-cylinder', 'quarter-cylinder']
this.shapePosition = 0
this.main.currentShape = 'cube'
this.rotationAxes = ['x','y','z']
this.rotationPosition = 0
this.main.currentRotationAxe = 'x'
this.currentCommand = 'CREATE' // DEFAULTS
this.currentCommandDiv = document.getElementById('currentCommand');
this.currentCommandDiv.innerHTML = this.currentCommand
this.startListenDocumentKeyup()
}
getNextShape () {
this.shapePosition++
if (this.shapePosition > this.shapes.length - 1) {
this.shapePosition = 0
}
return this.shapes[this.shapePosition]
}
getNextRotation () {
this.rotationPosition++
if (this.rotationPosition > this.rotationAxes.length - 1) {
this.rotationPosition = 0
}
return this.rotationAxes[this.rotationPosition]
}
startListenDocumentKeyup () {
document.onkeyup = (e) => {
if (e.key == 'Escape' || e.key == ' ') {
this.main.currentShape = this.getNextShape()
this.currentCommand = 'CREATE';
console.log('Shape: ', this.main.currentShape)
} else if (e.key == 'e') {
this.currentCommand = 'EDIT';
} else if (e.key == 'd') {
this.currentCommand = 'DELETE';
} else if (e.key == 'f') {
this.currentCommand = 'FILL';
} else if (e.key == 'r') {
this.main.currentRotationAxe = this.getNextRotation()
this.currentCommand = 'ROTATE';
} else if (e.key == 'm') {
this.currentCommand = 'MOVE';
} else if (e.key == '1') {
this.main.gridDiv = 128
this.main.createGrid(this.main.gridDiv)
} else if (e.key == '2') {
this.main.gridDiv = 64
this.main.createGrid(this.main.gridDiv)
} else if (e.key == '3') { // default
this.main.gridDiv = 32
this.main.createGrid(this.main.gridDiv)
} else if (e.key == '4') {
this.main.gridDiv = 16
this.main.createGrid(this.main.gridDiv)
} else if (e.key == '5') {
this.main.gridDiv = 8
this.main.createGrid(this.main.gridDiv)
}
this.currentCommandDiv.innerHTML = this.currentCommand
}
}
}