Skip to content

Commit 4d4e1c4

Browse files
committed
cleanup code
1 parent f6877b6 commit 4d4e1c4

21 files changed

+194
-203
lines changed

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"socket.io": "^2.3.0",
4040
"socket.io-client": "^2.3.0",
4141
"stats-js": "^1.0.1",
42+
"sweetalert": "^2.1.2",
4243
"three": "^0.124.0",
4344
"webpack-dev-server": "^3.11.1",
4445
"webpack-merge": "^5.7.3",

src/client/scripts/AssetLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from "three";
22
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
33

4-
var AssetLoader = class AssetLoader {
4+
class AssetLoader {
55
constructor(init) {
66
var _this = this;
77
this.assets = {};

src/client/scripts/BlockBreak.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as THREE from "three";
22

3-
var BlockBreak = class BlockBreak {
3+
class BlockBreak {
44
constructor(game) {
55
this.game = game;
66
this.texture = this.game.al.get("blocksAtlasSnap");
@@ -27,20 +27,17 @@ var BlockBreak = class BlockBreak {
2727
}
2828

2929
setState(state) {
30-
var i, j, q, ref, toxX, toxY;
31-
//od 0 do 9
3230
if (state === 0) {
3331
return (this.cursor.material.visible = false);
3432
} else {
3533
this.cursor.material.visible = true;
36-
toxX = 6 + state;
37-
toxY = 8;
38-
q = 1 / 27;
34+
var toxX = 6 + state;
35+
var toxY = 8;
36+
var q = 1 / 27;
3937
for (
40-
i = j = 0,
41-
ref = this.cursor.geometry.attributes.uv.array.length;
42-
0 <= ref ? j <= ref : j >= ref;
43-
i = 0 <= ref ? ++j : --j
38+
var i = 0;
39+
i <= this.cursor.geometry.attributes.uv.array.length;
40+
i++
4441
) {
4542
if (this.uv[i] === void 0) {
4643
if (i % 2 === 0) {
@@ -79,14 +76,13 @@ var BlockBreak = class BlockBreak {
7976
}
8077

8178
updatePos(cb) {
82-
var pos, rayBlock;
83-
rayBlock = this.game.world.getRayBlock();
79+
var rayBlock = this.game.world.getRayBlock();
8480
if (JSON.stringify(this.lastPos) !== JSON.stringify(rayBlock)) {
8581
this.lastPos = rayBlock;
8682
cb();
8783
}
8884
if (rayBlock) {
89-
pos = rayBlock.posBreak;
85+
var pos = rayBlock.posBreak;
9086
this.cursor.position.set(...pos);
9187
this.cursor.visible = true;
9288
this.cursorOut.position.set(...pos);
@@ -98,19 +94,17 @@ var BlockBreak = class BlockBreak {
9894
}
9995

10096
digRequest() {
101-
var pos;
10297
console.log("REQUESTING DIGGING...");
103-
pos = this.game.world.getRayBlock().posBreak;
98+
var pos = this.game.world.getRayBlock().posBreak;
10499
if (pos !== void 0) {
105100
this.game.socket.emit("dig", pos);
106101
this.done = false;
107102
}
108103
}
109104

110105
startDigging(time) {
111-
var _this, ile;
112-
_this = this;
113-
ile = 0;
106+
var _this = this;
107+
var ile = 0;
114108
if (this.isDigging === false) {
115109
this.isDigging = true;
116110
this.int = setInterval(function () {
@@ -136,6 +130,6 @@ var BlockBreak = class BlockBreak {
136130
this.setState(0);
137131
clearInterval(this.int);
138132
}
139-
};
133+
}
140134

141135
export { BlockBreak };

src/client/scripts/BlockPlace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var BlockPlace = class BlockPlace {
1+
class BlockPlace {
22
constructor(game) {
33
this.game = game;
44
}
@@ -13,6 +13,6 @@ var BlockPlace = class BlockPlace {
1313
pos.posBreak[1] -= 16;
1414
return this.game.socket.emit("blockPlace", pos.posBreak, vector);
1515
}
16-
};
16+
}
1717

1818
export { BlockPlace };

src/client/scripts/Chat.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Chat = class Chat {
1+
class Chat {
22
constructor(game) {
33
var _this = this;
44
this.game = game;
@@ -55,8 +55,11 @@ var Chat = class Chat {
5555
}
5656

5757
log(message) {
58-
if(message.split(" ")[1].indexOf("<") == -1 && message.split(" ").indexOf(">") == -1)
59-
$(".chat").append(`<span>${message}<br></span>`);
58+
if (
59+
message.split(" ")[1].indexOf("<") == -1 &&
60+
message.split(" ").indexOf(">") == -1
61+
)
62+
$(".chat").append(`<span>${message}<br></span>`);
6063
this.scrollToBottom(this.chatDiv);
6164
}
6265

@@ -69,6 +72,6 @@ var Chat = class Chat {
6972
return this.game.socket.emit("command", com);
7073
}
7174
}
72-
};
75+
}
7376

7477
export { Chat };

src/client/scripts/DistanceBasedFog.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import * as THREE from "three";
22

3-
var DistanceBasedFog = class DistanceBasedFog {
4-
constructor() {
3+
class DistanceBasedFog {
4+
constructor(game) {
5+
this.game = game;
56
this.view = new THREE.Vector3();
67
this.farnear = new THREE.Vector2();
78
this.color = new THREE.Vector4();
89
return;
910
}
1011

12+
update() {
13+
this.view
14+
.copy(this.game.camera.position)
15+
.applyMatrix4(this.game.camera.matrixWorldInverse);
16+
}
17+
1118
addShaderToMaterial(material) {
1219
var _this = this;
1320
material.onBeforeCompile = function (shader) {
@@ -50,6 +57,6 @@ var DistanceBasedFog = class DistanceBasedFog {
5057
);
5158
};
5259
}
53-
};
60+
}
5461

5562
export { DistanceBasedFog };

src/client/scripts/Entities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as THREE from "three";
22

3-
var Entities = class Entities {
3+
class Entities {
44
constructor(game) {
55
this.game = game;
66
this.mobMaterial = new THREE.MeshStandardMaterial({
@@ -67,6 +67,6 @@ var Entities = class Entities {
6767
}
6868
this.playerMesh.instanceMatrix.needsUpdate = true;
6969
}
70-
};
70+
}
7171

7272
export { Entities };

src/client/scripts/EventHandler.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class EventHandler {
2121
this.setState("menu");
2222
document.exitPointerLock =
2323
document.exitPointerLock || document.mozExitPointerLock;
24-
//Mouse wheel change inventory
2524
var focus = 0;
2625
this.game.inv_bar.setFocus(focus);
2726
$(window).on("wheel", function (e) {
@@ -35,41 +34,34 @@ class EventHandler {
3534
_this.game.inv_bar.setFocus(focus);
3635
}
3736
});
38-
//Keydown
3937
$(document).on("keydown", function (z) {
4038
_this.keys[z.code] = true;
41-
//Digits
4239
for (var i = 1; i < 10; i++) {
4340
if (z.code === `Digit${i}` && _this.gameState === "gameLock") {
4441
_this.game.inv_bar.setFocus(i - 1);
4542
focus = i - 1;
4643
}
4744
}
48-
//Klawisz Escape
4945
if (z.code === "Escape" && _this.gameState === "inventory") {
5046
_this.setState("menu");
5147
}
52-
//Strzałki
5348
if (z.code === "ArrowUp" && _this.gameState === "chat") {
5449
_this.game.chat.chatGoBack();
5550
}
5651
if (z.code === "ArrowDown" && _this.gameState === "chat") {
5752
_this.game.chat.chatGoForward();
5853
}
59-
//Klawisz Enter
6054
if (z.code === "Enter" && _this.gameState === "chat") {
6155
_this.game.chat.command($(".com_i").val());
6256
$(".com_i").val("");
6357
}
64-
//Klawisz E
6558
if (
6659
z.code === "KeyE" &&
6760
_this.gameState !== "chat" &&
6861
_this.gameState !== "menu"
6962
) {
7063
_this.setState("inventory");
7164
}
72-
//Klawisz T lub /
7365
if (
7466
(z.code === "KeyT" || z.code === "Slash") &&
7567
_this.gameState === "gameLock"
@@ -80,7 +72,6 @@ class EventHandler {
8072
_this.setState("chat");
8173
z.preventDefault();
8274
}
83-
//Klawisz `
8475
if (z.code === "Backquote") {
8576
z.preventDefault();
8677
if (
@@ -96,13 +87,10 @@ class EventHandler {
9687
if (z.code === "Escape" && _this.gameState === "chat") {
9788
_this.setState("menu");
9889
}
99-
100-
//Flying
10190
if (z.code === "KeyF") {
10291
_this.game.flying = !_this.game.flying;
10392
_this.game.socket.emit("fly", _this.game.flying);
10493
}
105-
//Wysyłanie state'u do serwera
10694
if (
10795
_this.controls[z.code] !== undefined &&
10896
_this.gameState === "gameLock"
@@ -111,7 +99,7 @@ class EventHandler {
11199
switch (_this.controls[z.code]) {
112100
case "sprint":
113101
var to = {
114-
fov: _this.game.fov,
102+
fov: _this.game.fov.sprint,
115103
};
116104
new TWEEN.Tween(_this.game.camera)
117105
.to(to, 200)
@@ -129,15 +117,14 @@ class EventHandler {
129117
}
130118
}
131119
});
132-
//Keyup
133120
$(document).on("keyup", function (z) {
134121
delete _this.keys[z.code];
135122
if (_this.controls[z.code] !== undefined) {
136123
_this.game.socket.emit("move", _this.controls[z.code], false);
137124
switch (_this.controls[z.code]) {
138125
case "sprint":
139126
var to = {
140-
fov: _this.game.fov,
127+
fov: _this.game.fov.normal,
141128
};
142129
new TWEEN.Tween(_this.game.camera)
143130
.to(to, 200)
@@ -155,34 +142,27 @@ class EventHandler {
155142
}
156143
}
157144
});
158-
//Play game button
159145
$(".gameOn").on("click", function () {
160146
_this.setState("game");
161147
});
162-
//Window onblur
163148
window.onblur = function () {
164149
Object.keys(_this.controls).forEach(function (el) {
165150
_this.game.socket.emit("move", _this.controls[el], false);
166151
});
167152
};
168-
//Pointerlock
169153
var lockChangeAlert = function () {
170154
if (
171155
document.pointerLockElement === _this.game.canvas ||
172156
document.mozPointerLockElement === _this.game.canvas
173157
) {
174-
//Lock
175158
if (_this.gameState === "game") {
176159
_this.setState("gameLock");
177160
}
178-
} else {
179-
//Unlock
180-
if (
181-
_this.gameState === "gameLock" &&
182-
_this.gameState !== "inventory"
183-
) {
184-
_this.setState("menu");
185-
}
161+
} else if (
162+
_this.gameState === "gameLock" &&
163+
_this.gameState !== "inventory"
164+
) {
165+
_this.setState("menu");
186166
}
187167
};
188168
document.addEventListener("pointerlockchange", lockChangeAlert, false);

0 commit comments

Comments
 (0)