-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweenComponent.h
More file actions
186 lines (152 loc) · 4.58 KB
/
Copy pathTweenComponent.h
File metadata and controls
186 lines (152 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#pragma once
#include <cstdint>
#include <functional>
#include "DekiBehaviour.h"
#include "reflection/DekiProperty.h"
#include "Easing.h"
#include "DekiVector.h"
#include "Color.h"
/**
* @brief Tween target type - which property to animate
*
* Uses DekiVector3 endValue:
* - Position: X,Y from endValue
* - Scale: X,Y from endValue
* - Rotation: Z from endValue (radians; engine convention)
*/
enum class TweenTargetType : uint8_t
{
Position = 0, // Animate X,Y position
Scale, // Animate X,Y scale
Rotation, // Animate rotation (uses Z component)
COUNT
};
/**
* @brief Editor-configurable tween component
*
* Allows designers to set up tweens in the inspector without code.
* Extends DekiBehaviour for Update() lifecycle.
*
* Tweens from current state to endValue:
* - Position: X,Y from endValue
* - Scale: X,Y from endValue
* - Rotation: Z from endValue (radians; engine convention)
*
* Features:
* - Target property selection (position, scale, rotation)
* - Duration, delay, looping, ping-pong
* - Easing selection dropdown
* - Auto-play on start option
* - Completion events (for chaining or triggering other behaviours)
*/
class DEKI_TWEEN_API TweenComponent : public DekiBehaviour
{
public:
DEKI_COMPONENT(TweenComponent, DekiBehaviour, "Animation", "9e113121-59df-4786-9752-0099935f1378", "DEKI_FEATURE_TWEEN")
DEKI_DESCRIPTION("Animates the object's position, scale or rotation along an easing curve.")
// ========== Inspector Properties ==========
/** @brief Target type to animate */
DEKI_EXPORT
TweenTargetType targetType = TweenTargetType::Position;
/** @brief End value - Position/Scale use X,Y; Rotation uses Z */
DEKI_EXPORT
DekiVector3 endValue = DekiVector3(0.0f, 0.0f, 0.0f);
/** @brief Duration in seconds. */
DEKI_EXPORT
DEKI_SLIDER(0.1f, 10.0f)
float duration = 1.0f;
/** @brief Delay before starting (seconds). */
DEKI_EXPORT
DEKI_SLIDER(0.0f, 5.0f)
float delay = 0.0f;
/** @brief Easing type */
DEKI_EXPORT
deki::EaseType easeType = deki::EaseType::Linear;
/** @brief Number of loops (-1 = infinite, 0 = no loop) */
DEKI_EXPORT
DEKI_RANGE(-1, 100)
int32_t loops = 0;
/** @brief Reverse direction each loop */
DEKI_EXPORT
bool pingPong = false;
/** @brief Auto-play when Start() is called */
DEKI_EXPORT
bool autoPlay = true;
/** @brief Use relative values (add to current instead of absolute) */
DEKI_EXPORT
bool relative = false;
// ========== Runtime Callbacks ==========
std::function<void()> on_complete;
std::function<void(float progress)> on_update;
// ========== Lifecycle ==========
TweenComponent();
virtual ~TweenComponent();
void Awake() override;
void Start() override;
void Update() override;
// ========== Control API ==========
/**
* @brief Start or restart the tween
*/
void Play();
/**
* @brief Pause the tween
*/
void Pause();
/**
* @brief Resume a paused tween
*/
void Resume();
/**
* @brief Stop and reset the tween
*/
void Stop();
/**
* @brief Set completion callback
*/
void SetOnComplete(std::function<void()> callback);
/**
* @brief Check if tween is currently playing
*/
bool IsPlaying() const { return m_IsPlaying; }
/**
* @brief Check if tween has completed
*/
bool HasCompleted() const { return m_HasCompleted; }
/**
* @brief Get current progress (0-1).
*/
float GetProgress() const;
private:
// Runtime state.
float m_Elapsed = 0.0f;
float m_DelayElapsed = 0.0f;
int32_t m_CurrentLoop = 0;
bool m_Reversed = false;
bool m_HasCompleted = false;
bool m_IsPlaying = false;
bool m_IsPaused = false;
// Cached initial value (captured when tween starts)
DekiVector3 m_StartValue = DekiVector3(0.0f, 0.0f, 0.0f);
/**
* @brief Get the current value of the target property as DekiVector3
* Position: X,Y from object position
* Scale: X,Y from object scale
* Rotation: Z from object rotation
*/
DekiVector3 GetCurrentValue() const;
/**
* @brief Apply interpolated DekiVector3 value to target
*/
void ApplyValue(float easedT);
/**
* @brief Get the eased progress value.
*/
float GetEasedProgress(float t) const;
/**
* @brief Handle loop completion or final completion
*/
void HandleLoopOrComplete();
};
// Generated property metadata (after class definition for offsetof)
#include "generated/TweenComponent.gen.h"