-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockbench_cli.js
More file actions
98 lines (89 loc) · 3.24 KB
/
blockbench_cli.js
File metadata and controls
98 lines (89 loc) · 3.24 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(function () {
function errorLog(msg) {
process.stdout.write(`ERROR: ${msg}\n`);
}
function infoLog(msg) {
process.stdout.write(`INFO: ${msg}\n`);
}
function exportModel() {
if (app.commandLine.hasSwitch("cli-model-path")) {
hasExportedSomething = true;
let exportModelPath = app.commandLine.getSwitchValue("cli-model-path");
let exportModelCodec = app.commandLine.getSwitchValue("cli-model-codec");
if (!exportModelCodec || !Codecs[exportModelCodec]) {
errorLog(`"${exportModelCodec}" is an invalid model codec, available codecs: ${Object.keys(Codecs)}`);
return true;
}
infoLog(`Exporting model with "${exportModelCodec}" codec to "${exportModelPath}"...`);
Blockbench.writeFile(
exportModelPath,
{
content: Codecs[exportModelCodec].compile()
},
cb => infoLog(`Model exported!`)
);
return true;
}
return false;
}
function exportTexture() {
if (app.commandLine.hasSwitch("cli-texture-path")) {
let texturePath = app.commandLine.getSwitchValue("cli-texture-path");
if (Texture.all.length == 0) {
errorLog("There isn't a texture in this model.");
return true;
}
if (Texture.all.length > 1) {
errorLog("More than one texture is not supported right now.");
return true;
}
infoLog(`Exporting the texture to "${texturePath}"...`);
Blockbench.writeFile(
texturePath,
{
content: Buffer.from(Texture.all[0].getBase64(), "base64"),
savetype: 'blob'
},
cb => infoLog("Texture exported!")
);
}
return false;
}
function exportAnimations() {
if (app.commandLine.hasSwitch("cli-animation-path")) {
let texturePath = app.commandLine.getSwitchValue("cli-animation-path");
if (Animation.all.length == 0) {
errorLog("There isn't any animation in this model.");
return true;
}
Blockbench.writeFile(
texturePath,
{
content: compileJSON(Animator.buildFile())
},
cb => infoLog("Animation exported!")
);
return true;
}
return false;
}
Plugin.register('blockbench_cli', {
title: 'Blockbench CLI',
author: 'xQuickGlare',
description: '(WIP) A small addon that adds some CLI options to Blockbench',
icon: 'file_download',
version: '0.0.1',
variant: 'both',
onload() {
Codecs.project.on('parsed', data => {
let hasExportedSomething = false;
hasExportedSomething |= exportModel();
hasExportedSomething |= exportTexture();
hasExportedSomething |= exportAnimations();
if (hasExportedSomething) {
app.exit();
}
});
}
});
})();