Unify absolute value and relative node of motion event.

This commit is contained in:
2023-04-04 21:18:34 +08:00
parent fd7c1e6635
commit 676d19f452
3 changed files with 25 additions and 29 deletions

View File

@@ -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;
}));
}
}