Support extra annotations on skin property key. Code cleanup.
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Common.Pdt;
|
|
||||||
using Cryville.Crtr.Components;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -58,41 +56,7 @@ namespace Cryville.Crtr {
|
|||||||
case ';':
|
case ';':
|
||||||
case ':':
|
case ':':
|
||||||
if (invalidKeyFlag) throw new FormatException("Invalid key format");
|
if (invalidKeyFlag) throw new FormatException("Invalid key format");
|
||||||
if (a.Contains("has")) {
|
return SkinPropertyKey.Construct(a, k, compKeyFlag);
|
||||||
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
|
||||||
return new SkinPropertyKey.CreateAnchor {
|
|
||||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (a.Contains("at")) {
|
|
||||||
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
|
||||||
return new SkinPropertyKey.SetAnchor {
|
|
||||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (a.Contains("emit")) {
|
|
||||||
if (k.Count != 1) throw new FormatException("Invalid effect name");
|
|
||||||
return new SkinPropertyKey.EmitEffect {
|
|
||||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
|
||||||
};
|
|
||||||
}
|
|
||||||
switch (k.Count) {
|
|
||||||
case 1:
|
|
||||||
if (compKeyFlag) return new SkinPropertyKey.CreateComponent {
|
|
||||||
Component = GetComponentByName(k[0])
|
|
||||||
};
|
|
||||||
else 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 '{':
|
case '{':
|
||||||
return new SkinSelectors(s, a);
|
return new SkinSelectors(s, a);
|
||||||
case '}':
|
case '}':
|
||||||
@@ -127,7 +91,7 @@ namespace Cryville.Crtr {
|
|||||||
if (cc != '{') throw new FormatException("Invalid span format");
|
if (cc != '{') throw new FormatException("Invalid span format");
|
||||||
return new Clip(start, end);
|
return new Clip(start, end);
|
||||||
}
|
}
|
||||||
k.Clear();
|
a.Clear(); k.Clear();
|
||||||
while (true) {
|
while (true) {
|
||||||
int pp = Position;
|
int pp = Position;
|
||||||
switch (cc) {
|
switch (cc) {
|
||||||
@@ -139,20 +103,7 @@ namespace Cryville.Crtr {
|
|||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
case ':':
|
case ':':
|
||||||
switch (k.Count) {
|
return SkinPropertyKey.Construct(a, k, false);
|
||||||
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 '{':
|
case '{':
|
||||||
throw new FormatException("Invalid token");
|
throw new FormatException("Invalid token");
|
||||||
case '}':
|
case '}':
|
||||||
@@ -167,10 +118,5 @@ namespace Cryville.Crtr {
|
|||||||
if (Position == pp) throw new FormatException("Invalid selector or key format");
|
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;
|
|
||||||
throw new ArgumentException(string.Format("Component type \"{0}\" not found", name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,16 +2,53 @@
|
|||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Crtr.Components;
|
using Cryville.Crtr.Components;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public abstract class SkinPropertyKey {
|
public abstract class SkinPropertyKey {
|
||||||
|
public static SkinPropertyKey Construct(HashSet<string> a, IReadOnlyList<string> k, bool compKeyFlag) {
|
||||||
|
if (a.Remove("has")) {
|
||||||
|
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
||||||
|
return new CreateAnchor(a, IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
|
}
|
||||||
|
else if (a.Remove("at")) {
|
||||||
|
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
||||||
|
return new SetAnchor(a, IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
|
}
|
||||||
|
else if (a.Remove("emit")) {
|
||||||
|
if (k.Count != 1) throw new FormatException("Invalid effect name");
|
||||||
|
return new EmitEffect(a, IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
|
}
|
||||||
|
switch (k.Count) {
|
||||||
|
case 1:
|
||||||
|
if (compKeyFlag) return new CreateComponent(a, GetComponentByName(k[0]));
|
||||||
|
else return new SetProperty(a, typeof(TransformInterface), IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
|
case 2:
|
||||||
|
return new SetProperty(a, GetComponentByName(k[0]), IdentifierManager.SharedInstance.Request(k[1]));
|
||||||
|
default:
|
||||||
|
throw new FormatException("Unknown error");
|
||||||
|
}
|
||||||
|
static Type GetComponentByName(string name) {
|
||||||
|
Type result;
|
||||||
|
if (GenericResources.Components.TryGetValue(name, out result)) return result;
|
||||||
|
throw new ArgumentException(string.Format("Component type \"{0}\" not found", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public readonly HashSet<string> annotations;
|
||||||
|
public SkinPropertyKey(IEnumerable<string> a) {
|
||||||
|
annotations = a.ToHashSet();
|
||||||
|
}
|
||||||
public abstract override string ToString();
|
public abstract override string ToString();
|
||||||
public abstract bool IsValueRequired { get; }
|
public abstract bool IsValueRequired { get; }
|
||||||
public abstract void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp);
|
public abstract void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp);
|
||||||
public abstract void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, int dl);
|
public abstract void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, int dl);
|
||||||
public class CreateComponent : SkinPropertyKey {
|
public class CreateComponent : SkinPropertyKey {
|
||||||
public Type Component { get; set; }
|
public Type Component { get; private set; }
|
||||||
|
public CreateComponent(IEnumerable<string> a, Type component) : base(a) {
|
||||||
|
Component = component;
|
||||||
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("*{0}", Component.Name);
|
return string.Format("*{0}", Component.Name);
|
||||||
}
|
}
|
||||||
@@ -24,8 +61,12 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SetProperty : SkinPropertyKey {
|
public class SetProperty : SkinPropertyKey {
|
||||||
public Type Component { get; set; }
|
public Type Component { get; private set; }
|
||||||
public int Name { get; set; }
|
public int Name { get; private set; }
|
||||||
|
public SetProperty(IEnumerable<string> a, Type component, int name) : base(a) {
|
||||||
|
Component = component;
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("{0}.{1}", Component.Name, IdentifierManager.SharedInstance.Retrieve(Name));
|
return string.Format("{0}.{1}", Component.Name, IdentifierManager.SharedInstance.Retrieve(Name));
|
||||||
}
|
}
|
||||||
@@ -61,7 +102,10 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class CreateAnchor : SkinPropertyKey {
|
public class CreateAnchor : SkinPropertyKey {
|
||||||
public int Name { get; set; }
|
public int Name { get; private set; }
|
||||||
|
public CreateAnchor(IEnumerable<string> a, int name) : base(a) {
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("@has {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
return string.Format("@has {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||||
}
|
}
|
||||||
@@ -74,8 +118,9 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SetAnchor : SkinPropertyKey {
|
public class SetAnchor : SkinPropertyKey {
|
||||||
public int Name { get; set; }
|
public int Name { get; private set; }
|
||||||
public SetAnchor() {
|
public SetAnchor(IEnumerable<string> a, int name) : base(a) {
|
||||||
|
Name = name;
|
||||||
_timeOp = new PropOp.Float(v => _time = v);
|
_timeOp = new PropOp.Float(v => _time = v);
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
@@ -97,8 +142,9 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class EmitEffect : SkinPropertyKey {
|
public class EmitEffect : SkinPropertyKey {
|
||||||
public int Name { get; set; }
|
public int Name { get; private set; }
|
||||||
public EmitEffect() {
|
public EmitEffect(IEnumerable<string> a, int name) : base(a) {
|
||||||
|
Name = name;
|
||||||
_op = new PropOp.Float(v => _index = v);
|
_op = new PropOp.Float(v => _index = v);
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
|
Reference in New Issue
Block a user