Support extra annotations on skin property key. Code cleanup.
This commit is contained in:
@@ -2,16 +2,53 @@
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
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 bool IsValueRequired { get; }
|
||||
public abstract void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp);
|
||||
public abstract void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, int dl);
|
||||
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() {
|
||||
return string.Format("*{0}", Component.Name);
|
||||
}
|
||||
@@ -24,8 +61,12 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public class SetProperty : SkinPropertyKey {
|
||||
public Type Component { get; set; }
|
||||
public int Name { get; set; }
|
||||
public Type Component { get; private 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() {
|
||||
return string.Format("{0}.{1}", Component.Name, IdentifierManager.SharedInstance.Retrieve(Name));
|
||||
}
|
||||
@@ -61,7 +102,10 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
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() {
|
||||
return string.Format("@has {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||
}
|
||||
@@ -74,8 +118,9 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public class SetAnchor : SkinPropertyKey {
|
||||
public int Name { get; set; }
|
||||
public SetAnchor() {
|
||||
public int Name { get; private set; }
|
||||
public SetAnchor(IEnumerable<string> a, int name) : base(a) {
|
||||
Name = name;
|
||||
_timeOp = new PropOp.Float(v => _time = v);
|
||||
}
|
||||
public override string ToString() {
|
||||
@@ -97,8 +142,9 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public class EmitEffect : SkinPropertyKey {
|
||||
public int Name { get; set; }
|
||||
public EmitEffect() {
|
||||
public int Name { get; private set; }
|
||||
public EmitEffect(IEnumerable<string> a, int name) : base(a) {
|
||||
Name = name;
|
||||
_op = new PropOp.Float(v => _index = v);
|
||||
}
|
||||
public override string ToString() {
|
||||
|
Reference in New Issue
Block a user