Unify absolute value and relative node of motion event.
This commit is contained in:
@@ -303,19 +303,20 @@ namespace Cryville.Crtr {
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
private void LoadFromString(string s) {
|
||||
if (RelativeNode != null || AbsoluteValue != null)
|
||||
if (Node != null)
|
||||
throw new InvalidOperationException("The motion property can only be set at initialization");
|
||||
Match m = Regex.Match(s, @"^(.+?)(#(\d+))?(@(.+?))?(\^(.+?))?(\*(.+?))?(:(.+))?$");
|
||||
if (!m.Success) throw new ArgumentException("Invalid motion string format");
|
||||
name = new Identifier(m.Groups[1].Value);
|
||||
var registry = ChartPlayer.motionRegistry[name];
|
||||
if (m.Groups[3].Success) {
|
||||
ushort id = ushort.Parse(m.Groups[3].Value);
|
||||
short id = short.Parse(m.Groups[3].Value);
|
||||
if (id < 0) throw new ArgumentException("Got negative motion node index");
|
||||
Vec1 time = m.Groups[5].Success ? new Vec1(m.Groups[5].Value) : null;
|
||||
byte? trs = m.Groups[7].Success ? byte.Parse(m.Groups[7].Value) : null;
|
||||
Vec1 rate = m.Groups[9].Success ? new Vec1(m.Groups[9].Value) : null;
|
||||
Vector value = m.Groups[11].Success ? Vector.Construct(registry.Type, m.Groups[11].Value) : null;
|
||||
RelativeNode = new MotionNode() {
|
||||
Node = new MotionNode {
|
||||
Id = id,
|
||||
Time = time,
|
||||
Transition = (TransitionType?)trs,
|
||||
@@ -324,18 +325,17 @@ namespace Cryville.Crtr {
|
||||
};
|
||||
}
|
||||
else {
|
||||
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
||||
Node = new MotionNode {
|
||||
Value = Vector.Construct(registry.Type, m.Groups[11].Value)
|
||||
};
|
||||
}
|
||||
SubmitPropSrc("value", new VectorSrc(() => {
|
||||
if (RelativeNode != null) return RelativeNode.Value;
|
||||
else return AbsoluteValue;
|
||||
}));
|
||||
SubmitPropSrc("value", new VectorSrc(() => Node.Value));
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
string result = Name.ToString();
|
||||
if (RelativeNode != null) {
|
||||
var node = RelativeNode;
|
||||
if (Node.Id >= 0) {
|
||||
var node = Node;
|
||||
result += "#" + node.Id;
|
||||
if (node.Time != null) result += "@" + node.Time.ToString();
|
||||
if (node.Transition != null) result = "^" + ((byte)node.Transition).ToString(CultureInfo.InvariantCulture);
|
||||
@@ -343,7 +343,7 @@ namespace Cryville.Crtr {
|
||||
if (node.Value != null) result += ":" + node.Value.ToString();
|
||||
}
|
||||
else {
|
||||
result += ":" + AbsoluteValue.ToString();
|
||||
result += ":" + Node.Value.ToString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -359,16 +359,13 @@ namespace Cryville.Crtr {
|
||||
MotionRegistry reg;
|
||||
if (!ChartPlayer.motionRegistry.TryGetValue(value, out reg))
|
||||
throw new ArgumentException("Invalid motion name");
|
||||
if (RelativeNode != null) RelativeNode.Value = reg.InitValue;
|
||||
else AbsoluteValue = reg.InitValue;
|
||||
Node = new MotionNode { Value = reg.InitValue };
|
||||
name = value;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Vector AbsoluteValue;
|
||||
[JsonIgnore]
|
||||
public MotionNode RelativeNode;
|
||||
public MotionNode Node;
|
||||
|
||||
[DefaultValue(TransitionType.Ease)][Obsolete]
|
||||
public TransitionType transition = TransitionType.Ease;
|
||||
@@ -391,8 +388,7 @@ namespace Cryville.Crtr {
|
||||
}));
|
||||
SubmitPropOp("value", new VectorOp(v => {
|
||||
var vec = Vector.Construct(ChartPlayer.motionRegistry[Name].Type, v);
|
||||
if (RelativeNode != null) RelativeNode.Value = vec;
|
||||
else AbsoluteValue = vec;
|
||||
Node.Value = vec;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@@ -390,26 +390,26 @@ namespace Cryville.Crtr.Event {
|
||||
private void UpdateMotions() {
|
||||
foreach (var m in PlayingMotions) {
|
||||
var tev = (Chart.Motion)m.Key.Unstamped;
|
||||
if (tev.RelativeNode != null && CloneType == 2) continue;
|
||||
if (tev.Node.Id >= 0 && CloneType == 2) continue;
|
||||
var value = GetMotionValue(tev.Name.Key/*, true*/);
|
||||
InvalidateMotion(tev.Name.Key);
|
||||
if (m.Key.Duration == 0) {
|
||||
if (tev.RelativeNode != null) {
|
||||
value.SetRelativeNode(tev.RelativeNode);
|
||||
if (tev.Node.Id >= 0) {
|
||||
value.SetRelativeNode(tev.Node);
|
||||
}
|
||||
else {
|
||||
value.AbsoluteValue.ReplaceFrom(tev.AbsoluteValue);
|
||||
value.AbsoluteValue.ReplaceFrom(tev.Node.Value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var scaledTime = (float)((Time - m.Key.Time - ChartPlayer.actualRenderStep * tev.sumfix) / m.Key.Duration);
|
||||
var lerpedTime = MotionLerper.GetEaseTime(scaledTime, tev.transition, tev.rate);
|
||||
if (tev.RelativeNode != null) {
|
||||
var target = value.QueryRelativeNode(tev.RelativeNode.Id);
|
||||
tev.RelativeNode.LerpWith(m.Value.GetRelativeNode(tev.RelativeNode.Id), lerpedTime, ref target);
|
||||
if (tev.Node.Id >= 0) {
|
||||
var target = value.QueryRelativeNode(tev.Node.Id);
|
||||
tev.Node.LerpWith(m.Value.GetRelativeNode(tev.Node.Id), lerpedTime, ref target);
|
||||
}
|
||||
else {
|
||||
tev.AbsoluteValue.LerpWith(m.Value.AbsoluteValue, lerpedTime, ref value.AbsoluteValue);
|
||||
tev.Node.Value.LerpWith(m.Value.AbsoluteValue, lerpedTime, ref value.AbsoluteValue);
|
||||
}
|
||||
}
|
||||
Values[tev.Name.Key] = value;
|
||||
|
@@ -170,7 +170,7 @@ namespace Cryville.Crtr {
|
||||
dest.RelativeNodes.RemoveRange(tcount, dcount - tcount);
|
||||
}
|
||||
|
||||
public MotionNode GetRelativeNode(ushort id) {
|
||||
public MotionNode GetRelativeNode(short id) {
|
||||
int i = RelativeNodes.FindIndex(n => n.Id == id);
|
||||
if (i == -1) {
|
||||
var r = GetRelativeNode((ushort)(id - 1));
|
||||
@@ -181,7 +181,7 @@ namespace Cryville.Crtr {
|
||||
return RelativeNodes[i];
|
||||
}
|
||||
|
||||
public MotionNode QueryRelativeNode(ushort id) {
|
||||
public MotionNode QueryRelativeNode(short id) {
|
||||
int i = RelativeNodes.FindIndex(n => n.Id == id);
|
||||
MotionNode cnode;
|
||||
if (i == -1) cnode = new MotionNode { Id = id };
|
||||
@@ -256,7 +256,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
public class MotionNode : IComparable<MotionNode> {
|
||||
public ushort Id;
|
||||
public short Id = -1;
|
||||
public Vec1 Time;
|
||||
float CmpTime { get { return Time != null ? Time.Value : 0; } }
|
||||
[Obsolete]
|
||||
|
Reference in New Issue
Block a user