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("body", new PropOp.String(v => body.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
|
||||
|
@@ -7,25 +7,32 @@ namespace Cryville.Crtr.Components {
|
||||
/// <summary>
|
||||
/// The property operators of the component.
|
||||
/// </summary>
|
||||
public Dictionary<string, PdtOperator> PropOps { get; private set; }
|
||||
public Dictionary<string, SkinProperty> Properties { get; private set; }
|
||||
/// <summary>
|
||||
/// Submits a property.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property operator.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property) {
|
||||
PropOps.Add(name, property);
|
||||
/// <param name="property">The property.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property, int uct = 1) {
|
||||
Properties.Add(name, new SkinProperty(property, uct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a skin component
|
||||
/// Creates a skin component.
|
||||
/// </summary>
|
||||
protected SkinComponent() {
|
||||
// Properties = new Dictionary<string, Property>();
|
||||
PropOps = new Dictionary<string, PdtOperator>();
|
||||
Properties = new Dictionary<string, SkinProperty>();
|
||||
}
|
||||
|
||||
public virtual void Init() { }
|
||||
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 {
|
||||
get { return cs.Container; }
|
||||
}
|
||||
|
||||
|
||||
public SkinContainer skinContainer;
|
||||
public 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) {
|
||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
||||
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);
|
||||
}
|
||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) { }
|
||||
|
@@ -9,41 +9,53 @@ using UnityEngine.Profiling;
|
||||
namespace Cryville.Crtr {
|
||||
public class SkinContainer {
|
||||
readonly PdtSkin skin;
|
||||
readonly Dictionary<SkinElement, Transform> matchedStatic
|
||||
= new Dictionary<SkinElement, Transform>();
|
||||
readonly Dictionary<SkinElement, Transform> matchedDynamic
|
||||
= new Dictionary<SkinElement, Transform>();
|
||||
readonly List<DynamicProperty> dynprops = new List<DynamicProperty>();
|
||||
struct DynamicProperty {
|
||||
public Transform Anchor { get; set; }
|
||||
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) {
|
||||
skin = _skin;
|
||||
}
|
||||
public void MatchStatic(ContainerState context) {
|
||||
dynprops.Clear(); dynelems.Clear();
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
matchedStatic.Clear();
|
||||
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.ContextState = 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) {
|
||||
var new_anchor = r.Key.MatchStatic(context, anchor);
|
||||
if (new_anchor != null) {
|
||||
MatchStatic(r.Value, context, new_anchor);
|
||||
try {
|
||||
var new_anchor = r.Key.MatchStatic(context, 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");
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
matchedDynamic.Clear();
|
||||
MatchDynamic(skin, context, context.Handler.gogroup);
|
||||
|
||||
foreach (var m in matchedDynamic) {
|
||||
var el = m.Key;
|
||||
var obj = m.Value;
|
||||
ChartPlayer.etor.ContextTransform = obj;
|
||||
foreach (var p in el.properties) {
|
||||
if (p.Key.Name == null) continue;
|
||||
if (p.Value.IsConstant) continue;
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(obj, p.Key), p.Value);
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var p in dynprops) {
|
||||
var prop = GetPropOp(p.Anchor, p.Key);
|
||||
if (context.CloneType > prop.UpdateCloneType) continue;
|
||||
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||
}
|
||||
foreach (var e in dynelems) {
|
||||
var anchor = e.Selectors.MatchDynamic(context, e.Anchor);
|
||||
if (anchor != null) MatchDynamic(e.Element, context, anchor);
|
||||
}
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
Profiler.EndSample();
|
||||
}
|
||||
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) {
|
||||
Transform new_anchor;
|
||||
if (!matchedStatic.ContainsKey(r.Value)) continue;
|
||||
if (!r.Key.IsUpdatable(context)) continue;
|
||||
new_anchor = r.Key.MatchDynamic(
|
||||
context, r.Value, matchedStatic[r.Value], anchor
|
||||
);
|
||||
var new_anchor = r.Key.MatchDynamic(context, anchor);
|
||||
if (new_anchor != null) {
|
||||
MatchDynamic(r.Value, context, new_anchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
PdtOperator GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||
var ctype = key.Component;
|
||||
var comp = (SkinComponent)obj.GetComponent(ctype);
|
||||
if (comp == null) throw new InvalidOperationException("Component instance not found");
|
||||
PdtOperator result;
|
||||
if (!comp.PropOps.TryGetValue(key.Name, out result))
|
||||
SkinProperty result;
|
||||
if (!comp.Properties.TryGetValue(key.Name, out result))
|
||||
throw new ArgumentException(string.Format("Property {0} not found on component", key.Name));
|
||||
return result;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ using Cryville.Crtr.Event;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
@@ -34,7 +35,15 @@ namespace Cryville.Crtr {
|
||||
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) {
|
||||
anchor = s.Match(h, anchor);
|
||||
if (anchor == null) return null;
|
||||
@@ -46,10 +55,9 @@ namespace Cryville.Crtr {
|
||||
if (!s.IsUpdatable(h)) return false;
|
||||
return true;
|
||||
}
|
||||
public Transform MatchDynamic(ContainerState h, SkinElement e, Transform old_target, Transform anchor = null) {
|
||||
if (!e.IsDynamic) return null;
|
||||
public Transform MatchDynamic(ContainerState h, Transform anchor) {
|
||||
foreach (var s in selectors) {
|
||||
anchor = s.Match(h, anchor, old_target);
|
||||
anchor = s.Match(h, anchor, true);
|
||||
if (anchor == null) return null;
|
||||
}
|
||||
return anchor;
|
||||
@@ -62,7 +70,7 @@ namespace Cryville.Crtr {
|
||||
get;
|
||||
}
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
@@ -71,12 +79,9 @@ namespace Cryville.Crtr {
|
||||
public override bool IsStatic {
|
||||
get { return true; }
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
||||
if (ot != null)
|
||||
return ot;
|
||||
var obj = new GameObject {
|
||||
name = "__obj__"
|
||||
};
|
||||
public override Transform Match(ContainerState h, Transform a, bool dyn = false) {
|
||||
if (dyn) throw new InvalidOperationException("Object creation in dynamic context is not allowed");
|
||||
var obj = new GameObject("__obj__");
|
||||
obj.transform.SetParent(a, false);
|
||||
obj.AddComponent<TransformInterface>();
|
||||
return obj.transform;
|
||||
@@ -91,7 +96,7 @@ namespace Cryville.Crtr {
|
||||
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;
|
||||
}
|
||||
public override bool IsUpdatable(ContainerState h) {
|
||||
@@ -110,13 +115,20 @@ namespace Cryville.Crtr {
|
||||
etor.Optimize(_exp);
|
||||
}
|
||||
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.Evaluate(_op, _exp);
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
return _flag ? a : null;
|
||||
try {
|
||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||
return _flag ? a : null;
|
||||
}
|
||||
catch (Exception) {
|
||||
throw new SelectorNotStaticException();
|
||||
}
|
||||
finally {
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class State : SkinSelector {
|
||||
@@ -124,7 +136,7 @@ namespace Cryville.Crtr {
|
||||
public override bool IsStatic {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -134,9 +146,15 @@ namespace Cryville.Crtr {
|
||||
public override bool IsStatic {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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