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;
37 float getNewChildDuration(entity this, float durationTime)
39 float maxDura = this.duration;
40 if (this.lastChild) maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration);
41 float dura = durationTime;
42 if (0 >= dura || dura > maxDura) dura = maxDura;
46 float getNewChildValue(entity this)
48 if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta;
49 else return this.startValue;
52 METHOD(Keyframe, addAnim, void(entity this, entity other))
54 if (other.parent) error("Can't add already added anim!");
56 if (other.isFinished(other)) error("Can't add finished anim!");
60 entity l = this.lastChild;
64 l.nextSibling = other;
68 this.currentChild = other;
69 this.firstChild = other;
72 other.prevSibling = l;
73 other.nextSibling = NULL;
74 this.lastChild = other;
77 METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
79 if (this.currentChild)
80 if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling;
82 if (this.currentChild)
84 this.currentChild.tick(this.currentChild, tickTime);
85 return this.currentChild.value;
88 return animStartValue + animDelta;