Skip to content

Commit c6cb4be

Browse files
committed
remove _this and use arrow functions
1 parent 4d4e1c4 commit c6cb4be

File tree

12 files changed

+229
-257
lines changed

12 files changed

+229
-257
lines changed

src/atlasCreator.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,40 @@ var AtlasCreator = class AtlasCreator {
3434
}
3535

3636
firstLoad() {
37-
var _this = this;
38-
fs.readdir(this.loadPath, function (err, files) {
37+
fs.readdir(this.loadPath, (err, files) => {
3938
var totalImages = 0;
40-
files.forEach(function (file) {
39+
files.forEach((file) => {
4140
if (path.extname(file) === ".png") {
4241
totalImages += 1;
4342
}
4443
});
45-
_this.totalImages = totalImages;
46-
files.forEach(function (file) {
47-
var filePath;
48-
filePath = `${_this.loadPath}/${file}`;
44+
this.totalImages = totalImages;
45+
files.forEach((file) => {
46+
var filePath = `${this.loadPath}/${file}`;
4947
if (path.extname(file) === ".png") {
5048
// console.log filePath
51-
_this.addImageToLoad(filePath, file);
49+
this.addImageToLoad(filePath, file);
5250
}
5351
});
5452
});
5553
}
5654

5755
addImageToLoad(filePath, name) {
58-
var _this = this;
5956
var img = new Canvas.Image();
60-
img.onload = function () {
61-
_this.images[name] = img;
62-
_this.loadedImages++;
63-
if (_this.loadedImages === _this.totalImages) {
64-
return _this.forEachToxel();
57+
img.onload = () => {
58+
this.images[name] = img;
59+
this.loadedImages++;
60+
if (this.loadedImages === this.totalImages) {
61+
return this.forEachToxel();
6562
}
6663
};
6764
img.src = filePath;
6865
}
6966

7067
forEachToxel() {
71-
var _this = this;
72-
Object.keys(this.images).forEach(function (name) {
73-
var img;
74-
img = _this.images[name];
75-
_this.addToxelToAtlas(img, name);
68+
Object.keys(this.images).forEach((name) => {
69+
var img = this.images[name];
70+
this.addToxelToAtlas(img, name);
7671
});
7772
return this.updateAtlas();
7873
}

src/client/scripts/AssetLoader.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,42 @@ import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
33

44
class AssetLoader {
55
constructor(init) {
6-
var _this = this;
76
this.assets = {};
8-
$.get("assets/assetLoader.json", function (assets) {
9-
_this.load(assets, function () {
7+
$.get("assets/assetLoader.json", (assets) => {
8+
this.load(assets, function () {
109
console.log("AssetLoader: done loading!");
1110
if (init !== null) {
12-
init(_this);
11+
init(this);
1312
}
1413
});
1514
});
1615
return;
1716
}
1817

1918
load(assets, callback) {
20-
var _this = this;
2119
var textureLoader = new THREE.TextureLoader();
2220
var fbxl = new FBXLoader();
2321
var assetsNumber = 0;
2422
var assetsLoaded = 0;
2523
Object.keys(assets).forEach(function () {
2624
return assetsNumber++;
2725
});
28-
Object.keys(assets).forEach(function (p) {
26+
Object.keys(assets).forEach((p) => {
2927
var img, path, type;
3028
type = assets[p].type;
3129
path = assets[p].path;
3230
if (type === "texture") {
33-
textureLoader.load(path, function (texture) {
34-
_this.assets[p] = texture;
31+
textureLoader.load(path, (texture) => {
32+
this.assets[p] = texture;
3533
assetsLoaded++;
3634
if (assetsLoaded === assetsNumber) {
3735
return callback();
3836
}
3937
});
4038
}
4139
if (type === "text") {
42-
$.get(path, function (data) {
43-
_this.assets[p] = data;
40+
$.get(path, (data) => {
41+
this.assets[p] = data;
4442
assetsLoaded++;
4543
if (assetsLoaded === assetsNumber) {
4644
return callback();
@@ -49,8 +47,8 @@ class AssetLoader {
4947
}
5048
if (type === "image") {
5149
img = new Image();
52-
img.onload = function () {
53-
_this.assets[p] = img;
50+
img.onload = () => {
51+
this.assets[p] = img;
5452
assetsLoaded++;
5553
if (assetsLoaded === assetsNumber) {
5654
return callback();
@@ -59,8 +57,8 @@ class AssetLoader {
5957
img.src = path;
6058
}
6159
if (type === "fbx") {
62-
return fbxl.load(path, function (fbx) {
63-
_this.assets[p] = fbx;
60+
return fbxl.load(path, (fbx) => {
61+
this.assets[p] = fbx;
6462
assetsLoaded++;
6563
if (assetsLoaded === assetsNumber) {
6664
return callback();
@@ -74,6 +72,6 @@ class AssetLoader {
7472
get(assetName) {
7573
return this.assets[assetName];
7674
}
77-
};
75+
}
7876

7977
export { AssetLoader };

src/client/scripts/BlockBreak.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,16 @@ class BlockBreak {
103103
}
104104

105105
startDigging(time) {
106-
var _this = this;
107106
var ile = 0;
108107
if (this.isDigging === false) {
109108
this.isDigging = true;
110-
this.int = setInterval(function () {
109+
this.int = setInterval(() => {
111110
if (ile === 11) {
112-
_this.setState(0);
113-
clearInterval(_this.int);
114-
_this.isDigging = false;
111+
this.setState(0);
112+
clearInterval(this.int);
113+
this.isDigging = false;
115114
} else {
116-
_this.setState(ile);
115+
this.setState(ile);
117116
}
118117
ile++;
119118
}, time / 10);

src/client/scripts/Chat.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
class Chat {
22
constructor(game) {
3-
var _this = this;
43
this.game = game;
54
this.chatDiv = document.querySelector(".chat");
65
this.listen();
76
this.history = [""];
87
this.histState = 0;
9-
$(".com_i").on("input", function () {
10-
_this.history[_this.history.length - 1] = $(".com_i").val();
11-
console.log(_this.history);
8+
$(".com_i").on("input", () => {
9+
this.history[this.history.length - 1] = $(".com_i").val();
10+
console.log(this.history);
1211
});
1312
return;
1413
}
@@ -28,11 +27,10 @@ class Chat {
2827
}
2928

3029
listen() {
31-
var _this = this;
3230
window.addEventListener(
3331
"wheel",
34-
function (e) {
35-
if (_this.game.eh.gameState !== "chat") {
32+
(e) => {
33+
if (this.game.eh.gameState !== "chat") {
3634
e.preventDefault();
3735
}
3836
},

src/client/scripts/DistanceBasedFog.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ class DistanceBasedFog {
1616
}
1717

1818
addShaderToMaterial(material) {
19-
var _this = this;
20-
material.onBeforeCompile = function (shader) {
19+
material.onBeforeCompile = (shader) => {
2120
shader.uniforms.u_viewPos = {
22-
value: _this.view,
21+
value: this.view,
2322
};
2423
shader.uniforms.u_fogColor = {
25-
value: _this.color,
24+
value: this.color,
2625
};
2726
shader.uniforms.u_farnear = {
28-
value: _this.farnear,
27+
value: this.farnear,
2928
};
3029
shader.fragmentShader = [
3130
"uniform vec3 u_viewPos;",

0 commit comments

Comments
 (0)