-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse.ts
executable file
·50 lines (43 loc) · 1.4 KB
/
parse.ts
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
#!/usr/bin/env ts-node
/**
* This is a script for parsing the color mappings from MapArtCraft (https://github.com/rebane2001/mapartcraft/blob/master/src/components/mapart/json/coloursJSON.json)
*/
import * as fs from 'fs';
const data = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
const target_version = process.argv[3];
const tupleToRgb = (color: [number, number, number]) => {
const [r, g, b] = color;
return { r, g, b };
};
const final = Object.entries(data as any).reduce((palette: any[], [id, item]: any) => {
palette.push({
id,
colors: [tupleToRgb(item.tonesRGB.light), tupleToRgb(item.tonesRGB.normal), tupleToRgb(item.tonesRGB.dark)],
blocks: Object.values(item.blocks)
.map((block: any) => {
if (!block.validVersions[target_version]) {
return [];
}
let version = block.validVersions[target_version];
if (typeof version === 'string') {
version = block.validVersions[version.replace('&', '')];
}
if (!version) {
return [];
}
return [
{
id: `minecraft:${version.NBTName}`,
attributes: {
flammable: block.flammable,
requires_support: block.supportBlockMandatory
},
properties: version.NBTArgs
}
];
})
.flat()
});
return palette;
}, []);
console.log(JSON.stringify(final));