Implement set variable annotation.
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Cryville.Crtr {
|
||||
readonly SkinElement _rootElement;
|
||||
readonly DynamicStack[] _stacks = new DynamicStack[2];
|
||||
readonly HashSet<SkinPropertyKey> _once = new HashSet<SkinPropertyKey>();
|
||||
public readonly Dictionary<int, SkinVariable> Variables = new Dictionary<int, SkinVariable>();
|
||||
|
||||
class DynamicStack {
|
||||
public readonly List<DynamicProperty> Properties = new List<DynamicProperty>();
|
||||
@@ -45,7 +46,7 @@ namespace Cryville.Crtr {
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeInsert(rc.PropSrcs);
|
||||
foreach (var p in rel.properties) {
|
||||
try {
|
||||
p.Key.ExecuteStatic(_group, ctx, p.Value);
|
||||
p.Key.ExecuteStatic(_group, ctx, p.Value, Variables);
|
||||
}
|
||||
catch (EvaluationFailureException) { }
|
||||
if (p.Key.IsValueRequired && !p.Value.IsConstant) stack.Properties.Add(
|
||||
@@ -73,15 +74,16 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
}
|
||||
public void MatchDynamic(int dl) {
|
||||
public void MatchDynamic(int dl, bool recursive = false) {
|
||||
var stack = _stacks[dl];
|
||||
if (stack.Properties.Count == 0 && stack.Elements.Count == 0) return;
|
||||
var nstack = dl + 1 < _stacks.Length ? _stacks[dl + 1] : null;
|
||||
if (nstack != null) nstack.Clear();
|
||||
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
||||
if (!recursive) ChartPlayer.etor.ContextSkinContainer = this;
|
||||
for (int i = 0; i < stack.Properties.Count; i++) {
|
||||
DynamicProperty p = stack.Properties[i];
|
||||
p.Key.ExecuteDynamic(_group, p.Context, p.Value, dl);
|
||||
p.Key.ExecuteDynamic(_group, p.Context, p.Value, Variables, dl);
|
||||
if (p.Key.annotations.Contains("once")) {
|
||||
stack.Properties.RemoveAt(i--);
|
||||
}
|
||||
@@ -108,6 +110,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
if (psrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
}
|
||||
if (!recursive) ChartPlayer.etor.ContextSkinContainer = null;
|
||||
Profiler.EndSample();
|
||||
}
|
||||
void MatchDynamic(SkinElement rel, int dl, DynamicStack stack, RuntimeSkinContext ctx) {
|
||||
@@ -117,11 +120,11 @@ namespace Cryville.Crtr {
|
||||
foreach (var p in rel.properties) {
|
||||
if (p.Key.annotations.Contains("once")) {
|
||||
if (_once.Contains(p.Key)) continue;
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, dl);
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, Variables, dl);
|
||||
_once.Add(p.Key);
|
||||
}
|
||||
else {
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, dl);
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, Variables, dl);
|
||||
}
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
@@ -144,15 +147,17 @@ namespace Cryville.Crtr {
|
||||
float _rtime;
|
||||
readonly PropSrc _rtimeSrc;
|
||||
public void MatchAnimation(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
|
||||
ChartPlayer.etor.ContextSkinContainer = this;
|
||||
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
|
||||
MatchAnimationInternal(span, rtime, ctx);
|
||||
ChartPlayer.etor.ContextSelfValue = null;
|
||||
ChartPlayer.etor.ContextSkinContainer = null;
|
||||
}
|
||||
void MatchAnimationInternal(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
|
||||
_rtime = rtime;
|
||||
_rtimeSrc.Invalidate();
|
||||
foreach (var p in span.properties) {
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, 0);
|
||||
p.Key.ExecuteDynamic(_group, ctx, p.Value, Variables, 0);
|
||||
}
|
||||
foreach (var s in span.spans) {
|
||||
if (rtime < s.Key.Behind || rtime >= s.Key.Ahead) continue;
|
||||
@@ -202,4 +207,17 @@ namespace Cryville.Crtr {
|
||||
void RegisterAnchor(int name);
|
||||
void PushAnchorEvent(double time, int name);
|
||||
}
|
||||
public class SkinVariable {
|
||||
float _value;
|
||||
public PropOp Op { get; private set; }
|
||||
public PropSrc Src { get; private set; }
|
||||
public SkinVariable() {
|
||||
Op = new PropOp.Float(Set);
|
||||
Src = new PropSrc.Float(() => _value);
|
||||
}
|
||||
void Set(float value) {
|
||||
_value = value;
|
||||
Src.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user