Improve indentation consistency in client.qc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.qc
1 #include "keyframe.qh"
2
3 #include "../menu.qh"
4 #include "easing.qh"
5
6 #include "../item/container.qh"
7
8 .entity parent;
9
10         entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
11         {
12                 entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
13                 anim.addAnim(anim, this);
14                 return this;
15         }
16
17         entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
18         {
19                 entity this = NEW(Keyframe);
20                 this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
21                 return this;
22         }
23
24         METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
25         {
26                 entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
27                 this.addAnim(this, other);
28                 return other;
29         }
30
31         float getNewChildStart(entity this)
32         {
33                 if (this.lastChild) return this.lastChild.startTime + this.lastChild.duration;
34                 else return 0;
35         }
36
37         float getNewChildDuration(entity this, float durationTime)
38         {
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;
43                 return dura;
44         }
45
46         float getNewChildValue(entity this)
47         {
48                 if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta;
49                 else return this.startValue;
50         }
51
52         METHOD(Keyframe, addAnim, void(entity this, entity other))
53         {
54                 if (other.parent) error("Can't add already added anim!");
55
56                 if (other.isFinished(other)) error("Can't add finished anim!");
57
58                 other.parent = this;
59
60                 entity l = this.lastChild;
61
62                 if (l)
63                 {
64                         l.nextSibling = other;
65                 }
66                 else
67                 {
68                         this.currentChild = other;
69                         this.firstChild = other;
70                 }
71
72                 other.prevSibling = l;
73                 other.nextSibling = NULL;
74                 this.lastChild = other;
75         }
76
77         METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
78         {
79                 if (this.currentChild)
80                         if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling;
81
82                 if (this.currentChild)
83                 {
84                         this.currentChild.tick(this.currentChild, tickTime);
85                         return this.currentChild.value;
86                 }
87
88                 return animStartValue + animDelta;
89         }