Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
76
NBT/IntArrayTag.cs
Normal file
76
NBT/IntArrayTag.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class IntArrayTag : Tag
|
||||
{
|
||||
public List<int> Value { get; private set; } = new List<int>();
|
||||
|
||||
public IntArrayTag() { }
|
||||
|
||||
private IntArrayTag(List<int> value)
|
||||
{
|
||||
this.Value.AddRange(value);
|
||||
}
|
||||
|
||||
public static IntArrayTag ValueOf(List<int> value)
|
||||
{
|
||||
return new IntArrayTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
int count = data.ReadInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Value.Add(data.ReadInt());
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteInt(Value.Count);
|
||||
foreach (int i in Value)
|
||||
{
|
||||
data.WriteInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.IntArray;
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val) { }
|
||||
|
||||
public override dynamic GetValue() { return null; }
|
||||
|
||||
public override void PrettyPrint(int indent, bool recurse)
|
||||
{
|
||||
string array = string.Join(", ", Value);
|
||||
Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: [{array}]");
|
||||
}
|
||||
|
||||
public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList)
|
||||
{
|
||||
builder.Append($"{(isList ? new string('\t', indent) : "")}[I; {string.Join("I, ", Value)}I]");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
reader.Expect('[');
|
||||
reader.Expect('I');
|
||||
reader.Expect(';');
|
||||
while (reader.Peek() != ']')
|
||||
{
|
||||
Value.Add(int.Parse(reader.ReadNumber()));
|
||||
|
||||
if (reader.Peek() == ',')
|
||||
reader.Next();
|
||||
}
|
||||
reader.Expect('I');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue