Implement animation.

This commit is contained in:
2023-02-27 00:17:14 +08:00
parent 9a51cf1b56
commit a755cc13bd
3 changed files with 54 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ namespace Cryville.Crtr {
#region Fields #region Fields
Chart chart; Chart chart;
Skin skin; Skin skin;
PdtSkin pskin; public static PdtSkin pskin;
Ruleset ruleset; Ruleset ruleset;
PdtRuleset pruleset; PdtRuleset pruleset;
Dictionary<string, Texture2D> texs; Dictionary<string, Texture2D> texs;

View File

@@ -1,5 +1,48 @@
namespace Cryville.Crtr.Components { using Cryville.Common;
namespace Cryville.Crtr.Components {
public class SkinAnimation : SkinComponent { public class SkinAnimation : SkinComponent {
public SkinAnimation() {
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
_rtimeSrc = new PropSrc.Float(() => _rtime);
}
SkinContext _skinContext;
AnimationSpan _anim;
public int Name {
set {
if (value == 0) return;
var id = new Identifier(value);
AnimationSpan anim;
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
Logger.Log("main", 4, "Skin", "Animation {0} not found", id.Name);
_anim = null;
return;
}
_anim = anim;
}
}
public float Duration { get; private set; }
double _startTime;
float _rtime;
readonly PropSrc _rtimeSrc;
public override void Init() {
_skinContext = new SkinContext(transform);
}
public override void Rewind(double time) {
_startTime = time;
}
public override void Tick(SkinContainer c, double time) {
_rtime = (float)(time - _startTime) / Duration;
_rtimeSrc.Invalidate();
ChartPlayer.etor.ContextSelfValue = _rtimeSrc;
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
ChartPlayer.etor.ContextSelfValue = null;
}
protected override void OnDestroy() { } protected override void OnDestroy() { }
} }
} }

View File

@@ -140,6 +140,15 @@ namespace Cryville.Crtr {
} }
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard(); if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
} }
public void MatchAnimation(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
foreach (var p in span.properties) {
p.Key.ExecuteDynamic(_group, ctx, p.Value, 0);
}
foreach (var s in span.spans) {
if (rtime < s.Key.Behind || rtime >= s.Key.Ahead) continue;
MatchAnimation(s.Value, rtime, ctx);
}
}
} }
public class SkinContext { public class SkinContext {
public Transform Transform { get; private set; } public Transform Transform { get; private set; }