Implement multiple static matching.
This commit is contained in:
@@ -48,8 +48,8 @@ namespace Cryville.Crtr {
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var r in rel.elements) {
|
||||
try {
|
||||
var new_anchor = r.Key.MatchStatic(context, anchor);
|
||||
if (new_anchor != null) {
|
||||
var new_anchors = r.Key.MatchStatic(context, anchor);
|
||||
if (new_anchors != null) foreach (var new_anchor in new_anchors) {
|
||||
MatchStatic(r.Value, context, new_anchor);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
using CAnchor = Cryville.Crtr.Anchor;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class SkinSelectors {
|
||||
@@ -36,20 +37,12 @@ namespace Cryville.Crtr {
|
||||
selectors[i].Optimize(etor);
|
||||
}
|
||||
}
|
||||
public bool IsStatic {
|
||||
get {
|
||||
foreach (var s in selectors) {
|
||||
if (!s.IsStatic) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public Transform MatchStatic(ContainerState h, Transform anchor) {
|
||||
public IEnumerable<Transform> MatchStatic(ContainerState h, Transform anchor) {
|
||||
IEnumerable<Transform> result = new Transform[] { anchor };
|
||||
foreach (var s in selectors) {
|
||||
anchor = s.Match(h, anchor);
|
||||
if (anchor == null) return null;
|
||||
result = result.SelectMany(l => s.MatchStatic(h, l));
|
||||
}
|
||||
return anchor;
|
||||
return result;
|
||||
}
|
||||
public bool IsUpdatable(ContainerState h) {
|
||||
foreach (var s in selectors)
|
||||
@@ -58,7 +51,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public Transform MatchDynamic(ContainerState h, Transform anchor) {
|
||||
foreach (var s in selectors) {
|
||||
anchor = s.Match(h, anchor, true);
|
||||
anchor = s.MatchDynamic(h, anchor);
|
||||
if (anchor == null) return null;
|
||||
}
|
||||
return anchor;
|
||||
@@ -67,25 +60,19 @@ namespace Cryville.Crtr {
|
||||
|
||||
public abstract class SkinSelector {
|
||||
protected SkinSelector() { }
|
||||
public abstract bool IsStatic {
|
||||
get;
|
||||
}
|
||||
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
||||
public abstract Transform Match(ContainerState h, Transform a, bool dyn = false);
|
||||
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 bool IsUpdatable(ContainerState h) {
|
||||
return true;
|
||||
}
|
||||
public class CreateObject : SkinSelector {
|
||||
public CreateObject() { }
|
||||
public override bool IsStatic {
|
||||
get { return true; }
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
if (dyn) throw new InvalidOperationException("Object creation in dynamic context is not allowed");
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
var obj = new GameObject("__obj__");
|
||||
obj.transform.SetParent(a, false);
|
||||
obj.AddComponent<TransformInterface>();
|
||||
return obj.transform;
|
||||
return new Transform[] { obj.transform };
|
||||
}
|
||||
}
|
||||
public class Anchor : SkinSelector {
|
||||
@@ -93,15 +80,16 @@ namespace Cryville.Crtr {
|
||||
public Anchor(string name) {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
}
|
||||
public override bool IsStatic {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
return h.Handler.Anchors[Name].Transform;
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
List<CAnchor> anchors;
|
||||
if (h.Handler.Anchors.TryGetValue(Name, out anchors)) {
|
||||
return anchors.Select(a => a.Transform);
|
||||
}
|
||||
else return Enumerable.Empty<Transform>();
|
||||
}
|
||||
public override bool IsUpdatable(ContainerState h) {
|
||||
return h.Handler.Anchors[Name].Opened;
|
||||
return h.Handler.OpenAnchors.ContainsKey(Name);
|
||||
}
|
||||
}
|
||||
public class AtAnchor : SkinSelector {
|
||||
@@ -109,16 +97,11 @@ namespace Cryville.Crtr {
|
||||
public AtAnchor(string name) {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
}
|
||||
public override bool IsStatic {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
if (!dyn) throw new SelectorNotStaticException();
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
return IsUpdatable(h) ? a : null;
|
||||
}
|
||||
public override bool IsUpdatable(ContainerState h) {
|
||||
return h.Handler.Anchors[Name].Opened;
|
||||
return h.Handler.OpenAnchors.ContainsKey(Name);
|
||||
}
|
||||
}
|
||||
public class Property : SkinSelector {
|
||||
@@ -132,10 +115,15 @@ namespace Cryville.Crtr {
|
||||
public override void Optimize(PdtEvaluatorBase etor) {
|
||||
etor.Optimize(_exp);
|
||||
}
|
||||
public override bool IsStatic {
|
||||
get { return _exp.IsConstant; }
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
var result = Match(h, a);
|
||||
if (result != null) return new Transform[] { Match(h, a) };
|
||||
else return Enumerable.Empty<Transform>();
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
return Match(h, a, true);
|
||||
}
|
||||
public Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
ChartPlayer.etor.ContextTransform = a;
|
||||
try {
|
||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||
@@ -152,22 +140,15 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public class State : SkinSelector {
|
||||
public State(string state) { }
|
||||
public override bool IsStatic {
|
||||
get { return false; }
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
if (!dyn) throw new SelectorNotStaticException();
|
||||
public override Transform MatchDynamic(ContainerState h, Transform a) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class ElementType : SkinSelector {
|
||||
readonly string _type;
|
||||
public ElementType(string type) { _type = type; }
|
||||
public override bool IsStatic {
|
||||
get { return true; }
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
return h.Handler.TypeName == _type ? a : null;
|
||||
public override IEnumerable<Transform> MatchStatic(ContainerState h, Transform a) {
|
||||
return h.Handler.TypeName == _type ? new Transform[] { a } : Enumerable.Empty<Transform>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user