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.
This commit is contained in:
@ -20,7 +20,6 @@ namespace Roblox.DataTypes
|
||||
|
||||
private static List<BrickColor> ByPalette;
|
||||
private static Dictionary<int, BrickColor> ByNumber;
|
||||
private static Dictionary<string, BrickColor> ByName;
|
||||
|
||||
private static Random RNG = new Random();
|
||||
|
||||
@ -41,20 +40,38 @@ namespace Roblox.DataTypes
|
||||
|
||||
static BrickColor()
|
||||
{
|
||||
ByName = BrickColors.ColorMap.ToDictionary(brickColor => brickColor.Name);
|
||||
Dictionary<string, int> bcSum = new Dictionary<string, int>();
|
||||
|
||||
foreach (BrickColor color in BrickColors.ColorMap)
|
||||
{
|
||||
if (bcSum.ContainsKey(color.Name))
|
||||
{
|
||||
bcSum[color.Name]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
bcSum.Add(color.Name, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ByNumber = BrickColors.ColorMap.ToDictionary(brickColor => brickColor.Number);
|
||||
ByPalette = BrickColors.PaletteMap.Select(number => ByNumber[number]).ToList();
|
||||
}
|
||||
|
||||
public static BrickColor New(string name)
|
||||
public static BrickColor FromName(string name)
|
||||
{
|
||||
if (!ByName.ContainsKey(name))
|
||||
name = DefaultName;
|
||||
BrickColor result = null;
|
||||
var query = BrickColors.ColorMap.Where((bc) => bc.Name == name);
|
||||
|
||||
return ByName[name];
|
||||
if (query.Count() > 0)
|
||||
result = query.First();
|
||||
else
|
||||
result = FromName(DefaultName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static BrickColor New(int number)
|
||||
public static BrickColor FromNumber(int number)
|
||||
{
|
||||
if (!ByNumber.ContainsKey(number))
|
||||
number = DefaultNumber;
|
||||
@ -62,14 +79,14 @@ namespace Roblox.DataTypes
|
||||
return ByNumber[number];
|
||||
}
|
||||
|
||||
public static BrickColor New(Color3 color)
|
||||
public static BrickColor FromColor3(Color3 color)
|
||||
{
|
||||
return New(color.R, color.G, color.B);
|
||||
return FromRGB(color.R, color.G, color.B);
|
||||
}
|
||||
|
||||
public static BrickColor New(float r = 0, float g = 0, float b = 0)
|
||||
public static BrickColor FromRGB(float r = 0, float g = 0, float b = 0)
|
||||
{
|
||||
BrickColor bestMatch = New(-1);
|
||||
BrickColor bestMatch = FromNumber(-1);
|
||||
float closest = float.MaxValue;
|
||||
|
||||
foreach (BrickColor brickColor in BrickColors.ColorMap)
|
||||
@ -106,13 +123,13 @@ namespace Roblox.DataTypes
|
||||
return ByPalette[index];
|
||||
}
|
||||
|
||||
public static BrickColor White() => New("White");
|
||||
public static BrickColor Gray() => New("Medium stone grey");
|
||||
public static BrickColor DarkGray() => New("Dark stone grey");
|
||||
public static BrickColor Black() => New("Black");
|
||||
public static BrickColor Red() => New("Bright red");
|
||||
public static BrickColor Yellow() => New("Bright yellow");
|
||||
public static BrickColor Green() => New("Dark green");
|
||||
public static BrickColor Blue() => New("Bright blue");
|
||||
public static BrickColor White() => FromName("White");
|
||||
public static BrickColor Gray() => FromName("Medium stone grey");
|
||||
public static BrickColor DarkGray() => FromName("Dark stone grey");
|
||||
public static BrickColor Black() => FromName("Black");
|
||||
public static BrickColor Red() => FromName("Bright red");
|
||||
public static BrickColor Yellow() => FromName("Bright yellow");
|
||||
public static BrickColor Green() => FromName("Dark green");
|
||||
public static BrickColor Blue() => FromName("Bright blue");
|
||||
}
|
||||
}
|
@ -24,21 +24,21 @@ namespace Roblox.DataTypes
|
||||
|
||||
public ColorSequence(ColorSequenceKeypoint[] keypoints)
|
||||
{
|
||||
int len = keypoints.Length;
|
||||
int numKeys = keypoints.Length;
|
||||
|
||||
if (len < 2)
|
||||
if (numKeys < 2)
|
||||
throw new Exception("ColorSequence: requires at least 2 keypoints");
|
||||
else if (len > 20)
|
||||
else if (numKeys > 20)
|
||||
throw new Exception("ColorSequence: table is too long.");
|
||||
|
||||
for (int i = 1; i < len; i++)
|
||||
if (keypoints[i-1].Time > keypoints[i].Time)
|
||||
for (int key = 1; key < numKeys; key++)
|
||||
if (keypoints[key - 1].Time > keypoints[key].Time)
|
||||
throw new Exception("ColorSequence: all keypoints must be ordered by time");
|
||||
|
||||
if (keypoints[0].Time < 0)
|
||||
if (Math.Abs(keypoints[0].Time) >= 10e-5f)
|
||||
throw new Exception("ColorSequence must start at time=0.0");
|
||||
|
||||
if (keypoints[len-1].Time > 1)
|
||||
if (Math.Abs(keypoints[numKeys - 1].Time - 1f) >= 10e-5f)
|
||||
throw new Exception("ColorSequence must end at time=1.0");
|
||||
|
||||
Keypoints = keypoints;
|
||||
|
@ -24,21 +24,21 @@ namespace Roblox.DataTypes
|
||||
|
||||
public NumberSequence(NumberSequenceKeypoint[] keypoints)
|
||||
{
|
||||
int len = keypoints.Length;
|
||||
int numKeys = keypoints.Length;
|
||||
|
||||
if (len < 2)
|
||||
if (numKeys < 2)
|
||||
throw new Exception("NumberSequence: requires at least 2 keypoints");
|
||||
else if (len > 20)
|
||||
else if (numKeys > 20)
|
||||
throw new Exception("NumberSequence: table is too long.");
|
||||
|
||||
for (int i = 1; i < len; i++)
|
||||
if (keypoints[i - 1].Time > keypoints[i].Time)
|
||||
for (int key = 1; key < numKeys; key++)
|
||||
if (keypoints[key - 1].Time > keypoints[key].Time)
|
||||
throw new Exception("NumberSequence: all keypoints must be ordered by time");
|
||||
|
||||
if (keypoints[0].Time < 0)
|
||||
if (Math.Abs(keypoints[0].Time) >= 10e-5f)
|
||||
throw new Exception("NumberSequence must start at time=0.0");
|
||||
|
||||
if (keypoints[len - 1].Time > 1)
|
||||
if (Math.Abs(keypoints[numKeys - 1].Time - 1f) >= 10e-5f)
|
||||
throw new Exception("NumberSequence must end at time=1.0");
|
||||
|
||||
Keypoints = keypoints;
|
||||
|
@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using Roblox.Enums;
|
||||
|
||||
namespace Roblox.DataTypes
|
||||
{
|
||||
public struct PathWaypoint
|
||||
{
|
||||
public readonly Vector3 Position;
|
||||
public readonly PathWaypointAction Action;
|
||||
|
||||
public PathWaypoint(Vector3? position)
|
||||
{
|
||||
Position = position ?? Vector3.Zero;
|
||||
Action = PathWaypointAction.Walk;
|
||||
}
|
||||
|
||||
public PathWaypoint(Vector3 position, PathWaypointAction action = PathWaypointAction.Walk)
|
||||
{
|
||||
Position = position;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
Type PathWaypointAction = typeof(PathWaypointAction);
|
||||
return '{' + Position + "} " + Enum.GetName(PathWaypointAction, Action);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,8 @@ namespace Roblox.DataTypes
|
||||
public readonly float Friction;
|
||||
public readonly float Elasticity;
|
||||
|
||||
public float FrictionWeight;
|
||||
public float ElasticityWeight;
|
||||
public readonly float FrictionWeight;
|
||||
public readonly float ElasticityWeight;
|
||||
|
||||
public PhysicalProperties(Material material)
|
||||
{
|
||||
|
Reference in New Issue
Block a user