Add animation stub and effect stub for skin.

This commit is contained in:
2023-02-15 18:12:41 +08:00
parent b6e238780e
commit eb6dafbd60
6 changed files with 118 additions and 6 deletions

View File

@@ -13,9 +13,14 @@ namespace Cryville.Crtr {
readonly HashSet<string> a = new HashSet<string>();
readonly List<string> k = new List<string>(2);
protected override object InterpretKey(Type type) {
if (!typeof(SkinElement).IsAssignableFrom(type)) {
if (typeof(SkinElement).IsAssignableFrom(type))
return InterpretSkinElementKey();
else if (typeof(AnimationSpan).IsAssignableFrom(type))
return InterpretAnimationSpanKey();
else
return base.InterpretKey(type);
}
}
object InterpretSkinElementKey() {
s.Clear(); a.Clear(); k.Clear();
bool invalidKeyFlag = false, compKeyFlag = false;
while (true) {
@@ -103,6 +108,59 @@ namespace Cryville.Crtr {
if (Position == pp) throw new FormatException("Invalid selector or key format");
}
}
object InterpretAnimationSpanKey() {
if ((ct & 0x0040) != 0 || cc == ',') {
float start = 0, end = 1;
if (cc != ',') {
start = float.Parse(GetNumber());
ws(); if (cc != ',') throw new FormatException("Invalid span format");
}
GetChar(); ws();
if (cc != '{') end = float.Parse(GetNumber());
ws();
if (cc != '{') throw new FormatException("Invalid span format");
return new Clip(start, end);
}
k.Clear();
while (true) {
int pp = Position;
switch (cc) {
case '.':
GetChar();
if (k.Count != 1)
throw new FormatException("Invalid key format");
k.Add(GetIdentifier());
break;
case ';':
case ':':
switch (k.Count) {
case 1:
return new SkinPropertyKey.SetProperty {
Component = typeof(TransformInterface),
Name = IdentifierManager.SharedInstance.Request(k[0])
};
case 2:
return new SkinPropertyKey.SetProperty {
Component = GetComponentByName(k[0]),
Name = IdentifierManager.SharedInstance.Request(k[1])
};
default:
throw new FormatException("Unknown error"); // Unreachable
}
case '{':
throw new FormatException("Invalid token");
case '}':
throw new FormatException("Invalid token");
default:
if (k.Count != 0)
throw new FormatException("Invalid key format");
k.Add(GetIdentifier());
break;
}
ws();
if (Position == pp) throw new FormatException("Invalid selector or key format");
}
}
static Type GetComponentByName(string name) {
Type result;
if (GenericResources.Components.TryGetValue(name, out result)) return result;