Finish implementing CompoundTag
This commit is contained in:
parent
a27248daf9
commit
70f6e16d17
4 changed files with 108 additions and 6 deletions
|
@ -3,10 +3,17 @@ import 'package:libac_flutter/nbt/Tag.dart';
|
|||
|
||||
class ByteArrayTag extends Tag {
|
||||
List<int> _value = [];
|
||||
ByteArrayTag(List<int> value) {
|
||||
|
||||
ByteArrayTag();
|
||||
|
||||
ByteArrayTag._(List<int> value) {
|
||||
_value.addAll(value);
|
||||
}
|
||||
|
||||
static ByteArrayTag valueOf(List<int> value) {
|
||||
return ByteArrayTag._(value);
|
||||
}
|
||||
|
||||
@override
|
||||
void readValue(ByteLayer data) {
|
||||
int len = data.readInt();
|
||||
|
|
|
@ -4,10 +4,16 @@ import 'package:libac_flutter/nbt/Tag.dart';
|
|||
class ByteTag extends Tag {
|
||||
int _value = 0;
|
||||
|
||||
ByteTag(int value) {
|
||||
ByteTag._(int value) {
|
||||
_value = value;
|
||||
}
|
||||
|
||||
ByteTag();
|
||||
|
||||
static ByteTag valueOf(int value) {
|
||||
return ByteTag._(value);
|
||||
}
|
||||
|
||||
@override
|
||||
void readValue(ByteLayer data) {
|
||||
_value = data.readByte();
|
||||
|
|
|
@ -1,21 +1,37 @@
|
|||
import 'package:libac_flutter/nbt/Stream.dart';
|
||||
import 'package:libac_flutter/nbt/Tag.dart';
|
||||
|
||||
class TagCompound extends Tag {
|
||||
class CompoundTag extends Tag {
|
||||
late final Map<String, Tag> _value;
|
||||
|
||||
TagCompound() {
|
||||
CompoundTag() {
|
||||
_value = new Map();
|
||||
}
|
||||
|
||||
@override
|
||||
void readValue(ByteLayer data) {
|
||||
// TODO: implement readValue
|
||||
_value.clear();
|
||||
|
||||
while (true) {
|
||||
Tag tag = Tag.readNamedTag(data);
|
||||
if (tag.getType() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
put(tag.getKey(), tag);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void writeValue(ByteLayer data) {
|
||||
// TODO: implement writeValue
|
||||
Iterator<Tag> it = _value.values.iterator;
|
||||
|
||||
while (it.moveNext()) {
|
||||
Tag tag = it.current;
|
||||
Tag.writeNamedTag(tag, data);
|
||||
}
|
||||
|
||||
data.writeByte(TagType.End.byte);
|
||||
}
|
||||
|
||||
void put(String name, Tag tag) {
|
Loading…
Add table
Add a link
Reference in a new issue