Skip to content

Commit 7287b6a

Browse files
committed
use for in instead of forEach
1 parent aa22265 commit 7287b6a

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

src/client/scripts/AssetLoader.js

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,51 @@ class AssetLoader {
2323
var assetsNumber = Object.keys(assets).length;
2424
var assetsLoaded = 0;
2525

26-
Object.keys(assets).forEach((p) => {
27-
var img, path, type;
28-
type = assets[p].type;
29-
path = assets[p].path;
30-
if (type === "texture") {
31-
textureLoader.load(path, (texture) => {
32-
this.assets[p] = texture;
33-
assetsLoaded++;
34-
if (assetsLoaded === assetsNumber) {
35-
return callback();
36-
}
37-
});
38-
}
39-
if (type === "text") {
40-
$.get(path, (data) => {
41-
this.assets[p] = data;
42-
assetsLoaded++;
43-
if (assetsLoaded === assetsNumber) {
44-
return callback();
45-
}
46-
});
47-
}
48-
if (type === "image") {
49-
img = new Image();
50-
img.onload = () => {
51-
this.assets[p] = img;
52-
assetsLoaded++;
53-
if (assetsLoaded === assetsNumber) {
54-
return callback();
55-
}
56-
};
57-
img.src = path;
58-
}
59-
if (type === "fbx") {
60-
return fbxl.load(path, (fbx) => {
61-
this.assets[p] = fbx;
62-
assetsLoaded++;
63-
if (assetsLoaded === assetsNumber) {
64-
return callback();
65-
}
66-
});
26+
for (const assetName in assets) {
27+
let asset = assets[assetName];
28+
var img;
29+
30+
switch (asset.type) {
31+
case "texture":
32+
textureLoader.load(asset.path, (texture) => {
33+
this.assets[assetName] = texture;
34+
assetsLoaded++;
35+
if (assetsLoaded === assetsNumber) {
36+
return callback();
37+
}
38+
});
39+
break;
40+
case "text":
41+
$.get(asset.path, (data) => {
42+
this.assets[assetName] = data;
43+
assetsLoaded++;
44+
if (assetsLoaded === assetsNumber) {
45+
return callback();
46+
}
47+
});
48+
break;
49+
case "image":
50+
img = new Image();
51+
img.onload = () => {
52+
this.assets[assetName] = img;
53+
assetsLoaded++;
54+
if (assetsLoaded === assetsNumber) {
55+
return callback();
56+
}
57+
};
58+
img.src = asset.path;
59+
break;
60+
case "fbx":
61+
fbxl.load(asset.path, (fbx) => {
62+
this.assets[assetName] = fbx;
63+
assetsLoaded++;
64+
if (assetsLoaded === assetsNumber) {
65+
return callback();
66+
}
67+
});
68+
break;
6769
}
68-
});
70+
}
6971
return this;
7072
}
7173

0 commit comments

Comments
 (0)