general mindustry schematic tools
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
#!/usr/bin/env node

import fs from "fs";
import { Schematic } from "mindustry-schematic-parser";
import { ArgumentParser } from "argparse";

const parser = new ArgumentParser();

parser.add_argument("--base64", "-b", {
  nargs: 1,
  type: "string",
});
parser.add_argument("--file", "-f", {
  nargs: 1,
  type: "string",
  action: "store",
});
parser.add_argument("--image", "-i", {
  nargs: 1,
  type: "string",
  help: "where to output the image",
});

const args = parser.parse_args();
if (!args.file && !args.base64) {
  throw new Error("You must specify either a file or base64");
}

let schematic;
if (args.base64) {
  schematic = Schematic.decode(args.base64[0]);
} else {
  const buffer = fs.readFileSync(args.file[0]);
  schematic = Schematic.decode(buffer);
}
console.log(schematic.name);

if (args.image) {
  // save a preview of the schematic
  schematic
    .render({
      background: false, // disable background
    })
    .then((nodeCanvas) => nodeCanvas.toBuffer())
    .then((buffer) => fs.writeFileSync(args.image[0], buffer));
}