Roblox-File-Format/Core/Property.cs
CloneTrooper1019 08c5032ca8 Generally working out the library's flow.
I've setup a system for supporting multiple implementations for Roblox's
file format. This will allow me to cover the binary format and xml
format under the same general-purpose object.

Haven't done much with the XML format yet, but I've been making some
adjustments to the binary format implementation so that its more evenly
branched out and doesn't retain more information than it needs to. I've
also fixed some issues with the data-types, and documented the Instance
object.
2019-01-29 03:50:55 -06:00

97 lines
2.4 KiB
C#

using System;
namespace Roblox
{
public enum PropertyType
{
Unknown,
String,
Bool,
Int,
Float,
Double,
UDim,
UDim2,
Ray,
Faces,
Axes,
BrickColor,
Color3,
Vector2,
Vector3,
Vector2int16,
CFrame,
Quaternion,
Enum,
Ref,
Vector3int16,
NumberSequence,
ColorSequence,
NumberRange,
Rect,
PhysicalProperties,
Color3uint8,
Int64
}
public class Property
{
public string Name;
public PropertyType Type;
public object Value;
private byte[] RawBuffer = null;
public bool HasRawBuffer
{
get
{
if (RawBuffer == null && Value != null)
{
// Infer what the buffer should be if this is a primitive.
switch (Type)
{
case PropertyType.Int:
RawBuffer = BitConverter.GetBytes((int)Value);
break;
case PropertyType.Int64:
RawBuffer = BitConverter.GetBytes((long)Value);
break;
case PropertyType.Bool:
RawBuffer = BitConverter.GetBytes((bool)Value);
break;
case PropertyType.Float:
RawBuffer = BitConverter.GetBytes((float)Value);
break;
case PropertyType.Double:
RawBuffer = BitConverter.GetBytes((double)Value);
break;
}
}
return (RawBuffer != null);
}
}
public override string ToString()
{
string typeName = Enum.GetName(typeof(PropertyType), Type);
string valueLabel = (Value != null ? Value.ToString() : "null");
if (Type == PropertyType.String)
valueLabel = '"' + valueLabel + '"';
return string.Join(" ", typeName, Name, '=', valueLabel);
}
internal void SetRawBuffer(byte[] buffer)
{
RawBuffer = buffer;
}
public byte[] GetRawBuffer()
{
return RawBuffer;
}
}
}