Fixed some bugs, generally refining stuff.

This commit is contained in:
CloneTrooper1019
2019-02-04 13:30:33 -06:00
parent ebd56d22a7
commit 2be61916de
23 changed files with 436 additions and 221 deletions

View File

@ -0,0 +1,40 @@
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
{
public class Vector3int16Token : IXmlPropertyToken
{
public string Token => "Vector3int16";
private static string[] Coords = new string[3] { "X", "Y", "Z" };
public bool ReadToken(Property property, XmlNode token)
{
short[] xyz = new short[3];
for (int i = 0; i < 3; i++)
{
string key = Coords[i];
try
{
var coord = token[key];
xyz[i] = short.Parse(coord.InnerText);
}
catch
{
return false;
}
}
short x = xyz[0],
y = xyz[1],
z = xyz[2];
property.Type = PropertyType.Vector3int16;
property.Value = new Vector3int16(x, y, z);
return true;
}
}
}

View File

@ -4,7 +4,7 @@ using System.Xml;
namespace RobloxFiles.XmlFormat
{
static class XmlDataReader
public static class XmlDataReader
{
public static void ReadProperties(Instance instance, XmlNode propsNode)
{
@ -39,7 +39,7 @@ namespace RobloxFiles.XmlFormat
}
}
public static Instance ReadInstance(XmlNode instNode, ref Dictionary<string, Instance> instances)
public static Instance ReadInstance(XmlNode instNode, XmlRobloxFile file = null)
{
// Process the instance itself
if (instNode.Name != "Item")
@ -54,14 +54,14 @@ namespace RobloxFiles.XmlFormat
// The 'referent' attribute is optional, but should be defined if a Ref property needs to link to this Instance.
XmlNode refToken = instNode.Attributes.GetNamedItem("referent");
if (refToken != null && instances != null)
if (refToken != null && file != null)
{
string refId = refToken.InnerText;
if (instances.ContainsKey(refId))
if (file.Instances.ContainsKey(refId))
throw new Exception("XmlDataReader.ReadItem: Got an Item with a duplicate 'referent' attribute!");
instances.Add(refId, inst);
file.Instances.Add(refId, inst);
}
// Process the child nodes of this instance.
@ -73,7 +73,7 @@ namespace RobloxFiles.XmlFormat
}
else if (childNode.Name == "Item")
{
Instance child = ReadInstance(childNode, ref instances);
Instance child = ReadInstance(childNode, file);
child.Parent = inst;
}
}

View File

@ -6,12 +6,6 @@ using System.Xml;
namespace RobloxFiles.XmlFormat
{
public interface IXmlPropertyToken
{
string Token { get; }
bool ReadToken(Property prop, XmlNode token);
}
public static class XmlPropertyTokens
{
public static IReadOnlyDictionary<string, IXmlPropertyToken> Handlers;

View File

@ -47,12 +47,12 @@ namespace RobloxFiles.XmlFormat
{
if (child.Name == "Item")
{
Instance item = XmlDataReader.ReadInstance(child, ref Instances);
Instance item = XmlDataReader.ReadInstance(child, this);
item.Parent = XmlContents;
}
}
// Resolve references for Ref properties.
// Resolve referent properties.
var refProps = Instances.Values
.SelectMany(inst => inst.Properties)
.Where(prop => prop.Type == PropertyType.Ref);