2019-01-26 00:39:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2019-02-01 17:19:20 +00:00
|
|
|
|
namespace RobloxFiles.DataTypes
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-02-01 18:40:39 +00:00
|
|
|
|
public class NumberSequence
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
|
|
|
|
public readonly NumberSequenceKeypoint[] Keypoints;
|
|
|
|
|
|
2019-11-01 02:40:31 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Join<NumberSequenceKeypoint>(" ", Keypoints);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 00:39:37 +00:00
|
|
|
|
public NumberSequence(float n)
|
|
|
|
|
{
|
|
|
|
|
NumberSequenceKeypoint a = new NumberSequenceKeypoint(0, n);
|
|
|
|
|
NumberSequenceKeypoint b = new NumberSequenceKeypoint(1, n);
|
|
|
|
|
|
|
|
|
|
Keypoints = new NumberSequenceKeypoint[2] { a, b };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NumberSequence(float n0, float n1)
|
|
|
|
|
{
|
|
|
|
|
NumberSequenceKeypoint a = new NumberSequenceKeypoint(0, n0);
|
|
|
|
|
NumberSequenceKeypoint b = new NumberSequenceKeypoint(1, n1);
|
|
|
|
|
|
|
|
|
|
Keypoints = new NumberSequenceKeypoint[2] { a, b };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NumberSequence(NumberSequenceKeypoint[] keypoints)
|
|
|
|
|
{
|
2019-01-29 09:50:55 +00:00
|
|
|
|
int numKeys = keypoints.Length;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-01-29 09:50:55 +00:00
|
|
|
|
if (numKeys < 2)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
throw new Exception("NumberSequence: requires at least 2 keypoints");
|
2019-01-29 09:50:55 +00:00
|
|
|
|
else if (numKeys > 20)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
throw new Exception("NumberSequence: table is too long.");
|
|
|
|
|
|
2019-01-29 09:50:55 +00:00
|
|
|
|
for (int key = 1; key < numKeys; key++)
|
|
|
|
|
if (keypoints[key - 1].Time > keypoints[key].Time)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
throw new Exception("NumberSequence: all keypoints must be ordered by time");
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
var first = keypoints[0];
|
|
|
|
|
var last = keypoints[numKeys - 1];
|
|
|
|
|
|
|
|
|
|
if (!first.Time.FuzzyEquals(0))
|
2019-01-26 00:39:37 +00:00
|
|
|
|
throw new Exception("NumberSequence must start at time=0.0");
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
if (!last.Time.FuzzyEquals(1))
|
2019-01-26 00:39:37 +00:00
|
|
|
|
throw new Exception("NumberSequence must end at time=1.0");
|
|
|
|
|
|
|
|
|
|
Keypoints = keypoints;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 02:40:31 +00:00
|
|
|
|
public NumberSequence(Attribute attr)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2020-09-14 16:20:34 +00:00
|
|
|
|
int numKeys = attr.ReadInt();
|
2019-11-01 02:40:31 +00:00
|
|
|
|
var keypoints = new NumberSequenceKeypoint[numKeys];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numKeys; i++)
|
|
|
|
|
keypoints[i] = new NumberSequenceKeypoint(attr);
|
|
|
|
|
|
|
|
|
|
Keypoints = keypoints;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
2020-09-13 01:16:19 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
int hash = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var keypoint in Keypoints)
|
|
|
|
|
hash ^= keypoint.GetHashCode();
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2021-02-18 19:15:08 +00:00
|
|
|
|
if (!(obj is NumberSequence numberSeq))
|
2020-09-13 01:16:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-02-18 19:15:08 +00:00
|
|
|
|
var otherKeys = numberSeq.Keypoints;
|
2020-09-13 01:16:19 +00:00
|
|
|
|
|
|
|
|
|
if (Keypoints.Length != otherKeys.Length)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Keypoints.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var keyA = Keypoints[i];
|
|
|
|
|
var keyB = otherKeys[i];
|
|
|
|
|
|
|
|
|
|
if (keyA.Equals(keyB))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|