2019-05-17 12:08:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Xml;
|
2019-02-01 17:19:20 +00:00
|
|
|
|
using RobloxFiles.DataTypes;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2021-02-25 20:09:54 +00:00
|
|
|
|
namespace RobloxFiles.Tokens
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class RayToken : IXmlPropertyToken
|
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
public string XmlPropertyToken => "Ray";
|
|
|
|
|
private static readonly string[] Fields = new string[2] { "origin", "direction" };
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
public bool ReadProperty(Property prop, XmlNode token)
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-02-01 18:40:39 +00:00
|
|
|
|
try
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-02-01 18:40:39 +00:00
|
|
|
|
Vector3[] read = new Vector3[Fields.Length];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < read.Length; i++)
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-02-01 18:40:39 +00:00
|
|
|
|
string field = Fields[i];
|
2019-01-30 06:36:56 +00:00
|
|
|
|
var fieldToken = token[field];
|
2019-02-01 18:40:39 +00:00
|
|
|
|
read[i] = Vector3Token.ReadVector3(fieldToken);
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-19 04:44:51 +00:00
|
|
|
|
Vector3 origin = read[0],
|
2019-02-01 18:40:39 +00:00
|
|
|
|
direction = read[1];
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2019-02-01 18:40:39 +00:00
|
|
|
|
Ray ray = new Ray(origin, direction);
|
|
|
|
|
prop.Type = PropertyType.Ray;
|
|
|
|
|
prop.Value = ray;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2019-02-01 18:40:39 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
Ray ray = prop.CastValue<Ray>();
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
XmlElement origin = doc.CreateElement("origin");
|
|
|
|
|
XmlElement direction = doc.CreateElement("direction");
|
2019-05-19 04:44:51 +00:00
|
|
|
|
|
|
|
|
|
Vector3Token.WriteVector3(doc, origin, ray.Origin);
|
2019-05-17 12:08:06 +00:00
|
|
|
|
Vector3Token.WriteVector3(doc, direction, ray.Direction);
|
2019-05-19 04:44:51 +00:00
|
|
|
|
|
|
|
|
|
node.AppendChild(origin);
|
2019-05-17 12:08:06 +00:00
|
|
|
|
node.AppendChild(direction);
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|