Finish implementing - and testing SNBT
This commit is contained in:
parent
a0f372693b
commit
dfd536ae1c
10 changed files with 57 additions and 3 deletions
|
@ -419,6 +419,9 @@ class StringReader {
|
|||
// Check if there's more to read
|
||||
bool get canRead => _position < _buffer.length;
|
||||
|
||||
// Get the number of chars seeked
|
||||
int get getSeeked => _lastPostion - _position;
|
||||
|
||||
// Read the next character
|
||||
String next() {
|
||||
if (canRead) {
|
||||
|
|
|
@ -44,6 +44,7 @@ enum TagType {
|
|||
static TagType getStringifiedTagType(StringReader reader) {
|
||||
reader.startSeek();
|
||||
TagType ret = TagType.End;
|
||||
bool isNumber = true;
|
||||
|
||||
// Start to determine the next tag type
|
||||
while (reader.canRead && ret == TagType.End) {
|
||||
|
@ -97,6 +98,11 @@ enum TagType {
|
|||
ret = TagType.Float;
|
||||
break;
|
||||
}
|
||||
case "I":
|
||||
{
|
||||
ret = TagType.Int;
|
||||
break;
|
||||
}
|
||||
case "L":
|
||||
{
|
||||
ret = TagType.Long;
|
||||
|
@ -107,6 +113,26 @@ enum TagType {
|
|||
ret = TagType.Short;
|
||||
break;
|
||||
}
|
||||
case "\"":
|
||||
{
|
||||
ret = TagType.String;
|
||||
break;
|
||||
}
|
||||
case ",":
|
||||
case "\n":
|
||||
{
|
||||
if (reader.getSeeked >= 1) ret = TagType.String;
|
||||
if (isNumber) ret = TagType.Int;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (!reader.isDigit(val)) {
|
||||
if (isNumber) isNumber = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ class ByteArrayTag extends Tag {
|
|||
@override
|
||||
void readStringifiedValue(StringReader reader) {
|
||||
reader.expect("[");
|
||||
reader.expect("B");
|
||||
reader.expect(";");
|
||||
while (reader.peek() != "]") {
|
||||
value.add(int.parse(reader.readNumber()));
|
||||
reader.expect("b");
|
||||
|
|
|
@ -198,6 +198,8 @@ class CompoundTag extends Tag implements Map<String, Tag> {
|
|||
while (reader.peek() != "}") {
|
||||
Tag tag = Tag.readStringifiedNamedTag(reader);
|
||||
put(tag.getKey(), tag);
|
||||
|
||||
if (reader.peek() == ",") reader.next();
|
||||
}
|
||||
|
||||
reader.expect("}");
|
||||
|
|
|
@ -55,6 +55,8 @@ class IntArrayTag extends Tag {
|
|||
@override
|
||||
void readStringifiedValue(StringReader reader) {
|
||||
reader.expect("[");
|
||||
reader.expect("I");
|
||||
reader.expect(";");
|
||||
while (reader.peek() != "]") {
|
||||
value.add(int.parse(reader.readNumber()));
|
||||
|
||||
|
|
|
@ -43,5 +43,11 @@ class IntTag extends Tag {
|
|||
void readStringifiedValue(StringReader reader) {
|
||||
String val = reader.readNumber();
|
||||
value = int.parse(val);
|
||||
|
||||
// Since a type indicator is optional for a int, check for a comma
|
||||
if (reader.peek() == ",")
|
||||
return;
|
||||
else
|
||||
reader.expect("i");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,10 @@ class ListTag extends Tag {
|
|||
void readStringifiedValue(StringReader reader) {
|
||||
reader.expect("[");
|
||||
while (reader.peek() != "]") {
|
||||
value.add(Tag.readStringifiedNamedTag(reader));
|
||||
TagType type = TagType.getStringifiedTagType(reader);
|
||||
Tag newTag = Tag.makeTagOfType(type);
|
||||
newTag.readStringifiedValue(reader);
|
||||
add(newTag);
|
||||
|
||||
if (reader.peek() == ",") reader.next();
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ class LongArrayTag extends Tag {
|
|||
@override
|
||||
void readStringifiedValue(StringReader reader) {
|
||||
reader.expect("[");
|
||||
reader.expect("L");
|
||||
reader.expect(";");
|
||||
while (reader.peek() != "]") {
|
||||
value.add(int.parse(reader.readNumber()));
|
||||
reader.expect("l");
|
||||
|
|
|
@ -15,7 +15,10 @@ class PathHelper {
|
|||
}
|
||||
|
||||
bool exists() {
|
||||
return File(build()).existsSync();
|
||||
File fi = File(build());
|
||||
Directory dir = Directory(build());
|
||||
|
||||
return fi.existsSync() || dir.existsSync();
|
||||
}
|
||||
|
||||
PathHelper clone() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:libac_dart/nbt/Stream.dart';
|
|||
import 'package:libac_dart/nbt/Tag.dart';
|
||||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
||||
import 'package:libac_dart/utils/IOTools.dart';
|
||||
import 'package:libac_dart/utils/uuid/NbtUUID.dart';
|
||||
import 'package:libac_dart/utils/uuid/UUID.dart';
|
||||
import 'package:test/expect.dart';
|
||||
|
@ -85,7 +86,10 @@ void main() {
|
|||
SnbtIo.writeToFile(output, ct);
|
||||
|
||||
// Expect that the file exists
|
||||
expect(file.existsSync(), true);
|
||||
PathHelper ph = PathHelper.builder(Directory.current.path)
|
||||
.resolve("build")
|
||||
.resolve("bigtest.snbt");
|
||||
expect(ph.exists(), true);
|
||||
});
|
||||
|
||||
test("Read BigTest from SNBT file", () async {
|
||||
|
@ -93,6 +97,7 @@ void main() {
|
|||
"${Directory.current.path}/build/bigtest.snbt") as CompoundTag;
|
||||
|
||||
expect(tag.containsKey("stringTest"), true);
|
||||
expect(tag.get("doubleTest")!.asDouble(), 0.4931287132182315);
|
||||
});
|
||||
|
||||
test("Write NULL UUID to NBT", () async {
|
||||
|
|
Loading…
Reference in a new issue