Initial SNBT implementation

This commit is contained in:
zontreck 2024-05-08 18:52:20 -07:00
parent c10ffc58b8
commit 84b37f8b04
16 changed files with 137 additions and 0 deletions

View file

@ -82,6 +82,38 @@ abstract class Tag {
}
}
static void writeStringifiedNamedTag(
Tag tag, StringBuilder builder, int indents) {
if (tag.getType() != 0) {
if (builder != "") {
// Write name
if (tag.shouldQuoteName()) {
builder.append("${"".padLeft(indents, "\t")}\"${tag.getKey()}\": ");
} else
builder.append("${"".padLeft(indents, '\t')}${tag.getKey()}: ");
}
tag.writeStringifiedValue(builder, indents + 1);
}
}
bool shouldQuoteName() {
if (getKey() == "") {
return false;
} else {
String letters = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < getKey().length; i++) {
String digit = getKey().substring(i, i + 1);
if (letters.indexOf(digit) == -1) {
return true;
}
}
return false;
}
}
void writeStringifiedValue(StringBuilder builder, int indent);
bool equals(dynamic object) {
if (object == null || object is! Tag) return false;