Add chart compatibility handler.

This commit is contained in:
2023-04-19 15:32:16 +08:00
parent 56fd0936bb
commit b51c7d2352
4 changed files with 135 additions and 35 deletions

View File

@@ -242,6 +242,7 @@ namespace Cryville.Crtr {
}
}
[JsonConverter(typeof(ChartCompatibilityHandler))]
public class Chart : EventContainer {
[JsonRequired]
public long format; // Format Version
@@ -308,40 +309,7 @@ namespace Cryville.Crtr {
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, @"^([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");
Node.Id = id;
}
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(_vecop, exp);
Node.Time = new Vec1(_vecbuf);
break;
case '~':
ChartPlayer.etor.Evaluate(_vecop, exp);
Node.EndTime = new Vec1(_vecbuf);
break;
case ':':
ChartPlayer.etor.Evaluate(_vecop, exp);
Node.Value = Vector.Construct(ChartPlayer.motionRegistry[Name].Type, _vecbuf);
break;
default:
throw new ArgumentException("Invalid motion string format");
}
}
}
else Node.Reset = true;
ChartCompatibilityHandler.MotionStringParser.Parse(s, out name, out Node);
SubmitPropSrc("value", new VectorSrc(() => Node.Value));
}