Wrap Transform into SkinContext. Implement r/w context separation for skins.
This commit is contained in:
@@ -12,90 +12,98 @@ namespace Cryville.Crtr {
|
||||
readonly PdtSkin skin;
|
||||
readonly List<DynamicProperty> dynprops = new List<DynamicProperty>();
|
||||
struct DynamicProperty {
|
||||
public Transform Anchor { get; set; }
|
||||
public RuntimeSkinContext Context { 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 RuntimeSkinContext Context { get; set; }
|
||||
public SkinSelectors Selectors { get; set; }
|
||||
public SkinElement Element { get; set; }
|
||||
}
|
||||
public SkinContainer(PdtSkin _skin) {
|
||||
skin = _skin;
|
||||
}
|
||||
public void MatchStatic(ContainerState context) {
|
||||
public void MatchStatic(ContainerState state) {
|
||||
dynprops.Clear(); dynelems.Clear();
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
MatchStatic(skin, context, context.Handler.gogroup);
|
||||
ChartPlayer.etor.ContextState = state;
|
||||
ChartPlayer.etor.ContextEvent = state.Container;
|
||||
MatchStatic(skin, state, new RuntimeSkinContext(state.Handler.SkinContext));
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
}
|
||||
void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||
ChartPlayer.etor.ContextTransform = anchor;
|
||||
void MatchStatic(SkinElement rel, ContainerState state, RuntimeSkinContext ctx) {
|
||||
var rc = ctx.ReadContext;
|
||||
ChartPlayer.etor.ContextTransform = rc.Transform;
|
||||
foreach (var p in rel.properties) {
|
||||
if (p.Key.Name == 0)
|
||||
anchor.gameObject.AddComponent(p.Key.Component);
|
||||
rc.Transform.gameObject.AddComponent(p.Key.Component);
|
||||
else {
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(anchor, p.Key).Operator, p.Value);
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(ctx.WriteTransform, p.Key).Operator, p.Value);
|
||||
if (!p.Value.IsConstant) dynprops.Add(
|
||||
new DynamicProperty { Anchor = anchor, Key = p.Key, Value = p.Value }
|
||||
new DynamicProperty { Context = ctx, Key = p.Key, Value = p.Value }
|
||||
);
|
||||
}
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var r in rel.elements) {
|
||||
try {
|
||||
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);
|
||||
var nctxs = r.Key.MatchStatic(state, rc);
|
||||
var roflag = r.Key.annotations.Contains("if");
|
||||
foreach (var nctx in nctxs) {
|
||||
var nrctx = new RuntimeSkinContext(nctx, ctx.WriteTransform, roflag);
|
||||
MatchStatic(r.Value, state, nrctx);
|
||||
}
|
||||
}
|
||||
catch (SelectorNotStaticException) {
|
||||
dynelems.Add(
|
||||
new DynamicElement { Anchor = anchor, Selectors = r.Key, Element = r.Value }
|
||||
new DynamicElement { Context = ctx, Selectors = r.Key, Element = r.Value }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void MatchDynamic(ContainerState context) {
|
||||
public void MatchDynamic(ContainerState state) {
|
||||
if (dynprops.Count == 0 && dynelems.Count == 0) return;
|
||||
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
ChartPlayer.etor.ContextState = state;
|
||||
ChartPlayer.etor.ContextEvent = state.Container;
|
||||
for (int i = 0; i < dynprops.Count; i++) {
|
||||
DynamicProperty p = dynprops[i];
|
||||
var prop = GetPropOp(p.Anchor, p.Key);
|
||||
if (context.CloneType > prop.UpdateCloneType) continue;
|
||||
var prop = GetPropOp(p.Context.WriteTransform, p.Key);
|
||||
if (state.CloneType > prop.UpdateCloneType) continue;
|
||||
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||
}
|
||||
for (int i = 0; i < dynelems.Count; i++) {
|
||||
DynamicElement e = dynelems[i];
|
||||
var anchor = e.Selectors.MatchDynamic(context, e.Anchor);
|
||||
if (anchor != null) MatchDynamic(e.Element, context, anchor);
|
||||
var nctx = e.Selectors.MatchDynamic(state, e.Context.ReadContext);
|
||||
if (nctx != null) MatchDynamic(
|
||||
e.Element, state,
|
||||
new RuntimeSkinContext(nctx, e.Context.ReadContext.Transform, e.Selectors.annotations.Contains("if"))
|
||||
);
|
||||
}
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
Profiler.EndSample();
|
||||
}
|
||||
void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||
ChartPlayer.etor.ContextTransform = anchor;
|
||||
void MatchDynamic(SkinElement rel, ContainerState state, RuntimeSkinContext ctx) {
|
||||
var rc = ctx.ReadContext;
|
||||
ChartPlayer.etor.ContextTransform = rc.Transform;
|
||||
foreach (var p in rel.properties) {
|
||||
if (p.Key.Name == 0)
|
||||
throw new InvalidOperationException("Component creation in dynamic context is not allowed");
|
||||
var prop = GetPropOp(anchor, p.Key);
|
||||
if (context.CloneType > prop.UpdateCloneType) continue;
|
||||
var prop = GetPropOp(ctx.WriteTransform, p.Key);
|
||||
if (state.CloneType > prop.UpdateCloneType) continue;
|
||||
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var r in rel.elements) {
|
||||
if (!r.Key.IsUpdatable(context)) continue;
|
||||
var new_anchor = r.Key.MatchDynamic(context, anchor);
|
||||
if (new_anchor != null) {
|
||||
MatchDynamic(r.Value, context, new_anchor);
|
||||
}
|
||||
if (!r.Key.IsUpdatable(state)) continue;
|
||||
var nctx = r.Key.MatchDynamic(state, rc);
|
||||
if (nctx != null) MatchDynamic(
|
||||
r.Value, state,
|
||||
new RuntimeSkinContext(nctx, ctx.WriteTransform, r.Key.annotations.Contains("if"))
|
||||
);
|
||||
}
|
||||
}
|
||||
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||
@@ -114,4 +122,28 @@ namespace Cryville.Crtr {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class SkinContext {
|
||||
public Transform Transform { get; private set; }
|
||||
public Dictionary<int, PropSrc.Arbitrary> PropSrcs { get; private set; }
|
||||
public SkinContext(Transform transform, Dictionary<int, PropSrc.Arbitrary> propSrcs = null) {
|
||||
Transform = transform;
|
||||
PropSrcs = propSrcs;
|
||||
}
|
||||
}
|
||||
public struct RuntimeSkinContext {
|
||||
public SkinContext ReadContext { get; private set; }
|
||||
public Transform WriteTransform { get; private set; }
|
||||
public RuntimeSkinContext(SkinContext rw) {
|
||||
ReadContext = rw;
|
||||
WriteTransform = rw.Transform;
|
||||
}
|
||||
public RuntimeSkinContext(SkinContext r, Transform w) {
|
||||
ReadContext = r;
|
||||
WriteTransform = w;
|
||||
}
|
||||
public RuntimeSkinContext(SkinContext newctx, Transform oldctx, bool roflag) {
|
||||
ReadContext = newctx;
|
||||
WriteTransform = roflag ? oldctx : newctx.Transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user