]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animation.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animation.qc
1 #include "animation.qh"
2
3 #include "../menu.qh"
4
5 METHOD(Animation, configureAnimation, void(entity this, entity obj, void(entity, float) objSetter, float animStartTime, float animDuration, float animStartValue, float animEndValue))
6 {
7         this.setObjectSetter(this, obj, objSetter);
8         this.setTimeStartDuration(this, animStartTime, animDuration);
9         this.setValueStartEnd(this, animStartValue, animEndValue);
10 }
11
12 METHOD(Animation, update, void(entity this, float animDuration, float animStartValue, float animEndValue))
13 {
14         this.setTimeStartDuration(this, time, animDuration);
15         this.setValueStartEnd(this, animStartValue, animEndValue);
16 }
17
18 METHOD(Animation, setTimeStartEnd, void(entity this, float s, float e))
19 {
20         this.startTime = s;
21         this.duration = e - s;
22 }
23
24 METHOD(Animation, setTimeStartDuration, void(entity this, float s, float d))
25 {
26         this.startTime = s;
27         this.duration = d;
28 }
29
30 METHOD(Animation, setValueStartEnd, void(entity this, float s, float e))
31 {
32         this.startValue = s;
33         this.delta = e - s;
34 }
35
36 METHOD(Animation, setValueStartDelta, void(entity this, float s, float d))
37 {
38         this.startValue = s;
39         this.delta = d;
40 }
41
42 METHOD(Animation, setObjectSetter, void(entity this, entity o, void(entity, float) s))
43 {
44         this.object = o;
45         this.setter = s;
46 }
47
48 METHOD(Animation, tick, void(entity this, float tickTime))
49 {
50         if (this.isStopped(this) || this.isFinished(this) || (tickTime < this.startTime)) { return; }
51
52         if (tickTime >= (this.startTime + this.duration)) { this.finishAnim(this); } else { this.value = this.calcValue(this, (tickTime - this.startTime), this.duration, this.startValue, this.delta); }
53
54         this.setter(this.object, this.value);
55 }
56
57 METHOD(Animation, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
58 {
59         return animStartValue;
60 }
61
62 METHOD(Animation, isStopped, bool(entity this))
63 {
64         return this.stopped;
65 }
66
67 METHOD(Animation, stopAnim, void(entity this))
68 {
69         this.stopped = true;
70 }
71
72 METHOD(Animation, resumeAnim, void(entity this))
73 {
74         this.stopped = false;
75 }
76
77 METHOD(Animation, isFinished, bool(entity this))
78 {
79         return this.finished;
80 }
81
82 METHOD(Animation, finishAnim, void(entity this))
83 {
84         this.value = this.delta + this.startValue;
85         this.finished = true;
86         this.setter(this.object, this.value);
87 }