Implement IntArrayTag

This commit is contained in:
zontreck 2024-05-04 21:40:20 -07:00
parent 5642a7f693
commit 4ee91e762a
3 changed files with 37 additions and 22 deletions

View file

@ -3,6 +3,7 @@ import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
import 'package:libac_flutter/nbt/impl/DoubleTag.dart';
import 'package:libac_flutter/nbt/impl/EndTag.dart';
import 'package:libac_flutter/nbt/impl/FloatTag.dart';
import 'package:libac_flutter/nbt/impl/IntArrayTag.dart';
import 'package:libac_flutter/nbt/impl/IntTag.dart';
import 'package:libac_flutter/nbt/impl/TagLong.dart';
import 'package:libac_flutter/nbt/impl/TagShort.dart';
@ -103,6 +104,10 @@ abstract class Tag {
return new TagLong(value: 0);
case TagType.Float:
return new FloatTag();
case TagType.IntArray:
{
return new IntArrayTag();
}
}
}
}

View file

@ -0,0 +1,32 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class IntArrayTag extends Tag {
List<int> _value = [];
IntArrayTag();
IntArrayTag._(List<int> value) {
_value.addAll(value);
}
@override
void readValue(ByteLayer data) {
int count = data.readInt();
for (int i = 0; i < count; i++) {
_value.add(data.readInt());
}
}
@override
void writeValue(ByteLayer data) {
data.writeInt(_value.length);
for (int i in _value) {
data.writeInt(i);
}
}
@override
TagType getTagType() {
return TagType.IntArray;
}
}

View file

@ -1,22 +0,0 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class TagIntArray extends Tag {
final List<int> value;
TagIntArray({required this.value});
@override
void readValue(ByteLayer data) {
// TODO: implement readValue
}
@override
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.IntArray;
}
}