-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassets.js
82 lines (67 loc) · 2.5 KB
/
assets.js
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
// Texturepacks
// Consts
const TEXTUREPACK_BASE_DIR = "./assets/texturepacks";
const UNDEFINED_TEXTURE_PATH = "/assets/undefined.png";
class Texturepack {
constructor(friendlyName) {
this.debugName = "Assets";
//Name of the folder where the texturepack is contained
this.friendlyName = friendlyName;
this.name = null;
this.assets = {};
this.textures = [];
}
load() {
let jsonData;
jsonData = loadJson(
`${TEXTUREPACK_BASE_DIR}/${this.friendlyName}/data.json`
);
if (jsonData) {
this.name = jsonData.info.name;
this.assets = jsonData.assets;
}
if (this.assets) {
this.undefinedTexture = loadImage(UNDEFINED_TEXTURE_PATH);
for (var block in this.assets) {
//Loading the actual images to the this.textures dict
this.textures[`${block}_texture`] = loadImage(
`${TEXTUREPACK_BASE_DIR}/${this.friendlyName}/${this.assets[block]}.png`
//Callbacks are bugged...
// //Callback in case of success
// ,(loadedImg) => {
// DEBUG &&
// console.log(
// `[${this.debugName}] Loaded: ${block} texture with id: ${this.assets[block]} successfully!`
// );
// },
// // callback in case of faliure
// () => {
// DEBUG &&
// console.error(
// `[${this.debugName}] An error occurred while loading the texture: ${block} texture with id: ${this.assets[block]}, with filename: ${this.assets[block]}.png`
// );
// }
);
DEBUG &&
console.log(
`[${this.debugName}] Loaded: ${block} texture with id: ${this.assets[block]} successfully!`
);
}
}
}
}
//Default block Class
class Block {
constructor(id, texture, pos, size) {
this.id = id;
this.tile = texture;
this.xx = pos[0];
this.yy = pos[1];
this.size = size;
}
Draw(xx, yy, size = this.size) {
noSmooth();
image(this.tile, xx, yy, size, size);
smooth();
}
}