Obsolete transition and rate, and add end time for relative motion node.

This commit is contained in:
2023-04-18 09:33:47 +08:00
parent 17d620ff0c
commit f4411629e4
7 changed files with 119 additions and 44 deletions

View File

@@ -1,10 +1,10 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Pdt;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using UnsafeIL;
@@ -302,33 +302,47 @@ namespace Cryville.Crtr {
}
#pragma warning restore IDE1006
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
private void LoadFromString(string s) {
if (Node != null)
throw new InvalidOperationException("The motion property can only be set at initialization");
Match m = Regex.Match(s, @"^(.+?)(#(\d+))?(@(.+?))?(\^(.+?))?(\*(.+?))?(:(.+))?$");
Match m = Regex.Match(s, @"^([0-9A-Za-z_]+)(#(\d+))?(.+)?$");
if (!m.Success) throw new ArgumentException("Invalid motion string format");
name = new Identifier(m.Groups[1].Value);
var registry = ChartPlayer.motionRegistry[name];
Node = new MotionNode();
if (m.Groups[3].Success) {
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;
Node = new MotionNode {
Id = id,
Time = time,
Transition = (TransitionType?)trs,
Rate = rate,
Value = value
};
Node.Id = id;
}
else {
Node = new MotionNode {
Value = Vector.Construct(registry.Type, m.Groups[11].Value)
};
if (m.Groups[4].Success) {
_itor.SetSource(m.Groups[4].Value);
while (_itor.Position < _itor.Source.Length) {
var c = _itor.GetChar();
var exp = _itor.GetExp();
switch (c) {
case '@':
ChartPlayer.etor.Evaluate(new VectorOp(v => {
Node.Time = new Vec1(v);
}), exp);
break;
case '!':
ChartPlayer.etor.Evaluate(new VectorOp(v => {
Node.EndTime = new Vec1(v);
}), exp);
break;
case ':':
ChartPlayer.etor.Evaluate(new VectorOp(v => {
Node.Value = Vector.Construct(ChartPlayer.motionRegistry[Name].Type, v);
}), exp);
break;
default:
throw new ArgumentException("Invalid motion string format");
}
}
}
else Node.Reset = true;
SubmitPropSrc("value", new VectorSrc(() => Node.Value));
}
@@ -338,8 +352,7 @@ namespace Cryville.Crtr {
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);
if (node.Rate != null) result += "*" + node.Rate.ToString();
if (node.EndTime != null) result += "~" + node.EndTime.ToString();
if (node.Value != null) result += ":" + node.Value.ToString();
}
else {
@@ -367,10 +380,6 @@ namespace Cryville.Crtr {
[JsonIgnore]
public MotionNode Node;
[DefaultValue(TransitionType.Ease)][Obsolete]
public TransitionType transition = TransitionType.Ease;
[DefaultValue(1.0f)][Obsolete]
public float rate = 1.0f;
[DefaultValue(0.0f)]
public float sumfix = 0.0f;