general mindustry schematic tools
Diffstat (limited to 'schem_image/main.js')
| -rwxr-xr-x | schem_image/main.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/schem_image/main.js b/schem_image/main.js new file mode 100755 index 0000000..25f70e7 --- /dev/null +++ b/schem_image/main.js @@ -0,0 +1,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)); +} |