Wrap Transform into SkinContext. Implement r/w context separation for skins.
This commit is contained in:
@@ -12,11 +12,11 @@ using CAnchor = Cryville.Crtr.Anchor;
|
||||
namespace Cryville.Crtr {
|
||||
public class SkinSelectors {
|
||||
readonly SkinSelector[] selectors;
|
||||
readonly string[] annotations;
|
||||
public readonly HashSet<string> annotations;
|
||||
|
||||
public SkinSelectors(IEnumerable<SkinSelector> s, IEnumerable<string> a) {
|
||||
selectors = s.ToArray();
|
||||
annotations = a.ToArray();
|
||||
annotations = a.ToHashSet();
|
||||
}
|
||||
public override string ToString() {
|
||||
if (selectors.Length == 0) return "";
|
||||
@@ -37,8 +37,8 @@ namespace Cryville.Crtr {
|
||||
selectors[i].Optimize(etor);
|
||||
}
|
||||
}
|
||||
public IEnumerable<Transform> MatchStatic(ContainerState h, Transform anchor) {
|
||||
IEnumerable<Transform> result = new Transform[] { anchor };
|
||||
public IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext ctx) {
|
||||
IEnumerable<SkinContext> result = new SkinContext[] { ctx };
|
||||
foreach (var s in selectors) {
|
||||
result = result.SelectMany(l => s.MatchStatic(h, l));
|
||||
}
|
||||
@@ -49,30 +49,30 @@ namespace Cryville.Crtr {
|
||||
if (!s.IsUpdatable(h)) return false;
|
||||
return true;
|
||||
}
|
||||
public Transform MatchDynamic(ContainerState h, Transform anchor) {
|
||||
public SkinContext MatchDynamic(ContainerState h, SkinContext ctx) {
|
||||
foreach (var s in selectors) {
|
||||
anchor = s.MatchDynamic(h, anchor);
|
||||
if (anchor == null) return null;
|
||||
ctx = s.MatchDynamic(h, ctx);
|
||||
if (ctx == null) return null;
|
||||
}
|
||||
return anchor;
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SkinSelector {
|
||||
protected SkinSelector() { }
|
||||
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
||||
public virtual IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) { throw new SelectorNotStaticException(); }
|
||||
public virtual Transform MatchDynamic(ContainerState h, Transform a) { throw new NotSupportedException(); }
|
||||
public virtual IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotStaticException(); }
|
||||
public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new NotSupportedException(); }
|
||||
public virtual bool IsUpdatable(ContainerState h) {
|
||||
return true;
|
||||
}
|
||||
public class CreateObject : SkinSelector {
|
||||
public CreateObject() { }
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
public override IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) {
|
||||
var obj = new GameObject("__obj__");
|
||||
obj.transform.SetParent(a, false);
|
||||
obj.transform.SetParent(c.Transform, false);
|
||||
obj.AddComponent<TransformInterface>();
|
||||
return new Transform[] { obj.transform };
|
||||
return new SkinContext[] { new SkinContext(obj.transform) };
|
||||
}
|
||||
}
|
||||
public class Anchor : SkinSelector {
|
||||
@@ -81,12 +81,12 @@ namespace Cryville.Crtr {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
}
|
||||
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
public override IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) {
|
||||
List<CAnchor> anchors;
|
||||
if (h.Handler.Anchors.TryGetValue(Name, out anchors)) {
|
||||
return anchors.Select(a => a.Transform);
|
||||
return anchors.Select(a => a.SkinContext);
|
||||
}
|
||||
else return Enumerable.Empty<Transform>();
|
||||
else return Enumerable.Empty<SkinContext>();
|
||||
}
|
||||
public override bool IsUpdatable(ContainerState h) {
|
||||
return h.Handler.OpenedAnchor.Name == Name;
|
||||
@@ -97,8 +97,8 @@ namespace Cryville.Crtr {
|
||||
public AtAnchor(string name) {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
}
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
return IsUpdatable(h) ? a : null;
|
||||
public override SkinContext MatchDynamic(ContainerState h, SkinContext c) {
|
||||
return IsUpdatable(h) ? c : null;
|
||||
}
|
||||
public override bool IsUpdatable(ContainerState h) {
|
||||
return h.Handler.OpenedAnchor.Name == Name;
|
||||
@@ -115,16 +115,16 @@ namespace Cryville.Crtr {
|
||||
public override void Optimize(PdtEvaluatorBase etor) {
|
||||
etor.Optimize(_exp);
|
||||
}
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
var result = Match(a);
|
||||
if (result != null) return new Transform[] { result };
|
||||
else return Enumerable.Empty<Transform>();
|
||||
public override IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) {
|
||||
var result = Match(c);
|
||||
if (result != null) return new SkinContext[] { result };
|
||||
else return Enumerable.Empty<SkinContext>();
|
||||
}
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
return Match(a, true);
|
||||
public override SkinContext MatchDynamic(ContainerState h, SkinContext c) {
|
||||
return Match(c, true);
|
||||
}
|
||||
public Transform Match(Transform a, bool dyn = false) {
|
||||
ChartPlayer.etor.ContextTransform = a;
|
||||
public SkinContext Match(SkinContext a, bool dyn = false) {
|
||||
ChartPlayer.etor.ContextTransform = a.Transform;
|
||||
try {
|
||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||
return _flag ? a : null;
|
||||
@@ -140,15 +140,15 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public class State : SkinSelector {
|
||||
public State(string state) { }
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
public override SkinContext MatchDynamic(ContainerState h, SkinContext c) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class ElementType : SkinSelector {
|
||||
readonly string _type;
|
||||
public ElementType(string type) { _type = type; }
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
return h.Handler.TypeName == _type ? new Transform[] { a } : Enumerable.Empty<Transform>();
|
||||
public override IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) {
|
||||
return h.Handler.TypeName == _type ? new SkinContext[] { c } : Enumerable.Empty<SkinContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user