general mindustry schematic tools
Diffstat (limited to 'schem_image/main.js')
-rwxr-xr-xschem_image/main.js57
1 files changed, 48 insertions, 9 deletions
diff --git a/schem_image/main.js b/schem_image/main.js
index 25f70e7..96d0800 100755
--- a/schem_image/main.js
+++ b/schem_image/main.js
@@ -1,8 +1,9 @@
-#!/usr/bin/env node
+#!/usr/bin/env -S node --no-warnings
import fs from "fs";
import { Schematic } from "mindustry-schematic-parser";
import { ArgumentParser } from "argparse";
+import clipboard from "clipboardy";
const parser = new ArgumentParser();
@@ -10,7 +11,10 @@ parser.add_argument("--base64", "-b", {
nargs: 1,
type: "string",
});
-parser.add_argument("--file", "-f", {
+parser.add_argument("-c", "--clipboard", {
+ action: "store_true",
+});
+parser.add_argument("--file", {
nargs: 1,
type: "string",
action: "store",
@@ -20,27 +24,62 @@ parser.add_argument("--image", "-i", {
type: "string",
help: "where to output the image",
});
+parser.add_argument("--rename", "-r", {
+ nargs: "+",
+ type: "string",
+ help: "to rename the schematic, and copy the new schematic",
+});
+parser.add_argument("--format", "-f", {
+ action: "store_true",
+});
+
+let base64;
+let file;
const args = parser.parse_args();
-if (!args.file && !args.base64) {
- throw new Error("You must specify either a file or base64");
+
+base64 = args.base64 ? args.base64[0] : "";
+file = args.file ? args.file[0] : "";
+
+if (args.clipboard) {
+ const clip = clipboard.readSync();
+ if (!clip) throw new Error("clipboard empty");
+ base64 = clip;
+}
+
+if (!file && !base64) {
+ throw new Error("file/base64 not specified");
}
let schematic;
-if (args.base64) {
- schematic = Schematic.decode(args.base64[0]);
-} else {
- const buffer = fs.readFileSync(args.file[0]);
+if (base64) {
+ schematic = Schematic.decode(base64);
+} else if (file) {
+ const buffer = fs.readFileSync(file);
schematic = Schematic.decode(buffer);
}
-console.log(schematic.name);
if (args.image) {
+ const opacity = 0.25;
// save a preview of the schematic
schematic
.render({
background: false, // disable background
+ bridges: {
+ opacity: opacity,
+ },
+ phaseBridges: {
+ opacity: opacity,
+ },
})
.then((nodeCanvas) => nodeCanvas.toBuffer())
.then((buffer) => fs.writeFileSync(args.image[0], buffer));
}
+
+if (args.rename) {
+ schematic.name = args.rename.join(" ");
+ if (args.format) clipboard.write(`\`\`\`${schematic.encode()}\`\`\``);
+ else clipboard.write(schematic.encode());
+} else if (args.format) clipboard.write(`\`\`\`${schematic.encode()}\`\`\``);
+
+console.log(schematic.name);