Adds to the Tag a parent tag reference.
This commit is contained in:
parent
7ec3ea33d1
commit
2ab89defeb
4 changed files with 44 additions and 15 deletions
|
@ -155,6 +155,19 @@ abstract class Tag {
|
||||||
|
|
||||||
TagType getTagType();
|
TagType getTagType();
|
||||||
TagType _parentTagType = TagType.End;
|
TagType _parentTagType = TagType.End;
|
||||||
|
Tag? _parentTag;
|
||||||
|
bool get hasParent => _parentTag != null;
|
||||||
|
void updateParent(Tag? tag) {
|
||||||
|
if (tag == null) {
|
||||||
|
_parentTag = null;
|
||||||
|
setParentTagType(TagType.End);
|
||||||
|
} else {
|
||||||
|
_parentTag = tag;
|
||||||
|
setParentTagType(tag.getTagType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tag? get getParent => _parentTag;
|
||||||
|
|
||||||
TagType get parentTagType => _parentTagType;
|
TagType get parentTagType => _parentTagType;
|
||||||
void setParentTagType(TagType type) {
|
void setParentTagType(TagType type) {
|
||||||
|
|
|
@ -47,7 +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.updateParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag? get(String name) {
|
Tag? get(String name) {
|
||||||
|
@ -114,19 +114,23 @@ 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);
|
value.updateParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addAll(Map<String, Tag> other) {
|
void addAll(Map<String, Tag> other) {
|
||||||
value.addAll(other);
|
value.addAll(other);
|
||||||
updateParent();
|
for (var entries in other.entries) {
|
||||||
|
entries.value.updateParent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addEntries(Iterable<MapEntry<String, Tag>> newEntries) {
|
void addEntries(Iterable<MapEntry<String, Tag>> newEntries) {
|
||||||
value.addEntries(newEntries);
|
value.addEntries(newEntries);
|
||||||
updateParent();
|
for (var entries in newEntries) {
|
||||||
|
entries.value.updateParent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -140,15 +144,10 @@ class CompoundTag extends Tag implements Map<String, Tag> {
|
||||||
value.clear();
|
value.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateParent() {
|
|
||||||
for (MapEntry<String, Tag> Entries in value.entries) {
|
|
||||||
Entries.value.setParentTagType(TagType.Compound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void unsetParent() {
|
void unsetParent() {
|
||||||
for (MapEntry<String, Tag> Entries in value.entries) {
|
for (MapEntry<String, Tag> Entries in value.entries) {
|
||||||
Entries.value.setParentTagType(TagType.End);
|
Entries.value.setParentTagType(TagType.End);
|
||||||
|
Entries.value.updateParent(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,28 +190,30 @@ class CompoundTag extends Tag implements Map<String, Tag> {
|
||||||
@override
|
@override
|
||||||
Tag putIfAbsent(String key, Tag Function() ifAbsent) {
|
Tag putIfAbsent(String key, Tag Function() ifAbsent) {
|
||||||
Tag X = this.value.putIfAbsent(key, ifAbsent);
|
Tag X = this.value.putIfAbsent(key, ifAbsent);
|
||||||
updateParent();
|
X.updateParent(this);
|
||||||
return X;
|
return X;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Tag? remove(Object? key) {
|
Tag? remove(Object? key) {
|
||||||
if (key is Tag && value.containsKey(key))
|
if (key is Tag && value.containsKey(key)) (key).updateParent(null);
|
||||||
(key).setParentTagType(TagType.End);
|
|
||||||
return value.remove(key);
|
return value.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DO NOT USE, Parent will not be updated on child tags when this function is used.
|
||||||
@override
|
@override
|
||||||
void removeWhere(bool Function(String key, Tag value) test) {
|
void removeWhere(bool Function(String key, Tag value) test) {
|
||||||
value.removeWhere(test);
|
value.removeWhere(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DO NOT USE
|
||||||
@override
|
@override
|
||||||
Tag update(String key, Tag Function(Tag value) update,
|
Tag update(String key, Tag Function(Tag value) update,
|
||||||
{Tag Function()? ifAbsent}) {
|
{Tag Function()? ifAbsent}) {
|
||||||
return value.update(key, update);
|
return value.update(key, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DO NOT USE
|
||||||
@override
|
@override
|
||||||
void updateAll(Tag Function(String key, Tag value) update) {
|
void updateAll(Tag Function(String key, Tag value) update) {
|
||||||
value.updateAll(update);
|
value.updateAll(update);
|
||||||
|
|
|
@ -7,6 +7,9 @@ class ListTag extends Tag {
|
||||||
|
|
||||||
ListTag();
|
ListTag();
|
||||||
|
|
||||||
|
TagType get getListTagType =>
|
||||||
|
value.length == 0 ? TagType.End : value[0].getTagType();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void readValue(ByteLayer data) {
|
void readValue(ByteLayer data) {
|
||||||
TagType type = TagType.get(data.readByte());
|
TagType type = TagType.get(data.readByte());
|
||||||
|
@ -40,7 +43,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);
|
tag.updateParent(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +57,11 @@ class ListTag extends Tag {
|
||||||
|
|
||||||
void remove(Tag tag) {
|
void remove(Tag tag) {
|
||||||
value.remove(tag);
|
value.remove(tag);
|
||||||
|
tag.updateParent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeAt(int index) {
|
void removeAt(int index) {
|
||||||
|
value[index].updateParent(null);
|
||||||
value.removeAt(index);
|
value.removeAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +84,16 @@ class ListTag extends Tag {
|
||||||
return value.length;
|
return value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
// Clear the list
|
||||||
|
for (var entry in value) {
|
||||||
|
entry.updateParent(null);
|
||||||
|
entry.setParentTagType(TagType.End);
|
||||||
|
}
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void prettyPrint(int indent, bool recurse) {
|
void prettyPrint(int indent, bool recurse) {
|
||||||
print(
|
print(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_dart
|
name: libac_dart
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.2.072124+0507
|
version: 1.2.072224+0449
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue