Implement StringTag, run autofix

This commit is contained in:
zontreck 2024-05-04 23:02:03 -07:00
parent 3956dc0ea9
commit 6c83fbc371
6 changed files with 50 additions and 32 deletions

View file

@ -12,6 +12,7 @@ import 'Stream.dart';
import 'impl/ByteTag.dart';
import 'impl/ListTag.dart';
import 'impl/LongArrayTag.dart';
import 'impl/StringTag.dart';
enum TagType {
End(0),
@ -59,7 +60,7 @@ abstract class Tag {
static Tag readNamedTag(ByteLayer data) {
var type = data.readByte();
if (type == 0) {
return new EndTag();
return EndTag();
} else {
Tag tag = makeTagOfType(TagType.get(type));
tag._key = data.readString();
@ -78,63 +79,72 @@ abstract class Tag {
}
bool equals(dynamic object) {
if (object == null || !(object is Tag)) return false;
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;
if (!(getKey() == tag.getKey())) return false;
return true;
}
static Tag makeTagOfType(TagType type) {
switch (type) {
case TagType.Byte:
{
return new ByteTag();
return ByteTag();
}
case TagType.ByteArray:
{
return new ByteArrayTag();
return ByteArrayTag();
}
case TagType.Compound:
{
return new CompoundTag();
return CompoundTag();
}
case TagType.Double:
{
return new DoubleTag();
return DoubleTag();
}
case TagType.End:
return new EndTag();
{
return EndTag();
}
case TagType.Short:
return new ShortTag();
{
return ShortTag();
}
case TagType.Int:
return new IntTag();
{
return IntTag();
}
case TagType.Long:
return new LongTag();
{
return LongTag();
}
case TagType.Float:
return new FloatTag();
{
return FloatTag();
}
case TagType.IntArray:
{
return new IntArrayTag();
return IntArrayTag();
}
case TagType.LongArray:
{
return new LongArrayTag();
return LongArrayTag();
}
case TagType.List:
{
return new ListTag();
return ListTag();
}
case TagType.String:
{
return StringTag();
}
}
}
}
}

View file

@ -2,7 +2,7 @@ import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class ByteArrayTag extends Tag {
List<int> _value = [];
final List<int> _value = [];
ByteArrayTag();

View file

@ -5,7 +5,7 @@ class CompoundTag extends Tag {
late final Map<String, Tag> _value;
CompoundTag() {
_value = new Map();
_value = <String, Tag>{};
}
@override
@ -43,9 +43,9 @@ class CompoundTag extends Tag {
}
Tag? get(String name) {
if (contains(name))
if (contains(name)) {
return _value[name] as Tag;
else {
} else {
// Does not exist!
return null;
}

View file

@ -2,7 +2,7 @@ import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class IntArrayTag extends Tag {
List<int> _value = [];
final List<int> _value = [];
IntArrayTag();
IntArrayTag._(List<int> value) {

View file

@ -2,7 +2,7 @@ import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class LongArrayTag extends Tag {
List<int> _value = [];
final List<int> _value = [];
LongArrayTag();
LongArrayTag._(List<int> lst) {

View file

@ -1,18 +1,26 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class TagString extends Tag {
final String value;
TagString({required this.value});
class StringTag extends Tag {
String _value = "";
StringTag();
StringTag._(String str) {
_value = str;
}
static StringTag valueOf(String str) {
return StringTag._(str);
}
@override
void readValue(ByteLayer data) {
// TODO: implement readValue
_value = data.readString();
}
@override
void writeValue(ByteLayer data) {
// TODO: implement writeValue
data.writeString(_value);
}
@override