6 #include "../item/container.qh"
10 entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
12 entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
13 anim.addAnim(anim, this);
17 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
19 entity this = NEW(Keyframe);
20 this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
24 METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
26 entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
27 this.addAnim(this, other);
31 float getNewChildStart(entity this)
33 if (this.lastChild) { return this.lastChild.startTime + this.lastChild.duration; } else { return 0; }
36 float getNewChildDuration(entity this, float durationTime)
38 float maxDura = this.duration;
39 if (this.lastChild) { maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration); }
40 float dura = durationTime;
41 if (0 >= dura || dura > maxDura) { dura = maxDura; }
45 float getNewChildValue(entity this)
47 if (this.lastChild) { return this.lastChild.startValue + this.lastChild.delta; } else { return this.startValue; }
50 METHOD(Keyframe, addAnim, void(entity this, entity other))
52 if (other.parent) { error("Can't add already added anim!"); }
54 if (other.isFinished(other)) { error("Can't add finished anim!"); }
58 entity l = this.lastChild;
61 l.nextSibling = other;
63 this.currentChild = other;
64 this.firstChild = other;
67 other.prevSibling = l;
68 other.nextSibling = NULL;
69 this.lastChild = other;
72 METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
74 if (this.currentChild) {
75 if (this.currentChild.isFinished(this.currentChild)) { this.currentChild = this.currentChild.nextSibling; } }
77 if (this.currentChild) {
78 this.currentChild.tick(this.currentChild, tickTime);
79 return this.currentChild.value;
82 return animStartValue + animDelta;