-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateColorIndex.js
71 lines (60 loc) · 1.7 KB
/
createColorIndex.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
// Read the file and print its contents.
var fs = require('fs');
var mapColors = require("./web/js/map-colors.json");
var mcData = require('minecraft-data')("1.12");
var defaultColors = {
"Light Blue": [112, 108, 138, 255],
"Light Gray": [135, 107, 98, 255],
"White": [209, 177, 161, 255],
"Orange": [159, 82, 36, 255],
"Magenta": [149, 87, 108, 255],
"Yellow": [186, 133, 36, 255],
"Lime": [103, 117, 53, 255],
"Pink": [160, 77, 78, 255],
"Gray": [57, 41, 35, 255],
"Cyan": [87, 92, 92, 255],
"Purple": [122, 73, 88, 255],
"Blue": [76, 62, 92, 255],
"Brown": [76, 50, 35, 255],
"Green": [76, 82, 42, 255],
"Red": [142, 60, 46, 255],
"Black": [37, 22, 16, 255],
"Ore": [112, 112, 112, 255]
}
var unknownColor = [255, 0, 255, 255];
function getColor(blockId){
for(var c in mapColors){
for(var b in mapColors[c].blocks){
if (blockId === mapColors[c].blocks[b]){
return mapColors[c].color;
}
}
}
return null;
}
function inferColor(displayName){
for(var c in defaultColors){
if (displayName.indexOf(c) >= 0){
return defaultColors[c];
}
}
return null
}
var colorIndex = [];
for(var i=0;i<253;i++) {
var color = getColor(i);
if (color !== null){
colorIndex[i] = color;
//console.log("Found color for " +mcData.blocks[i].displayName + " : " +color);
continue;
}
color = inferColor(mcData.blocks[i].displayName);
if (color !== null){
colorIndex[i] = color;
//console.log("Inferred color for " +mcData.blocks[i].displayName + " : " +color);
continue;
}
console.log("Can't find it for "+ i + " " + mcData.blocks[i].displayName)
colorIndex[i] = unknownColor;
}
process.stdout.write(JSON.stringify(colorIndex));