2019-06-08 03:43:28 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace RobloxFiles.BinaryFormat.Chunks
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public class PRNT : IBinaryFileChunk
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public byte Format { get; private set; }
|
|
|
|
|
public int NumRelations { get; private set; }
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public List<int> ChildrenIds { get; private set; }
|
|
|
|
|
public List<int> ParentIds { get; private set; }
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public void LoadFromReader(BinaryRobloxFileReader reader)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
BinaryRobloxFile file = reader.File;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
Format = reader.ReadByte();
|
|
|
|
|
NumRelations = reader.ReadInt32();
|
2019-01-29 09:50:55 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
ChildrenIds = reader.ReadInstanceIds(NumRelations);
|
|
|
|
|
ParentIds = reader.ReadInstanceIds(NumRelations);
|
|
|
|
|
|
2019-01-29 09:50:55 +00:00
|
|
|
|
for (int i = 0; i < NumRelations; i++)
|
|
|
|
|
{
|
|
|
|
|
int childId = ChildrenIds[i];
|
|
|
|
|
int parentId = ParentIds[i];
|
|
|
|
|
|
|
|
|
|
Instance child = file.Instances[childId];
|
2019-05-19 04:44:51 +00:00
|
|
|
|
child.Parent = (parentId >= 0 ? file.Instances[parentId] : file);
|
2019-01-29 09:50:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
public BinaryRobloxFileChunk SaveAsChunk(BinaryRobloxFileWriter writer)
|
|
|
|
|
{
|
|
|
|
|
BinaryRobloxFile file = writer.File;
|
|
|
|
|
writer.StartWritingChunk(this);
|
|
|
|
|
|
|
|
|
|
Format = 0;
|
|
|
|
|
NumRelations = file.Instances.Length;
|
|
|
|
|
|
|
|
|
|
ChildrenIds = new List<int>();
|
|
|
|
|
ParentIds = new List<int>();
|
|
|
|
|
|
|
|
|
|
foreach (Instance inst in file.Instances)
|
|
|
|
|
{
|
|
|
|
|
Instance parent = inst.Parent;
|
|
|
|
|
|
|
|
|
|
int childId = int.Parse(inst.Referent);
|
|
|
|
|
int parentId = -1;
|
|
|
|
|
|
|
|
|
|
if (parent != null)
|
|
|
|
|
parentId = int.Parse(parent.Referent);
|
|
|
|
|
|
|
|
|
|
ChildrenIds.Add(childId);
|
|
|
|
|
ParentIds.Add(parentId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writer.Write(Format);
|
|
|
|
|
writer.Write(NumRelations);
|
|
|
|
|
|
|
|
|
|
writer.WriteInstanceIds(ChildrenIds);
|
|
|
|
|
writer.WriteInstanceIds(ParentIds);
|
|
|
|
|
|
|
|
|
|
return writer.FinishWritingChunk();
|
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|