Expose a parent tag type value

This commit is contained in:
zontreck 2024-06-06 23:42:47 -07:00
parent 2954a1924e
commit bfa54b4804
4 changed files with 32 additions and 2 deletions

View file

@ -147,6 +147,13 @@ abstract class Tag {
}
TagType getTagType();
TagType _parentTagType = TagType.End;
TagType get parentTagType => _parentTagType;
void setParentTagType(TagType type) {
_parentTagType = type;
}
void writeValue(ByteLayer data);
void readValue(ByteLayer data);
String? _key;

View file

@ -20,6 +20,7 @@ class CompoundTag extends Tag implements Map<String, Tag> {
return;
}
tag.setParentTagType(TagType.Compound);
put(tag.getKey(), tag);
/*
if (tag.getTagType() != TagType.Compound &&
@ -46,6 +47,7 @@ class CompoundTag extends Tag implements Map<String, Tag> {
void put(String name, Tag tag) {
value[name] = tag;
tag.setKey(name);
tag.setParentTagType(TagType.Compound);
}
Tag? get(String name) {
@ -104,16 +106,19 @@ class CompoundTag extends Tag implements Map<String, Tag> {
@override
void operator []=(String key, Tag value) {
this.value[key] = value;
value.setParentTagType(TagType.Compound);
}
@override
void addAll(Map<String, Tag> other) {
value.addAll(other);
updateParent();
}
@override
void addEntries(Iterable<MapEntry<String, Tag>> newEntries) {
value.addEntries(newEntries);
updateParent();
}
@override
@ -123,9 +128,22 @@ class CompoundTag extends Tag implements Map<String, Tag> {
@override
void clear() {
unsetParent();
value.clear();
}
void updateParent() {
for (MapEntry<String, Tag> Entries in value.entries) {
Entries.value.setParentTagType(TagType.Compound);
}
}
void unsetParent() {
for (MapEntry<String, Tag> Entries in value.entries) {
Entries.value.setParentTagType(TagType.End);
}
}
@override
bool containsKey(Object? key) {
return value.containsKey(key);
@ -164,11 +182,15 @@ class CompoundTag extends Tag implements Map<String, Tag> {
@override
Tag putIfAbsent(String key, Tag Function() ifAbsent) {
return this.value.putIfAbsent(key, ifAbsent);
Tag X = this.value.putIfAbsent(key, ifAbsent);
updateParent();
return X;
}
@override
Tag? remove(Object? key) {
if (key is Tag && value.containsKey(key))
(key as Tag).setParentTagType(TagType.End);
return value.remove(key);
}

View file

@ -40,6 +40,7 @@ class ListTag extends Tag {
}
if (type == TagType.End || type == tag.getTagType()) {
value.add(tag);
tag.setParentTagType(TagType.List);
}
}

View file

@ -1,6 +1,6 @@
name: libac_dart
description: "Aria's Creations code library"
version: 1.0.32
version: 1.0.33
homepage: "https://zontreck.com"