Skip to content

Commit 9a81d69

Browse files
authored
Merge pull request michaljaz#8 from NexusNull/threejs-typescript
replacing the deprecated 'keyCode' with 'code'
2 parents fa0a3bc + 7df749e commit 9a81d69

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/client/scripts/FirstPersonControls.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ FirstPersonControls = class FirstPersonControls {
66
constructor(game) {
77
this.game = game;
88
this.kc = {
9-
87: "forward",
10-
65: "right",
11-
83: "back",
12-
68: "left",
13-
32: "jump",
14-
16: "sneak",
15-
82: "sprint",
9+
"KeyW": "forward",
10+
"KeyD": "right",
11+
"KeyS": "back",
12+
"KeyA": "left",
13+
"Space": "jump",
14+
"ShiftLeft": "sneak",
15+
"KeyR": "sprint",
1616
};
1717
this.keys = {};
1818
this.setState("menu");
@@ -43,44 +43,44 @@ FirstPersonControls = class FirstPersonControls {
4343
$(document).keydown(function (z) {
4444
var to;
4545
//Kliknięcie
46-
_this.keys[z.keyCode] = true;
46+
_this.keys[z.code] = true;
4747
//Klawisz Escape
48-
if (z.keyCode === 27 && _this.gameState === "inventory") {
48+
if (z.code === "Escape" && _this.gameState === "inventory") {
4949
_this.setState("menu");
5050
}
5151
//Strzałki
52-
if (z.keyCode === 38 && _this.gameState === "chat") {
52+
if (z.code === "ArrowUp" && _this.gameState === "chat") {
5353
_this.game.chat.chatGoBack();
5454
}
55-
if (z.keyCode === 40 && _this.gameState === "chat") {
55+
if (z.code === "ArrowDown" && _this.gameState === "chat") {
5656
_this.game.chat.chatGoForward();
5757
}
5858
//Klawisz Enter
59-
if (z.keyCode === 13 && _this.gameState === "chat") {
59+
if (z.code === "Enter" && _this.gameState === "chat") {
6060
_this.game.chat.command($(".com_i").val());
6161
$(".com_i").val("");
6262
}
6363
//Klawisz E
6464
if (
65-
z.keyCode === 69 &&
65+
z.code === "KeyE" &&
6666
_this.gameState !== "chat" &&
6767
_this.gameState !== "menu"
6868
) {
6969
_this.setState("inventory");
7070
}
7171
//Klawisz T lub /
7272
if (
73-
(z.keyCode === 84 || z.keyCode === 191) &&
73+
(z.code === "KeyT" || z.code === "Backslash") &&
7474
_this.gameState === "gameLock"
7575
) {
76-
if (z.keyCode === 191) {
76+
if (z.code === "Backslash") {
7777
$(".com_i").val("/");
7878
}
7979
_this.setState("chat");
8080
z.preventDefault();
8181
}
8282
//Klawisz `
83-
if (z.keyCode === 192) {
83+
if (z.code === "Backquote") {
8484
z.preventDefault();
8585
if (
8686
_this.gameState === "menu" ||
@@ -92,19 +92,19 @@ FirstPersonControls = class FirstPersonControls {
9292
_this.setState("menu");
9393
}
9494
}
95-
if (z.keyCode === 27 && _this.gameState === "chat") {
95+
if (z.code === "Escape" && _this.gameState === "chat") {
9696
_this.setState("menu");
9797
}
9898

9999
//Flying
100-
if (z.keyCode === 70) {
100+
if (z.code === "KeyF") {
101101
_this.game.flying = !_this.game.flying;
102102
_this.game.socket.emit("fly", _this.game.flying);
103103
}
104104
//Wysyłanie state'u do serwera
105-
if (_this.kc[z.keyCode] !== void 0 && _this.gameState === "gameLock") {
106-
_this.game.socket.emit("move", _this.kc[z.keyCode], true);
107-
if (_this.kc[z.keyCode] === "sprint") {
105+
if (_this.kc[z.code] !== void 0 && _this.gameState === "gameLock") {
106+
_this.game.socket.emit("move", _this.kc[z.code], true);
107+
if (_this.kc[z.code] === "sprint") {
108108
to = {
109109
fov: _this.game.fov + 10,
110110
};
@@ -121,11 +121,11 @@ FirstPersonControls = class FirstPersonControls {
121121
$(document).keyup(function (z) {
122122
var to;
123123
//Odkliknięcie
124-
delete _this.keys[z.keyCode];
124+
delete _this.keys[z.code];
125125
//Wysyłanie state'u do serwera
126-
if (_this.kc[z.keyCode] !== void 0) {
127-
_this.game.socket.emit("move", _this.kc[z.keyCode], false);
128-
if (_this.kc[z.keyCode] === "sprint") {
126+
if (_this.kc[z.code] !== void 0) {
127+
_this.game.socket.emit("move", _this.kc[z.code], false);
128+
if (_this.kc[z.code] === "sprint") {
129129
to = {
130130
fov: _this.game.fov,
131131
};

0 commit comments

Comments
 (0)