Implement animation.
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Cryville.Crtr {
|
||||
#region Fields
|
||||
Chart chart;
|
||||
Skin skin;
|
||||
PdtSkin pskin;
|
||||
public static PdtSkin pskin;
|
||||
Ruleset ruleset;
|
||||
PdtRuleset pruleset;
|
||||
Dictionary<string, Texture2D> texs;
|
||||
|
@@ -1,5 +1,48 @@
|
||||
namespace Cryville.Crtr.Components {
|
||||
using Cryville.Common;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
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() { }
|
||||
}
|
||||
}
|
||||
|
@@ -140,6 +140,15 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
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 Transform Transform { get; private set; }
|
||||
|
Reference in New Issue
Block a user