-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.js
More file actions
84 lines (79 loc) · 2.03 KB
/
controls.js
File metadata and controls
84 lines (79 loc) · 2.03 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
function changeViewScale(amount){
var textBox = document.getElementById("View scale");
textBox.value = parseInt(textBox.value) + amount;
textBox.dispatchEvent(new Event('change'));
}
function changeHexSize(direction, fine=false){
var textBox = document.getElementById("Hex size");
var changeAmount = 0;
if(!fine){
changeAmount = Math.ceil(parseInt(textBox.value) / 10.0);
if(changeAmount < 1){changeAmount=1;}
}else{
changeAmount=1;
}
textBox.value = parseInt(textBox.value) + changeAmount*direction;
textBox.dispatchEvent(new Event('change'));
}
function MouseController(){
}
MouseController.prototype.wheel = function (event) {
var textBox = document.getElementById("hex-size");
var changeDirection = 0;
if(event.deltaY > 0){ // Scroll down == zoom out
changeDirection = -1;
}
if(event.deltaY < 0){ // Scroll up == zoom in
changeDirection = 1;
}
changeHexSize(changeDirection, event.shiftKey);
}
function KeyboardController(){
}
KeyboardController.prototype.keyDown = function (event) {
if(document.activeElement.tagName == "INPUT"){return;}
var xCoord = document.getElementById("View coordinate X");
var yCoord = document.getElementById("View coordinate Y");
var xChange = 0;
var yChange = 0;
switch(event.code){
case "Equal":
changeHexSize(1, event.shiftKey);
break;
case "Minus":
changeHexSize(-1, event.shiftKey);
break;
case "KeyS":
changeViewScale(event.shiftKey ? 1 : -1);
break;
case "KeyW":
yChange--;
break;
case "KeyX":
yChange++;
break;
case "KeyA":
xChange--;
break;
case "KeyD":
xChange++;
break;
case "KeyE":
xChange++;
yChange--;
break;
case "KeyZ":
xChange--;
yChange++;
break;
}
xCoord.value = parseInt(xCoord.value) + xChange;
yCoord.value = parseInt(yCoord.value) + yChange;
if(xChange!=0){
xCoord.dispatchEvent(new Event('change'));
return;
}
if(yChange!=0){
yCoord.dispatchEvent(new Event('change'));
}
}