Added support for saving XML files!

Support for binary files will be coming later.
This commit is contained in:
CloneTrooper1019
2019-05-17 07:08:06 -05:00
parent 45a84e34d0
commit 34642f5656
40 changed files with 838 additions and 113 deletions

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -6,10 +7,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
public class AxesToken : IXmlPropertyToken
{
public string Token => "Axes";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
bool success = XmlPropertyTokens.ReadTokenGeneric<uint>(prop, PropertyType.Axes, token);
bool success = XmlPropertyTokens.ReadPropertyGeneric<uint>(prop, PropertyType.Axes, token);
if (success)
{
@ -27,5 +27,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
XmlElement axes = doc.CreateElement("axes");
node.AppendChild(axes);
int value = (int)prop.Value;
axes.InnerText = value.ToInvariantString();
}
}
}

View File

@ -7,10 +7,10 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "BinaryString";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
// BinaryStrings are encoded in base64
string base64 = token.InnerText;
string base64 = token.InnerText.Replace("\n", "");
prop.Type = PropertyType.String;
prop.Value = base64;
@ -19,5 +19,28 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
byte[] data = prop.GetRawBuffer();
string value = Convert.ToBase64String(data);
if (value.Length > 72)
{
string buffer = "";
while (value.Length > 72)
{
string chunk = value.Substring(0, 72);
value = value.Substring(72);
buffer += chunk + '\n';
}
value = buffer + value;
}
XmlCDataSection cdata = doc.CreateCDataSection(value);
node.AppendChild(cdata);
}
}
}

View File

@ -6,9 +6,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "bool";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
return XmlPropertyTokens.ReadTokenGeneric<bool>(prop, PropertyType.Bool, token);
return XmlPropertyTokens.ReadPropertyGeneric<bool>(prop, PropertyType.Bool, token);
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
string boolString = prop.Value
.ToString()
.ToLower();
node.InnerText = boolString;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -10,16 +11,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
// Since BrickColors are written as ints, the IntToken class will try to redirect
// to this handler if it believes that its representing a BrickColor.
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
bool success = XmlPropertyTokens.ReadTokenGeneric<int>(prop, PropertyType.BrickColor, token);
bool success = XmlPropertyTokens.ReadPropertyGeneric<int>(prop, PropertyType.BrickColor, token);
if (success)
{
int value = (int)prop.Value;
try
{
BrickColor brickColor = BrickColor.FromNumber(value);
prop.XmlToken = "BrickColor";
prop.Value = brickColor;
}
catch
@ -28,8 +31,19 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
success = false;
}
}
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
BrickColor value = prop.Value as BrickColor;
XmlElement brickColor = doc.CreateElement("int");
brickColor.InnerText = value.Number.ToInvariantString();
brickColor.SetAttribute("name", prop.Name);
brickColor.AppendChild(node);
}
}
}

View File

@ -19,7 +19,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
try
{
var coord = token[key];
components[i] = float.Parse(coord.InnerText);
components[i] = Formatting.ParseFloat(coord.InnerText);
}
catch
{
@ -30,18 +30,35 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return new CFrame(components);
}
public bool ReadToken(Property property, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
CFrame result = ReadCFrame(token);
bool success = (result != null);
if (success)
{
property.Type = PropertyType.CFrame;
property.Value = result;
prop.Type = PropertyType.CFrame;
prop.Value = result;
}
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
CFrame cf = prop.Value as CFrame;
float[] components = cf.GetComponents();
for (int i = 0; i < 12; i++)
{
string coordName = Coords[i];
float coordValue = components[i];
XmlElement coord = doc.CreateElement(coordName);
coord.InnerText = coordValue.ToInvariantString();
node.AppendChild(coord);
}
}
}
}

View File

@ -9,7 +9,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
public string Token => "Color3";
private string[] Fields = new string[3] { "R", "G", "B" };
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
bool success = true;
float[] fields = new float[Fields.Length];
@ -21,7 +21,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
try
{
var coord = token[key];
fields[i] = XmlPropertyTokens.ParseFloat(coord.InnerText);
fields[i] = Formatting.ParseFloat(coord.InnerText);
}
catch
{
@ -43,10 +43,35 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
// Try falling back to the Color3uint8 technique...
var color3uint8 = XmlPropertyTokens.GetHandler<Color3uint8Token>();
success = color3uint8.ReadToken(prop, token);
success = color3uint8.ReadProperty(prop, token);
}
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
if (prop.Name == "Color3uint8")
{
var handler = XmlPropertyTokens.GetHandler<Color3uint8Token>();
handler.WriteProperty(prop, doc, node);
}
else
{
Color3 color = prop.Value as Color3;
float[] rgb = new float[3] { color.R, color.G, color.B };
for (int i = 0; i < 3; i++)
{
string field = Fields[i];
float value = rgb[i];
XmlElement channel = doc.CreateElement(field);
channel.InnerText = value.ToInvariantString();
node.AppendChild(channel);
}
}
}
}
}

View File

@ -8,9 +8,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "Color3uint8";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
bool success = XmlPropertyTokens.ReadTokenGeneric<uint>(prop, PropertyType.Color3, token);
bool success = XmlPropertyTokens.ReadPropertyGeneric<uint>(prop, PropertyType.Color3, token);
if (success)
{
@ -25,5 +25,17 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Color3 color = prop.Value as Color3;
uint r = (uint)(color.R * 256);
uint g = (uint)(color.G * 256);
uint b = (uint)(color.B * 256);
uint rgb = (255u << 24) | (r << 16) | (g << 8) | b;
node.InnerText = rgb.ToString();
}
}
}

View File

@ -7,7 +7,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "ColorSequence";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText.Trim();
string[] buffer = contents.Split(' ');
@ -23,11 +23,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
for (int i = 0; i < length; i += 5)
{
float Time = float.Parse(buffer[i]);
float Time = Formatting.ParseFloat(buffer[i]);
float R = float.Parse(buffer[i + 1]);
float G = float.Parse(buffer[i + 2]);
float B = float.Parse(buffer[i + 3]);
float R = Formatting.ParseFloat(buffer[i + 1]);
float G = Formatting.ParseFloat(buffer[i + 2]);
float B = Formatting.ParseFloat(buffer[i + 3]);
Color3 Value = new Color3(R, G, B);
keypoints[i / 5] = new ColorSequenceKeypoint(Time, Value);
@ -44,5 +44,10 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return valid;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString() + ' ';
}
}
}

View File

@ -7,7 +7,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "Content";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string content = token.InnerText;
prop.Type = PropertyType.String;
@ -28,5 +28,21 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
string content = prop.Value.ToString();
string type = "null";
if (prop.HasRawBuffer)
type = "binary";
else if (content.Length > 0)
type = "url";
XmlElement contentType = doc.CreateElement(type);
contentType.InnerText = content;
node.AppendChild(contentType);
}
}
}

View File

@ -6,9 +6,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "double";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
return XmlPropertyTokens.ReadTokenGeneric<double>(prop, PropertyType.Double, token);
return XmlPropertyTokens.ReadPropertyGeneric<double>(prop, PropertyType.Double, token);
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToInvariantString();
}
}
}

View File

@ -6,9 +6,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "token";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
return XmlPropertyTokens.ReadTokenGeneric<uint>(prop, PropertyType.Enum, token);
return XmlPropertyTokens.ReadPropertyGeneric<uint>(prop, PropertyType.Enum, token);
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString();
}
}
}

View File

@ -7,9 +7,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "Faces";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
bool success = XmlPropertyTokens.ReadTokenGeneric<uint>(prop, PropertyType.Faces, token);
bool success = XmlPropertyTokens.ReadPropertyGeneric<uint>(prop, PropertyType.Faces, token);
if (success)
{
@ -27,5 +27,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
XmlElement faces = doc.CreateElement("faces");
node.AppendChild(faces);
int value = (int)prop.Value;
faces.InnerText = value.ToInvariantString();
}
}
}

View File

@ -6,19 +6,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "float";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
try
{
float value = XmlPropertyTokens.ParseFloat(token.InnerText);
prop.Type = PropertyType.Float;
prop.Value = value;
return true;
}
catch
{
return false;
}
return XmlPropertyTokens.ReadPropertyGeneric<float>(prop, PropertyType.Float, token);
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToInvariantString();
}
}
}

View File

@ -6,7 +6,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "int";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
// BrickColors are represented by ints, see if
// we can infer when they should be a BrickColor.
@ -14,12 +14,19 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
if (prop.Name.Contains("Color") || prop.Instance.ClassName.Contains("Color"))
{
var brickColorToken = XmlPropertyTokens.GetHandler<BrickColorToken>();
return brickColorToken.ReadToken(prop, token);
return brickColorToken.ReadProperty(prop, token);
}
else
{
return XmlPropertyTokens.ReadTokenGeneric<int>(prop, PropertyType.Int, token);
return XmlPropertyTokens.ReadPropertyGeneric<int>(prop, PropertyType.Int, token);
}
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToInvariantString();
}
}
}

View File

@ -6,9 +6,14 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "int64";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
return XmlPropertyTokens.ReadTokenGeneric<long>(prop, PropertyType.Int64, token);
return XmlPropertyTokens.ReadPropertyGeneric<long>(prop, PropertyType.Int64, token);
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString();
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -7,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "NumberRange";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText.Trim();
string[] buffer = contents.Split(' ');
@ -17,8 +18,8 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
try
{
float min = float.Parse(buffer[0]);
float max = float.Parse(buffer[1]);
float min = Formatting.ParseFloat(buffer[0]);
float max = Formatting.ParseFloat(buffer[1]);
prop.Type = PropertyType.NumberRange;
prop.Value = new NumberRange(min, max);
@ -31,5 +32,10 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return valid;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString() + ' ';
}
}
}

View File

@ -7,7 +7,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "NumberSequence";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText.Trim();
string[] buffer = contents.Split(' ');
@ -23,9 +23,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
for (int i = 0; i < length; i += 3)
{
float Time = float.Parse(buffer[ i ]);
float Value = float.Parse(buffer[i + 1]);
float Envelope = float.Parse(buffer[i + 2]);
float Time = Formatting.ParseFloat(buffer[ i ]);
float Value = Formatting.ParseFloat(buffer[i + 1]);
float Envelope = Formatting.ParseFloat(buffer[i + 2]);
keypoints[i / 3] = new NumberSequenceKeypoint(Time, Value, Envelope);
}
@ -41,5 +41,10 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return valid;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString() + ' ';
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Xml;
using RobloxFiles.DataTypes;
@ -17,10 +18,10 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
});
}
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
var readBool = createReader(bool.Parse, token);
var readFloat = createReader(XmlPropertyTokens.ParseFloat, token);
var readFloat = createReader(Formatting.ParseFloat, token);
try
{
@ -46,5 +47,40 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return false;
}
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
bool hasCustomPhysics = (prop.Value != null);
XmlElement customPhysics = doc.CreateElement("CustomPhysics");
customPhysics.InnerText = hasCustomPhysics
.ToString()
.ToLower();
node.AppendChild(customPhysics);
if (hasCustomPhysics)
{
var customProps = prop.Value as PhysicalProperties;
var data = new Dictionary<string, float>()
{
{ "Density", customProps.Density },
{ "Friction", customProps.Friction },
{ "Elasticity", customProps.Elasticity },
{ "FrictionWeight", customProps.FrictionWeight },
{ "ElasticityWeight", customProps.ElasticityWeight }
};
foreach (string elementType in data.Keys)
{
float value = data[elementType];
XmlElement element = doc.CreateElement(elementType);
element.InnerText = value.ToInvariantString();
node.AppendChild(element);
}
}
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -8,7 +9,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
public string Token => "Ray";
private static string[] Fields = new string[2] { "origin", "direction" };
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
try
{
@ -35,5 +36,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return false;
}
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Ray ray = prop.Value as Ray;
XmlElement origin = doc.CreateElement("origin");
Vector3Token.WriteVector3(doc, origin, ray.Origin);
node.AppendChild(origin);
XmlElement direction = doc.CreateElement("direction");
Vector3Token.WriteVector3(doc, direction, ray.Direction);
node.AppendChild(direction);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -8,7 +9,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
public string Token => "Rect2D";
private static string[] Fields = new string[2] { "min", "max" };
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
try
{
@ -35,5 +36,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return false;
}
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Rect rect = prop.Value as Rect;
XmlElement min = doc.CreateElement("min");
Vector2Token.WriteVector2(doc, min, rect.Min);
node.AppendChild(min);
XmlElement max = doc.CreateElement("max");
Vector2Token.WriteVector2(doc, max, rect.Max);
node.AppendChild(max);
}
}
}

View File

@ -6,7 +6,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "Ref";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string refId = token.InnerText;
prop.Type = PropertyType.Ref;
@ -14,5 +14,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
string result = "null";
if (prop.Value != null && prop.Value.ToString() != "null")
{
Instance inst = prop.Value as Instance;
result = inst.XmlReferent;
}
node.InnerText = result;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using System.Xml;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -7,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "SharedString";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText;
prop.Type = PropertyType.SharedString;
@ -15,5 +16,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
var BinaryStringToken = XmlPropertyTokens.GetHandler<BinaryStringToken>();
BinaryStringToken.WriteProperty(prop, doc, node);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using System.Xml;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -7,16 +8,28 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "string; ProtectedString";
public bool ReadToken(Property prop, XmlNode token)
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText;
prop.Type = PropertyType.String;
prop.Value = contents;
byte[] buffer = Encoding.UTF8.GetBytes(contents);
prop.SetRawBuffer(buffer);
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
string value = prop.Value.ToInvariantString();
if (value.Contains("\r") || value.Contains("\n"))
{
XmlCDataSection cdata = doc.CreateCDataSection(value);
node.AppendChild(cdata);
}
else
{
node.InnerText = value;
}
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -12,7 +13,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
try
{
XmlElement scaleToken = token[prefix + 'S'];
float scale = XmlPropertyTokens.ParseFloat(scaleToken.InnerText);
float scale = Formatting.ParseFloat(scaleToken.InnerText);
XmlElement offsetToken = token[prefix + 'O'];
int offset = int.Parse(offsetToken.InnerText);
@ -25,7 +26,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
}
}
public bool ReadToken(Property property, XmlNode token)
public static void WriteUDim(XmlDocument doc, XmlNode node, UDim value, string prefix = "")
{
XmlElement scale = doc.CreateElement(prefix + 'S');
scale.InnerText = value.Scale.ToInvariantString();
node.AppendChild(scale);
XmlElement offset = doc.CreateElement(prefix + 'O');
offset.InnerText = value.Offset.ToInvariantString();
node.AppendChild(offset);
}
public bool ReadProperty(Property property, XmlNode token)
{
UDim result = ReadUDim(token);
bool success = (result != null);
@ -38,5 +50,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
UDim value = prop.Value as UDim;
WriteUDim(doc, node, value);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -7,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
public string Token => "UDim2";
public bool ReadToken(Property property, XmlNode token)
public bool ReadProperty(Property property, XmlNode token)
{
UDim xUDim = UDimToken.ReadUDim(token, "X");
UDim yUDim = UDimToken.ReadUDim(token, "Y");
@ -22,5 +23,16 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return false;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
UDim2 value = prop.Value as UDim2;
UDim xUDim = value.X;
UDimToken.WriteUDim(doc, node, xUDim, "X");
UDim yUDim = value.Y;
UDimToken.WriteUDim(doc, node, yUDim, "Y");
}
}
}

View File

@ -20,7 +20,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
var coord = token[key];
string text = coord.InnerText;
xy[i] = XmlPropertyTokens.ParseFloat(text);
xy[i] = Formatting.ParseFloat(text);
}
catch
{
@ -31,7 +31,18 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return new Vector2(xy);
}
public bool ReadToken(Property property, XmlNode token)
public static void WriteVector2(XmlDocument doc, XmlNode node, Vector2 value)
{
XmlElement x = doc.CreateElement("X");
x.InnerText = value.X.ToInvariantString();
node.AppendChild(x);
XmlElement y = doc.CreateElement("Y");
y.InnerText = value.Y.ToInvariantString();
node.AppendChild(y);
}
public bool ReadProperty(Property property, XmlNode token)
{
Vector2 result = ReadVector2(token);
bool success = (result != null);
@ -44,5 +55,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Vector2 value = prop.Value as Vector2;
WriteVector2(doc, node, value);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
@ -19,7 +20,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
try
{
var coord = token[key];
xyz[i] = XmlPropertyTokens.ParseFloat(coord.InnerText);
xyz[i] = Formatting.ParseFloat(coord.InnerText);
}
catch
{
@ -30,7 +31,22 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return new Vector3(xyz);
}
public bool ReadToken(Property property, XmlNode token)
public static void WriteVector3(XmlDocument doc, XmlNode node, Vector3 value)
{
XmlElement x = doc.CreateElement("X");
x.InnerText = value.X.ToInvariantString();
node.AppendChild(x);
XmlElement y = doc.CreateElement("Y");
y.InnerText = value.Y.ToInvariantString();
node.AppendChild(y);
XmlElement z = doc.CreateElement("Z");
z.InnerText = value.Z.ToInvariantString();
node.AppendChild(z);
}
public bool ReadProperty(Property property, XmlNode token)
{
Vector3 result = ReadVector3(token);
bool success = (result != null);
@ -43,5 +59,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return success;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Vector3 value = prop.Value as Vector3;
WriteVector3(doc, node, value);
}
}
}

View File

@ -8,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
public string Token => "Vector3int16";
private static string[] Coords = new string[3] { "X", "Y", "Z" };
public bool ReadToken(Property property, XmlNode token)
public bool ReadProperty(Property property, XmlNode token)
{
short[] xyz = new short[3];
@ -36,5 +36,22 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
Vector3int16 value = prop.Value as Vector3int16;
XmlElement x = doc.CreateElement("X");
x.InnerText = value.X.ToString();
node.AppendChild(x);
XmlElement y = doc.CreateElement("Y");
y.InnerText = value.Y.ToString();
node.AppendChild(y);
XmlElement z = doc.CreateElement("Z");
z.InnerText = value.Z.ToString();
node.AppendChild(z);
}
}
}