Implement LongTag

This commit is contained in:
zontreck 2024-05-04 22:47:52 -07:00
parent dd133afd68
commit 4917419bd3
2 changed files with 29 additions and 20 deletions

View file

@ -5,7 +5,7 @@ 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/LongTag.dart';
import 'package:libac_flutter/nbt/impl/TagShort.dart';
import 'Stream.dart';
@ -76,6 +76,20 @@ abstract class Tag {
}
}
bool equals(dynamic object) {
if (object == null || !(object is Tag)) return false;
Tag tag = object;
if (tag.getType() != getType()) return false;
if (getKey() == null && tag.getKey() != null ||
tag.getKey() == null && getKey() != null) return false;
if (getKey() != null && !(getKey() == tag.getKey())) return false;
return true;
}
static Tag makeTagOfType(TagType type) {
switch (type) {
case TagType.Byte:
@ -102,7 +116,7 @@ abstract class Tag {
case TagType.Int:
return new IntTag();
case TagType.Long:
return new TagLong(value: 0);
return new LongTag();
case TagType.Float:
return new FloatTag();
case TagType.IntArray:
@ -118,17 +132,4 @@ abstract class Tag {
}
}
bool equals(dynamic object) {
if (object == null || !(object is Tag)) return false;
Tag tag = object;
if (tag.getType() != getType()) return false;
if (getKey() == null && tag.getKey() != null ||
tag.getKey() == null && getKey() != null) return false;
if (getKey() != null && !(getKey() == tag.getKey())) return false;
return true;
}
}

View file

@ -1,18 +1,26 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class TagLong extends Tag {
final int value;
TagLong({required this.value});
class LongTag extends Tag {
int _value = 0;
LongTag();
LongTag._(int value) {
_value = value;
}
static LongTag valueOf(int value) {
return LongTag._(value);
}
@override
void readValue(ByteLayer data) {
// TODO: implement readValue
_value = data.readLong();
}
@override
void writeValue(ByteLayer data) {
// TODO: implement writeValue
data.writeLong(_value);
}
@override