Reconstruct skin container. Add update clone type limit to skin property.
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||||
SubmitProperty("shape", new op_set_shape(this));
|
SubmitProperty("shape", new op_set_shape(this), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
|
|||||||
@@ -7,25 +7,32 @@ namespace Cryville.Crtr.Components {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The property operators of the component.
|
/// The property operators of the component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, PdtOperator> PropOps { get; private set; }
|
public Dictionary<string, SkinProperty> Properties { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Submits a property.
|
/// Submits a property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the property.</param>
|
/// <param name="name">The name of the property.</param>
|
||||||
/// <param name="property">The property operator.</param>
|
/// <param name="property">The property.</param>
|
||||||
protected void SubmitProperty(string name, PdtOperator property) {
|
protected void SubmitProperty(string name, PdtOperator property, int uct = 1) {
|
||||||
PropOps.Add(name, property);
|
Properties.Add(name, new SkinProperty(property, uct));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a skin component
|
/// Creates a skin component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected SkinComponent() {
|
protected SkinComponent() {
|
||||||
// Properties = new Dictionary<string, Property>();
|
Properties = new Dictionary<string, SkinProperty>();
|
||||||
PropOps = new Dictionary<string, PdtOperator>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Init() { }
|
public virtual void Init() { }
|
||||||
protected abstract void OnDestroy();
|
protected abstract void OnDestroy();
|
||||||
}
|
}
|
||||||
|
public struct SkinProperty {
|
||||||
|
public PdtOperator Operator { get; set; }
|
||||||
|
public int UpdateCloneType { get; set; }
|
||||||
|
public SkinProperty(PdtOperator op, int uct = 1) {
|
||||||
|
Operator = op;
|
||||||
|
UpdateCloneType = uct;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
public EventContainer Container {
|
public EventContainer Container {
|
||||||
get { return cs.Container; }
|
get { return cs.Container; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkinContainer skinContainer;
|
public SkinContainer skinContainer;
|
||||||
public Judge judge;
|
public Judge judge;
|
||||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||||
@@ -125,7 +125,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
||||||
if (flag) PreAwake(s);
|
if (flag) PreAwake(s);
|
||||||
if (Awoken && s.CloneType <= 2) if (gogroup) skinContainer.MatchDynamic(s);
|
if (s.CloneType <= 2) if (gogroup) skinContainer.MatchDynamic(s);
|
||||||
if (flag) Awake(s);
|
if (flag) Awake(s);
|
||||||
}
|
}
|
||||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) { }
|
public virtual void ExUpdate(ContainerState s, StampedEvent ev) { }
|
||||||
|
|||||||
@@ -9,41 +9,53 @@ using UnityEngine.Profiling;
|
|||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class SkinContainer {
|
public class SkinContainer {
|
||||||
readonly PdtSkin skin;
|
readonly PdtSkin skin;
|
||||||
readonly Dictionary<SkinElement, Transform> matchedStatic
|
readonly List<DynamicProperty> dynprops = new List<DynamicProperty>();
|
||||||
= new Dictionary<SkinElement, Transform>();
|
struct DynamicProperty {
|
||||||
readonly Dictionary<SkinElement, Transform> matchedDynamic
|
public Transform Anchor { get; set; }
|
||||||
= new Dictionary<SkinElement, Transform>();
|
public SkinPropertyKey Key { get; set; }
|
||||||
|
public PdtExpression Value { get; set; }
|
||||||
|
}
|
||||||
|
readonly List<DynamicElement> dynelems = new List<DynamicElement>();
|
||||||
|
struct DynamicElement {
|
||||||
|
public Transform Anchor { get; set; }
|
||||||
|
public SkinSelectors Selectors { get; set; }
|
||||||
|
public SkinElement Element { get; set; }
|
||||||
|
}
|
||||||
public SkinContainer(PdtSkin _skin) {
|
public SkinContainer(PdtSkin _skin) {
|
||||||
skin = _skin;
|
skin = _skin;
|
||||||
}
|
}
|
||||||
public void MatchStatic(ContainerState context) {
|
public void MatchStatic(ContainerState context) {
|
||||||
|
dynprops.Clear(); dynelems.Clear();
|
||||||
ChartPlayer.etor.ContextState = context;
|
ChartPlayer.etor.ContextState = context;
|
||||||
ChartPlayer.etor.ContextEvent = context.Container;
|
ChartPlayer.etor.ContextEvent = context.Container;
|
||||||
matchedStatic.Clear();
|
|
||||||
MatchStatic(skin, context, context.Handler.gogroup);
|
MatchStatic(skin, context, context.Handler.gogroup);
|
||||||
|
|
||||||
foreach (var m in matchedStatic) {
|
|
||||||
var el = m.Key;
|
|
||||||
var obj = m.Value;
|
|
||||||
ChartPlayer.etor.ContextTransform = obj;
|
|
||||||
foreach (var p in el.properties) {
|
|
||||||
if (p.Key.Name == null)
|
|
||||||
obj.gameObject.AddComponent(p.Key.Component);
|
|
||||||
else {
|
|
||||||
ChartPlayer.etor.Evaluate(GetPropOp(obj, p.Key), p.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ChartPlayer.etor.ContextTransform = null;
|
|
||||||
}
|
|
||||||
ChartPlayer.etor.ContextEvent = null;
|
ChartPlayer.etor.ContextEvent = null;
|
||||||
ChartPlayer.etor.ContextState = null;
|
ChartPlayer.etor.ContextState = null;
|
||||||
}
|
}
|
||||||
void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||||
matchedStatic.Add(rel, anchor);
|
ChartPlayer.etor.ContextTransform = anchor;
|
||||||
|
foreach (var p in rel.properties) {
|
||||||
|
if (p.Key.Name == null)
|
||||||
|
anchor.gameObject.AddComponent(p.Key.Component);
|
||||||
|
else {
|
||||||
|
ChartPlayer.etor.Evaluate(GetPropOp(anchor, p.Key).Operator, p.Value);
|
||||||
|
if (!p.Value.IsConstant) dynprops.Add(
|
||||||
|
new DynamicProperty { Anchor = anchor, Key = p.Key, Value = p.Value }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ChartPlayer.etor.ContextTransform = null;
|
||||||
foreach (var r in rel.elements) {
|
foreach (var r in rel.elements) {
|
||||||
var new_anchor = r.Key.MatchStatic(context, anchor);
|
try {
|
||||||
if (new_anchor != null) {
|
var new_anchor = r.Key.MatchStatic(context, anchor);
|
||||||
MatchStatic(r.Value, context, new_anchor);
|
if (new_anchor != null) {
|
||||||
|
MatchStatic(r.Value, context, new_anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SelectorNotStaticException) {
|
||||||
|
dynelems.Add(
|
||||||
|
new DynamicElement { Anchor = anchor, Selectors = r.Key, Element = r.Value }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,44 +63,43 @@ namespace Cryville.Crtr {
|
|||||||
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
||||||
ChartPlayer.etor.ContextState = context;
|
ChartPlayer.etor.ContextState = context;
|
||||||
ChartPlayer.etor.ContextEvent = context.Container;
|
ChartPlayer.etor.ContextEvent = context.Container;
|
||||||
matchedDynamic.Clear();
|
foreach (var p in dynprops) {
|
||||||
MatchDynamic(skin, context, context.Handler.gogroup);
|
var prop = GetPropOp(p.Anchor, p.Key);
|
||||||
|
if (context.CloneType > prop.UpdateCloneType) continue;
|
||||||
foreach (var m in matchedDynamic) {
|
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||||
var el = m.Key;
|
}
|
||||||
var obj = m.Value;
|
foreach (var e in dynelems) {
|
||||||
ChartPlayer.etor.ContextTransform = obj;
|
var anchor = e.Selectors.MatchDynamic(context, e.Anchor);
|
||||||
foreach (var p in el.properties) {
|
if (anchor != null) MatchDynamic(e.Element, context, anchor);
|
||||||
if (p.Key.Name == null) continue;
|
|
||||||
if (p.Value.IsConstant) continue;
|
|
||||||
ChartPlayer.etor.Evaluate(GetPropOp(obj, p.Key), p.Value);
|
|
||||||
}
|
|
||||||
ChartPlayer.etor.ContextTransform = null;
|
|
||||||
}
|
}
|
||||||
ChartPlayer.etor.ContextEvent = null;
|
ChartPlayer.etor.ContextEvent = null;
|
||||||
ChartPlayer.etor.ContextState = null;
|
ChartPlayer.etor.ContextState = null;
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
}
|
}
|
||||||
void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||||
matchedDynamic.Add(rel, anchor);
|
ChartPlayer.etor.ContextTransform = anchor;
|
||||||
|
foreach (var p in rel.properties) {
|
||||||
|
if (p.Key.Name == null)
|
||||||
|
throw new InvalidOperationException("Component creation in dynamic context is not allowed");
|
||||||
|
var prop = GetPropOp(anchor, p.Key);
|
||||||
|
if (context.CloneType > prop.UpdateCloneType) continue;
|
||||||
|
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||||
|
}
|
||||||
|
ChartPlayer.etor.ContextTransform = null;
|
||||||
foreach (var r in rel.elements) {
|
foreach (var r in rel.elements) {
|
||||||
Transform new_anchor;
|
|
||||||
if (!matchedStatic.ContainsKey(r.Value)) continue;
|
|
||||||
if (!r.Key.IsUpdatable(context)) continue;
|
if (!r.Key.IsUpdatable(context)) continue;
|
||||||
new_anchor = r.Key.MatchDynamic(
|
var new_anchor = r.Key.MatchDynamic(context, anchor);
|
||||||
context, r.Value, matchedStatic[r.Value], anchor
|
|
||||||
);
|
|
||||||
if (new_anchor != null) {
|
if (new_anchor != null) {
|
||||||
MatchDynamic(r.Value, context, new_anchor);
|
MatchDynamic(r.Value, context, new_anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PdtOperator GetPropOp(Transform obj, SkinPropertyKey key) {
|
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||||
var ctype = key.Component;
|
var ctype = key.Component;
|
||||||
var comp = (SkinComponent)obj.GetComponent(ctype);
|
var comp = (SkinComponent)obj.GetComponent(ctype);
|
||||||
if (comp == null) throw new InvalidOperationException("Component instance not found");
|
if (comp == null) throw new InvalidOperationException("Component instance not found");
|
||||||
PdtOperator result;
|
SkinProperty result;
|
||||||
if (!comp.PropOps.TryGetValue(key.Name, out result))
|
if (!comp.Properties.TryGetValue(key.Name, out result))
|
||||||
throw new ArgumentException(string.Format("Property {0} not found on component", key.Name));
|
throw new ArgumentException(string.Format("Property {0} not found on component", key.Name));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Cryville.Crtr.Event;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
@@ -34,7 +35,15 @@ namespace Cryville.Crtr {
|
|||||||
selectors[i].Optimize(etor);
|
selectors[i].Optimize(etor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Transform MatchStatic(ContainerState h, Transform anchor = null) {
|
public bool IsStatic {
|
||||||
|
get {
|
||||||
|
foreach (var s in selectors) {
|
||||||
|
if (!s.IsStatic) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Transform MatchStatic(ContainerState h, Transform anchor) {
|
||||||
foreach (var s in selectors) {
|
foreach (var s in selectors) {
|
||||||
anchor = s.Match(h, anchor);
|
anchor = s.Match(h, anchor);
|
||||||
if (anchor == null) return null;
|
if (anchor == null) return null;
|
||||||
@@ -46,10 +55,9 @@ namespace Cryville.Crtr {
|
|||||||
if (!s.IsUpdatable(h)) return false;
|
if (!s.IsUpdatable(h)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public Transform MatchDynamic(ContainerState h, SkinElement e, Transform old_target, Transform anchor = null) {
|
public Transform MatchDynamic(ContainerState h, Transform anchor) {
|
||||||
if (!e.IsDynamic) return null;
|
|
||||||
foreach (var s in selectors) {
|
foreach (var s in selectors) {
|
||||||
anchor = s.Match(h, anchor, old_target);
|
anchor = s.Match(h, anchor, true);
|
||||||
if (anchor == null) return null;
|
if (anchor == null) return null;
|
||||||
}
|
}
|
||||||
return anchor;
|
return anchor;
|
||||||
@@ -62,7 +70,7 @@ namespace Cryville.Crtr {
|
|||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
||||||
public abstract Transform Match(ContainerState h, Transform a, Transform ot = null);
|
public abstract Transform Match(ContainerState h, Transform a, bool dyn = false);
|
||||||
public virtual bool IsUpdatable(ContainerState h) {
|
public virtual bool IsUpdatable(ContainerState h) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -71,12 +79,9 @@ namespace Cryville.Crtr {
|
|||||||
public override bool IsStatic {
|
public override bool IsStatic {
|
||||||
get { return true; }
|
get { return true; }
|
||||||
}
|
}
|
||||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||||
if (ot != null)
|
if (dyn) throw new InvalidOperationException("Object creation in dynamic context is not allowed");
|
||||||
return ot;
|
var obj = new GameObject("__obj__");
|
||||||
var obj = new GameObject {
|
|
||||||
name = "__obj__"
|
|
||||||
};
|
|
||||||
obj.transform.SetParent(a, false);
|
obj.transform.SetParent(a, false);
|
||||||
obj.AddComponent<TransformInterface>();
|
obj.AddComponent<TransformInterface>();
|
||||||
return obj.transform;
|
return obj.transform;
|
||||||
@@ -91,7 +96,7 @@ namespace Cryville.Crtr {
|
|||||||
get { return true; }
|
get { return true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||||
return h.Handler.Anchors[Name].Transform;
|
return h.Handler.Anchors[Name].Transform;
|
||||||
}
|
}
|
||||||
public override bool IsUpdatable(ContainerState h) {
|
public override bool IsUpdatable(ContainerState h) {
|
||||||
@@ -110,13 +115,20 @@ namespace Cryville.Crtr {
|
|||||||
etor.Optimize(_exp);
|
etor.Optimize(_exp);
|
||||||
}
|
}
|
||||||
public override bool IsStatic {
|
public override bool IsStatic {
|
||||||
get { throw new NotImplementedException(); }
|
get { return _exp.IsConstant; }
|
||||||
}
|
}
|
||||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||||
ChartPlayer.etor.ContextTransform = a;
|
ChartPlayer.etor.ContextTransform = a;
|
||||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
try {
|
||||||
ChartPlayer.etor.ContextTransform = null;
|
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||||
return _flag ? a : null;
|
return _flag ? a : null;
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
throw new SelectorNotStaticException();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
ChartPlayer.etor.ContextTransform = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class State : SkinSelector {
|
public class State : SkinSelector {
|
||||||
@@ -124,7 +136,7 @@ namespace Cryville.Crtr {
|
|||||||
public override bool IsStatic {
|
public override bool IsStatic {
|
||||||
get { return false; }
|
get { return false; }
|
||||||
}
|
}
|
||||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,9 +146,15 @@ namespace Cryville.Crtr {
|
|||||||
public override bool IsStatic {
|
public override bool IsStatic {
|
||||||
get { return true; }
|
get { return true; }
|
||||||
}
|
}
|
||||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||||
return h.Handler.TypeName == _type ? a : null;
|
return h.Handler.TypeName == _type ? a : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class SelectorNotStaticException : Exception {
|
||||||
|
public SelectorNotStaticException() : base("The selector is not static") { }
|
||||||
|
public SelectorNotStaticException(string message) : base(message) { }
|
||||||
|
public SelectorNotStaticException(string message, Exception innerException) : base(message, innerException) { }
|
||||||
|
protected SelectorNotStaticException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user