Adds in a second converter program

This commit is contained in:
zontreck 2024-07-02 23:27:15 -07:00
parent 7cb95a8ae4
commit 416de8c722
5 changed files with 111 additions and 5 deletions

View file

@ -1,5 +1,51 @@
import 'dart:io';
import 'package:libac_dart/argparse/Args.dart';
import 'package:libac_dart/argparse/Builder.dart';
import 'package:libac_dart/argparse/CLIHelper.dart';
import 'package:libac_dart/argparse/types/Bool.dart';
import 'package:libac_dart/argparse/types/String.dart';
import 'package:libac_dart/nbt/NbtIo.dart';
import 'package:libac_dart/nbt/SnbtIo.dart';
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:nbteditor/Consts2.dart';
const HEADER =
"nbt2snbt\nCopyright Piccari Creations 2024 - Tara Piccari\nVersion: ${VERSION}\n\n";
void main(List<String> args) async {
for (int i = 0; i < args.length; i++) {
print("ARG ${i}: ${args[i]}");
Arguments usage = ArgumentsBuilder.builder()
.withArgument(
BoolArgument(name: "help", description: "Print this output"))
.withArgument(StringArgument(
name: "input", value: "%", description: "The input file to convert"))
.withArgument(StringArgument(
name: "out",
value: "%",
description:
"The path to the output file. If not supplied, STDOUT is used."))
.build();
Arguments defaults = Arguments();
Arguments vArgs = await CLIHelper.parseArgs(args, defaults);
if (vArgs.hasArg("help") || vArgs.count == 0) {
print(HEADER);
print(CLIHelper.makeArgCLIHelp(usage));
} else {
if (!vArgs.hasArg("input")) {
print(HEADER);
print("Missing required argument: input");
exit(1);
}
String file = vArgs.getArg("input")!.getValue() as String;
CompoundTag ct = await NbtIo.read(file);
if (!vArgs.hasArg("out")) {
print(SnbtIo.writeToString(ct));
} else {
SnbtIo.writeToFile(vArgs.getArg("out")!.getValue() as String, ct);
print("Wrote SNBT output to file");
}
}
}

55
bin/snbt2nbt.dart Normal file
View file

@ -0,0 +1,55 @@
import 'dart:io';
import 'package:libac_dart/argparse/Args.dart';
import 'package:libac_dart/argparse/Builder.dart';
import 'package:libac_dart/argparse/CLIHelper.dart';
import 'package:libac_dart/argparse/types/Bool.dart';
import 'package:libac_dart/argparse/types/String.dart';
import 'package:libac_dart/nbt/NbtIo.dart';
import 'package:libac_dart/nbt/SnbtIo.dart';
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:nbteditor/Consts2.dart';
const HEADER =
"snbt2nbt\nCopyright Piccari Creations 2024 - Tara Piccari\nVersion: ${VERSION}\n\n";
void main(List<String> args) async {
Arguments usage = ArgumentsBuilder.builder()
.withArgument(
BoolArgument(name: "help", description: "Print this output"))
.withArgument(StringArgument(
name: "input", value: "%", description: "The input file to convert"))
.withArgument(StringArgument(
name: "out", value: "%", description: "The path to the output file."))
.withArgument(BoolArgument(
name: "compress",
description: "If supplied, compresses the output file"))
.build();
Arguments defaults = Arguments();
Arguments vArgs = await CLIHelper.parseArgs(args, defaults);
if (vArgs.hasArg("help") || vArgs.count == 0) {
print(HEADER);
print(CLIHelper.makeArgCLIHelp(usage));
} else {
if (!vArgs.hasArg("input")) {
print(HEADER);
print("Missing required argument: input");
exit(1);
}
String file = vArgs.getArg("input")!.getValue() as String;
CompoundTag ct = await SnbtIo.readFromFile(file) as CompoundTag;
if (!vArgs.hasArg("out")) {
print("Missing required argument: out");
exit(2);
} else {
if (!vArgs.hasArg("compress"))
NbtIo.write(vArgs.getArg("out")!.getValue() as String, ct);
else
NbtIo.writeCompressed(vArgs.getArg("out")!.getValue() as String, ct);
print("Wrote NBT output to file");
}
}
}

5
compile.sh Normal file → Executable file
View file

@ -1,4 +1,7 @@
#!/bin/bash
flutter build linux
dart compile exe -o out/nbt2snbt bin/nbt2snbt.dart
dart compile exe -o out/nbt2snbt bin/nbt2snbt.dart
rm out/*.snbt
rm out/*.nbt

1
lib/Consts2.dart Normal file
View file

@ -0,0 +1 @@
const VERSION = "0.070224.2317";

View file

@ -1,7 +1,8 @@
name: nbteditor
description: A Minecraft NBT Editor written in Flutter
publish_to: 'none'
version: 0.070224.2047
version: 0.070224.2238
environment:
sdk: '>=3.1.5 <4.0.0'
@ -15,7 +16,7 @@ dependencies:
flutter_treeview: ^1.0.7+1
libac_dart:
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
version: 1.0.37
version: 1.1.070224+2232
dev_dependencies:
flutter_test: