Fix #6, testsuite implemented.

This commit is contained in:
zontreck 2024-05-06 01:16:08 -07:00
parent 270302bb4b
commit b359400c83
16 changed files with 268 additions and 3 deletions

View file

@ -34,4 +34,16 @@ class ByteArrayTag extends Tag {
TagType getTagType() {
return TagType.ByteArray;
}
@override
void prettyPrint(int indent, bool recurse) {
String array = "";
for (int b in value) {
array += "${b}, ";
}
array = array.substring(0, array.length - 2);
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: [${array}]");
}
}

View file

@ -28,4 +28,10 @@ class ByteTag extends Tag {
TagType getTagType() {
return TagType.Byte;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -10,13 +10,24 @@ class CompoundTag extends Tag {
void readValue(ByteLayer data) {
value.clear();
NBTAccountant.visitTag();
NBTAccountant.printRead(this);
while (true) {
Tag tag = Tag.readNamedTag(data);
if (tag.getType() == 0) {
NBTAccountant.leaveTag(this);
return;
}
put(tag.getKey(), tag);
if (tag.getTagType() != TagType.Compound &&
tag.getTagType() != TagType.List) {
NBTAccountant.visitTag();
NBTAccountant.printRead(tag);
NBTAccountant.leaveTag(tag);
}
}
}
@ -34,6 +45,7 @@ class CompoundTag extends Tag {
void put(String name, Tag tag) {
value[name] = tag;
tag.setKey(name);
}
bool contains(String name) {
@ -57,4 +69,20 @@ class CompoundTag extends Tag {
TagType getTagType() {
return TagType.Compound;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: [${value.length} entries]");
print("${"".padLeft(indent, '\t')}{");
if (recurse) {
for (Tag tag in value.values) {
tag.prettyPrint(indent + 1, true);
}
}
}
void endPrettyPrint(int indent) {
print("${"".padLeft(indent, '\t')}}");
}
}

View file

@ -28,4 +28,10 @@ class DoubleTag extends Tag {
TagType getTagType() {
return TagType.Double;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -14,4 +14,9 @@ class EndTag extends Tag {
TagType getTagType() {
return TagType.End;
}
@override
void prettyPrint(int indent, bool recurse) {
print("${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}");
}
}

View file

@ -27,4 +27,10 @@ class FloatTag extends Tag {
TagType getTagType() {
return TagType.Float;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -29,4 +29,16 @@ class IntArrayTag extends Tag {
TagType getTagType() {
return TagType.IntArray;
}
@override
void prettyPrint(int indent, bool recurse) {
String array = "";
for (int b in value) {
array += "${b}, ";
}
array = array.substring(0, array.length - 2);
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: [${array}]");
}
}

View file

@ -27,4 +27,10 @@ class IntTag extends Tag {
TagType getTagType() {
return TagType.Int;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -62,4 +62,18 @@ class ListTag extends Tag {
int size() {
return value.length;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: [${value.length} entries]");
print("${"".padLeft(indent, '\t')}[");
for (Tag tag in value) {
tag.prettyPrint(indent + 1, true);
}
}
void endPrettyPrint(int indent) {
print("${"".padLeft(indent, '\t')}]");
}
}

View file

@ -37,4 +37,16 @@ class LongArrayTag extends Tag {
TagType getTagType() {
return TagType.LongArray;
}
@override
void prettyPrint(int indent, bool recurse) {
String array = "";
for (int b in value) {
array += "${b}, ";
}
array = array.substring(0, array.length - 2);
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: [${array}]");
}
}

View file

@ -27,4 +27,10 @@ class LongTag extends Tag {
TagType getTagType() {
return TagType.Long;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -27,4 +27,10 @@ class ShortTag extends Tag {
TagType getTagType() {
return TagType.Short;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}

View file

@ -27,4 +27,10 @@ class StringTag extends Tag {
TagType getTagType() {
return TagType.String;
}
@override
void prettyPrint(int indent, bool recurse) {
print(
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${value}");
}
}