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 getTagType();
TagType _parentTagType = TagType.End;
TagType get parentTagType => _parentTagType;
void setParentTagType(TagType type) {
_parentTagType = type;
}
void writeValue(ByteLayer data); void writeValue(ByteLayer data);
void readValue(ByteLayer data); void readValue(ByteLayer data);
String? _key; String? _key;

View file

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

View file

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

View file

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