Finished basic implementation

This commit is contained in:
zontreck 2024-05-04 20:19:26 -07:00
parent 7432530c79
commit f9c83a676b
14 changed files with 125 additions and 42 deletions

View file

@ -20,16 +20,11 @@ enum TagType {
}
abstract class Tag {
late TagType type;
int getType() {
return type.byte;
}
TagType getTagType() {
return type;
return getTagType().byte;
}
TagType getTagType();
void writeValue(ByteLayer data);
void readValue(ByteLayer data);
}

View file

@ -4,9 +4,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class ByteTag extends Tag {
final int value;
ByteTag({required this.value}) {
type = TagType.Byte;
}
ByteTag({required this.value});
@override
void readValue(ByteLayer data) {
@ -17,4 +15,9 @@ class ByteTag extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Byte;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagByteArray extends Tag {
final List<int> value;
TagByteArray({required this.value}) {
type = TagType.ByteArray;
}
TagByteArray({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagByteArray extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.ByteArray;
}
}

View file

@ -6,7 +6,6 @@ class TagCompound extends Tag {
TagCompound() {
_value = new Map();
type = TagType.Compound;
}
@override
@ -18,4 +17,30 @@ class TagCompound extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
void put(String name, Tag tag) {
_value[name] = tag;
}
bool contains(String name) {
return _value.containsKey(name);
}
Tag? get(String name) {
if (contains(name))
return _value[name] as Tag;
else {
// Does not exist!
return null;
}
}
void remove(String name) {
_value.remove(name);
}
@override
TagType getTagType() {
return TagType.Compound;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagDouble extends Tag {
final double value;
TagDouble({required this.value}) {
type = TagType.Float;
}
TagDouble({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagDouble extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Double;
}
}

View file

@ -2,13 +2,16 @@ import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class TagEnd extends Tag {
TagEnd() {
type = TagType.End;
}
TagEnd();
@override
void readValue(ByteLayer data) {}
@override
void writeValue(ByteLayer data) {}
@override
TagType getTagType() {
return TagType.End;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagFloat extends Tag {
final double value;
TagFloat({required this.value}) {
type = TagType.Float;
}
TagFloat({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagFloat extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Float;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagInt extends Tag {
final int value;
TagInt({required this.value}) {
type = TagType.Int;
}
TagInt({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagInt extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Int;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagIntArray extends Tag {
final List<int> value;
TagIntArray({required this.value}) {
type = TagType.IntArray;
}
TagIntArray({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagIntArray extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.IntArray;
}
}

View file

@ -3,8 +3,9 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagList extends Tag {
late final List<Tag> _value;
TagType _internalType = TagType.End;
TagList() {
type = TagType.List;
_value = List.empty(growable: true);
}
@ -17,4 +18,33 @@ class TagList extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
void add(Tag tag) {
if (_internalType == TagType.End) {
_value.clear();
_value.add(tag);
_internalType = tag.getTagType();
} else {
if (_internalType == tag.getTagType()) {
_value.add(tag);
}
}
}
void remove(Tag tag) {
_value.remove(tag);
}
void removeAt(int index) {
_value.removeAt(index);
}
int indexOf(Tag tag) {
return _value.indexOf(tag);
}
@override
TagType getTagType() {
return TagType.List;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagLong extends Tag {
final int value;
TagLong({required this.value}) {
type = TagType.Long;
}
TagLong({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagLong extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Long;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagLongArray extends Tag {
final List<int> value;
TagLongArray({required this.value}) {
type = TagType.LongArray;
}
TagLongArray({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagLongArray extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.LongArray;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagShort extends Tag {
final int value;
TagShort({required this.value}) {
type = TagType.Short;
}
TagShort({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagShort extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.Short;
}
}

View file

@ -3,9 +3,7 @@ import 'package:libac_flutter/nbt/Tag.dart';
class TagString extends Tag {
final String value;
TagString({required this.value}) {
type = TagType.String;
}
TagString({required this.value});
@override
void readValue(ByteLayer data) {
@ -16,4 +14,9 @@ class TagString extends Tag {
void writeValue(ByteLayer data) {
// TODO: implement writeValue
}
@override
TagType getTagType() {
return TagType.String;
}
}