mirror of
https://github.com/Show-maket/Tween.git
synced 2026-09-22 12:59:35 +00:00
Compare commits
7 Commits
77e4385c14
...
car-v4.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d25037b83 | |||
| 7f22882900 | |||
| cc5158eef0 | |||
| c4995cf075 | |||
| 3a46538696 | |||
| 18e03b1f26 | |||
| cfc67b8138 |
430
Tween.h
430
Tween.h
@ -2,40 +2,63 @@
|
|||||||
#include "Easing.h"
|
#include "Easing.h"
|
||||||
#include "TimeWarp.h"
|
#include "TimeWarp.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// EASING HELPERS
|
||||||
|
//----------------------------------------------------------------------
|
||||||
namespace EasingFunc {
|
namespace EasingFunc {
|
||||||
|
|
||||||
// typedef float (*eFunc)(float); // тип easing-функции, как у Вас
|
// typedef float (*eFunc)(float); // тип easing-функции, как у Вас
|
||||||
|
|
||||||
// Статические данные для обёртки
|
|
||||||
static const TimeWarp* g_warp = nullptr;
|
|
||||||
static eFunc g_baseEasing = nullptr;
|
|
||||||
|
|
||||||
// Обёртка с модификатором времени (вызывается Tween'ом)
|
// Обёртка с модификатором времени (вызывается Tween'ом)
|
||||||
inline float _easingWithWarp(float t) {
|
inline float _easingWithWarp(float t, const TimeWarp* warp, eFunc baseEasing) {
|
||||||
if (!g_warp || !g_baseEasing) return t;
|
if (!warp || !baseEasing) return t;
|
||||||
float warpedT = g_warp->apply(t);
|
float warpedT = warp->apply(t);
|
||||||
return g_baseEasing(warpedT);
|
return baseEasing(warpedT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Установить текущий модификатор времени
|
// Создать обёртку с модификатором времени
|
||||||
inline eFunc withTimeWarp(eFunc easing, const TimeWarp& warp) {
|
inline std::function<float(float)> withTimeWarp(eFunc easing, const TimeWarp& warp) {
|
||||||
g_warp = &warp;
|
return [easing, &warp](float t) -> float {
|
||||||
g_baseEasing = easing;
|
return _easingWithWarp(t, &warp, easing);
|
||||||
return _easingWithWarp;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace EasingFunc
|
}; // namespace EasingFunc
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// LISTENER‑ИНТЕРФЕЙС
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
class Tween; // forward
|
||||||
|
|
||||||
|
class TweenListener {
|
||||||
|
public:
|
||||||
|
virtual void onTweenFinished(Tween& tween) = 0;
|
||||||
|
virtual void onTweenUpdate(Tween& tween) = 0;
|
||||||
|
virtual ~TweenListener() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// TWEEN
|
||||||
|
//----------------------------------------------------------------------
|
||||||
class Tween {
|
class Tween {
|
||||||
private:
|
private:
|
||||||
static inline Tween* head = nullptr;
|
static inline Tween* head = nullptr;
|
||||||
static inline Tween* last = nullptr;
|
static inline Tween* last = nullptr;
|
||||||
static inline uint32_t frameRateTimer;
|
Tween* next = nullptr;
|
||||||
Tween* next;
|
|
||||||
|
TweenListener* listener = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Tween(const Tween&) = delete;
|
||||||
|
Tween& operator=(const Tween&) = delete;
|
||||||
|
Tween(Tween&& other) noexcept;
|
||||||
|
Tween& operator=(Tween&& other) noexcept;
|
||||||
|
|
||||||
Tween(uint16_t fps = 30) {
|
Tween(uint16_t fps = 30) {
|
||||||
setFps(fps);
|
setFps(fps);
|
||||||
|
frameRateTimer = millis();
|
||||||
if (Tween::head == nullptr) {
|
if (Tween::head == nullptr) {
|
||||||
Tween::head = this;
|
Tween::head = this;
|
||||||
}
|
}
|
||||||
@ -46,24 +69,44 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void tick() {
|
static void tick() {
|
||||||
|
uint32_t now = millis();
|
||||||
Tween* current = Tween::head;
|
Tween* current = Tween::head;
|
||||||
while (current != nullptr) {
|
while (current != nullptr) {
|
||||||
current->update();
|
current->update(now);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setListener(TweenListener* l) { listener = l; }
|
||||||
|
TweenListener* getListener() const { return listener; }
|
||||||
|
|
||||||
///////
|
///////
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void unlinkFromList() {
|
||||||
|
if (Tween::head == nullptr) return;
|
||||||
|
if (this == Tween::head) {
|
||||||
|
Tween::head = this->next;
|
||||||
|
if (this == Tween::last) Tween::last = nullptr;
|
||||||
|
} else {
|
||||||
|
Tween* prev = Tween::head;
|
||||||
|
while (prev && prev->next != this) prev = prev->next;
|
||||||
|
if (prev) prev->next = this->next;
|
||||||
|
if (this == Tween::last) Tween::last = prev;
|
||||||
|
}
|
||||||
|
this->next = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t frameTime;
|
uint16_t frameTime;
|
||||||
float dt;
|
float dt;
|
||||||
uint32_t oldMillis;
|
uint32_t oldMillis;
|
||||||
|
uint32_t frameRateTimer;
|
||||||
|
|
||||||
float from;
|
float from;
|
||||||
float to;
|
float to;
|
||||||
float duration;
|
float duration;
|
||||||
EasingFunc::eFunc easing = nullptr;
|
EasingFunc::eFunc easing = nullptr;
|
||||||
|
std::function<float(float)> easingFunc = nullptr;
|
||||||
float progress;
|
float progress;
|
||||||
bool isPlayingF;
|
bool isPlayingF;
|
||||||
bool triggerLastTick = false; // Флаг последнего тика
|
bool triggerLastTick = false; // Флаг последнего тика
|
||||||
@ -77,24 +120,30 @@ public:
|
|||||||
oldMillis = loopStartTime;
|
oldMillis = loopStartTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update(uint32_t now) {
|
||||||
if (millis() - frameRateTimer > frameTime) {
|
if (now - frameRateTimer > frameTime) {
|
||||||
uint32_t now = millis();
|
|
||||||
dt = (now - oldMillis) / 1000.0;
|
dt = (now - oldMillis) / 1000.0;
|
||||||
oldMillis = now;
|
oldMillis = now;
|
||||||
|
|
||||||
if (!isPlayingF && triggerLastTick) {
|
if (!isPlayingF && triggerLastTick) {
|
||||||
triggerLastTick = false;
|
triggerLastTick = false;
|
||||||
current = to;
|
current = to;
|
||||||
|
if (listener != nullptr) listener->onTweenFinished(*this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPlayingF || easing == nullptr) return;
|
if (!isPlayingF) return;
|
||||||
|
|
||||||
progress = constrain(progress + dt, 0, duration);
|
progress = constrain(progress + dt, 0, duration);
|
||||||
float normProgress = constrain(progress / duration, 0, 1);
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
current = Tween::lerp(from, to, easing(normProgress));
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
|
||||||
if (progress >= duration) {
|
if (progress >= duration) {
|
||||||
current = to;
|
current = to;
|
||||||
@ -102,7 +151,9 @@ public:
|
|||||||
isPlayingF = false;
|
isPlayingF = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
frameRateTimer = millis();
|
if (listener != nullptr) listener->onTweenUpdate(*this);
|
||||||
|
|
||||||
|
frameRateTimer = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,21 +161,35 @@ public:
|
|||||||
return constrain(progress / duration, 0, 1);
|
return constrain(progress / duration, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start(float from, float to, uint16_t duration, EasingFunc::eFunc easing) {
|
void start(float from_, float to_, uint16_t durationMs, EasingFunc::eFunc easing_ = nullptr) {
|
||||||
|
// если easing не задан, используем линейную
|
||||||
|
easing = (easing_ != nullptr) ? easing_ : EasingFunc::easeLinear;
|
||||||
|
easingFunc = nullptr; // сбрасываем функцию с TimeWarp
|
||||||
|
|
||||||
|
from = from_;
|
||||||
|
to = to_;
|
||||||
|
duration = durationMs / 1000.0f;
|
||||||
|
progress = 0;
|
||||||
current = from;
|
current = from;
|
||||||
if (from == to) {
|
uint32_t now = millis();
|
||||||
current = to;
|
oldMillis = now;
|
||||||
isPlayingF = false;
|
frameRateTimer = now;
|
||||||
triggerLastTick = true;
|
isPlayingF = true;
|
||||||
return;
|
triggerLastTick = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->from = from;
|
void start(float from_, float to_, uint16_t durationMs, std::function<float(float)> easingFunc_) {
|
||||||
this->to = to;
|
easing = nullptr; // сбрасываем обычную функцию
|
||||||
this->duration = duration / 1000.0;
|
easingFunc = easingFunc_;
|
||||||
this->easing = easing;
|
|
||||||
|
from = from_;
|
||||||
|
to = to_;
|
||||||
|
duration = durationMs / 1000.0f;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
oldMillis = millis();
|
current = from;
|
||||||
|
uint32_t now = millis();
|
||||||
|
oldMillis = now;
|
||||||
|
frameRateTimer = now;
|
||||||
isPlayingF = true;
|
isPlayingF = true;
|
||||||
triggerLastTick = false;
|
triggerLastTick = false;
|
||||||
}
|
}
|
||||||
@ -135,7 +200,93 @@ public:
|
|||||||
void stop() {
|
void stop() {
|
||||||
isPlayingF = false;
|
isPlayingF = false;
|
||||||
current = to;
|
current = to;
|
||||||
triggerLastTick = true;
|
triggerLastTick = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================
|
||||||
|
// Force Update API - принудительное обновление параметров
|
||||||
|
// =========================================================
|
||||||
|
|
||||||
|
// Принудительное обновление начальной точки (from) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе нового from и текущего прогресса
|
||||||
|
void forceUpdateFrom(float newFrom) {
|
||||||
|
from = newFrom;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового from и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, просто обновляем from
|
||||||
|
current = from;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление конечной точки (to) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе нового to и текущего прогресса
|
||||||
|
void forceUpdateTo(float newTo) {
|
||||||
|
to = newTo;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового to и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, просто обновляем to и current
|
||||||
|
current = to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление обеих точек (from и to) без сброса прогресса
|
||||||
|
// Пересчитывает current на основе новых точек и текущего прогресса
|
||||||
|
void forceUpdateFromTo(float newFrom, float newTo) {
|
||||||
|
from = newFrom;
|
||||||
|
to = newTo;
|
||||||
|
if (isPlayingF && duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе новых точек и текущего прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если не играет или duration = 0, устанавливаем current в from
|
||||||
|
current = from;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Принудительное обновление прогресса (progress) без сброса других параметров
|
||||||
|
// Пересчитывает current на основе нового прогресса
|
||||||
|
// newProgress - абсолютное значение прогресса (0..duration)
|
||||||
|
void forceUpdateProgress(float newProgress) {
|
||||||
|
progress = constrain(newProgress, 0, duration);
|
||||||
|
if (duration > 0.0f) {
|
||||||
|
// Пересчитываем current на основе нового прогресса
|
||||||
|
float normProgress = constrain(progress / duration, 0, 1);
|
||||||
|
if (easingFunc) {
|
||||||
|
current = Tween::lerp(from, to, easingFunc(normProgress));
|
||||||
|
} else if (easing) {
|
||||||
|
current = Tween::lerp(from, to, easing(normProgress));
|
||||||
|
} else {
|
||||||
|
current = Tween::lerp(from, to, normProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Если duration = 0, устанавливаем current в to
|
||||||
|
current = to;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPlaying() const {
|
bool isPlaying() const {
|
||||||
@ -146,6 +297,8 @@ public:
|
|||||||
frameTime = 1000 / fps;
|
frameTime = 1000 / fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t getFrameTime() const { return frameTime; }
|
||||||
|
|
||||||
float getFrom() const {
|
float getFrom() const {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
@ -166,16 +319,207 @@ public:
|
|||||||
static float lerp(float a, float b, float t) {
|
static float lerp(float a, float b, float t) {
|
||||||
return a + (b - a) * t;
|
return a + (b - a) * t;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// TWEEN MOVE SEMANTICS
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline Tween::Tween(Tween&& other) noexcept {
|
||||||
|
unlinkFromList();
|
||||||
|
|
||||||
|
next = other.next;
|
||||||
|
listener = other.listener;
|
||||||
|
frameTime = other.frameTime;
|
||||||
|
dt = other.dt;
|
||||||
|
oldMillis = other.oldMillis;
|
||||||
|
frameRateTimer = other.frameRateTimer;
|
||||||
|
from = other.from;
|
||||||
|
to = other.to;
|
||||||
|
duration = other.duration;
|
||||||
|
easing = other.easing;
|
||||||
|
easingFunc = std::move(other.easingFunc);
|
||||||
|
progress = other.progress;
|
||||||
|
isPlayingF = other.isPlayingF;
|
||||||
|
triggerLastTick = other.triggerLastTick;
|
||||||
|
current = other.current;
|
||||||
|
|
||||||
|
other.next = nullptr;
|
||||||
|
other.listener = nullptr;
|
||||||
|
other.easing = nullptr;
|
||||||
|
other.easingFunc = nullptr;
|
||||||
|
other.isPlayingF = false;
|
||||||
|
other.triggerLastTick = false;
|
||||||
|
|
||||||
|
if (Tween::head == &other) Tween::head = this;
|
||||||
|
else {
|
||||||
|
Tween* prev = Tween::head;
|
||||||
|
while (prev && prev->next != &other) prev = prev->next;
|
||||||
|
if (prev) prev->next = this;
|
||||||
|
}
|
||||||
|
if (Tween::last == &other) Tween::last = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Tween& Tween::operator=(Tween&& other) noexcept {
|
||||||
|
if (this != &other) {
|
||||||
|
unlinkFromList();
|
||||||
|
|
||||||
|
next = other.next;
|
||||||
|
listener = other.listener;
|
||||||
|
frameTime = other.frameTime;
|
||||||
|
dt = other.dt;
|
||||||
|
oldMillis = other.oldMillis;
|
||||||
|
frameRateTimer = other.frameRateTimer;
|
||||||
|
from = other.from;
|
||||||
|
to = other.to;
|
||||||
|
duration = other.duration;
|
||||||
|
easing = other.easing;
|
||||||
|
easingFunc = std::move(other.easingFunc);
|
||||||
|
progress = other.progress;
|
||||||
|
isPlayingF = other.isPlayingF;
|
||||||
|
triggerLastTick = other.triggerLastTick;
|
||||||
|
current = other.current;
|
||||||
|
|
||||||
|
other.next = nullptr;
|
||||||
|
other.listener = nullptr;
|
||||||
|
other.easing = nullptr;
|
||||||
|
other.easingFunc = nullptr;
|
||||||
|
other.isPlayingF = false;
|
||||||
|
other.triggerLastTick = false;
|
||||||
|
|
||||||
|
if (Tween::head == &other) Tween::head = this;
|
||||||
|
else {
|
||||||
|
Tween* prev = Tween::head;
|
||||||
|
while (prev && prev->next != &other) prev = prev->next;
|
||||||
|
if (prev) prev->next = this;
|
||||||
|
}
|
||||||
|
if (Tween::last == &other) Tween::last = this;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// ANIMATION CHAIN
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
class AnimationChain : public TweenListener {
|
||||||
|
public:
|
||||||
|
using FromFunc = std::function<float()>;
|
||||||
|
struct Anim {
|
||||||
|
float from;
|
||||||
|
FromFunc fromFunc = nullptr;
|
||||||
|
float to;
|
||||||
|
uint16_t duration; // мс
|
||||||
|
EasingFunc::eFunc easing = nullptr;
|
||||||
|
std::function<float(float)> easingFunc = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// int clamp(int value, int a, int b) {
|
std::vector<Anim> animations;
|
||||||
// if (a > b) {
|
Tween tween; // единственный Tween
|
||||||
// a ^= b;
|
size_t currentIndex = 0;
|
||||||
// b ^= a;
|
bool chainPlaying = false;
|
||||||
// a ^= b;
|
float* currentUserPtr = nullptr;
|
||||||
// }
|
|
||||||
// if (value < a) return a;
|
void launchCurrent() {
|
||||||
// else if (value > b) return b;
|
const Anim& a = animations[currentIndex];
|
||||||
// else return value;
|
if (a.easingFunc) {
|
||||||
// }
|
tween.start(a.fromFunc ? a.fromFunc() : a.from, a.to, a.duration, a.easingFunc);
|
||||||
|
} else {
|
||||||
|
tween.start(a.fromFunc ? a.fromFunc() : a.from, a.to, a.duration, a.easing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
float current = 0; // актуальное значение наружу
|
||||||
|
|
||||||
|
explicit AnimationChain(uint16_t fps = 30) : tween(fps) {
|
||||||
|
tween.setListener(this); // подписываемся
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// API ЦЕПОЧКИ
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
void addAnim(float from, float to, uint16_t duration, EasingFunc::eFunc easing = nullptr) {
|
||||||
|
animations.push_back({from, {}, to, duration, easing, nullptr});
|
||||||
|
}
|
||||||
|
void addAnim(FromFunc fromF, float to, uint16_t duration, EasingFunc::eFunc easing = nullptr) {
|
||||||
|
animations.push_back({0, fromF, to, duration, easing, nullptr});
|
||||||
|
}
|
||||||
|
void addAnim(float from, float to, uint16_t duration, std::function<float(float)> easingFunc) {
|
||||||
|
animations.push_back({from, {}, to, duration, nullptr, easingFunc});
|
||||||
|
}
|
||||||
|
void addAnim(FromFunc fromF, float to, uint16_t duration, std::function<float(float)> easingFunc) {
|
||||||
|
animations.push_back({0, fromF, to, duration, nullptr, easingFunc});
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() { animations.clear(); }
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
if (animations.empty()) return;
|
||||||
|
currentIndex = 0;
|
||||||
|
chainPlaying = true;
|
||||||
|
launchCurrent();
|
||||||
|
|
||||||
|
// Serial.printf("Chain start [%d]\n", currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
chainPlaying = false;
|
||||||
|
tween.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCustomParam(float* val) {
|
||||||
|
currentUserPtr = val;
|
||||||
|
}
|
||||||
|
void resetCustomParam() {
|
||||||
|
currentUserPtr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isStaticAnim() {
|
||||||
|
if(!isChainPlaying()) return true;
|
||||||
|
const Anim& anim = animations[currentIndex];
|
||||||
|
float from = anim.fromFunc ? anim.fromFunc() : anim.from;
|
||||||
|
float to = anim.to;
|
||||||
|
return from == to;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tween& getTween() { return tween; }
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// STATE
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
bool isChainPlaying() const { return chainPlaying; }
|
||||||
|
|
||||||
|
bool isAnimPlaying(size_t index) const {
|
||||||
|
return chainPlaying && index == currentIndex && tween.isPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getCurrentIndex() const { return currentIndex; }
|
||||||
|
// void setCurrentIndex(size_t index){ currentIndex = index; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// LISTENER CALLBACK
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
void onTweenFinished(Tween& /*t*/) override {
|
||||||
|
++currentIndex;
|
||||||
|
if (currentIndex < animations.size()) {
|
||||||
|
// Serial.printf("Chain next [%d]\n", currentIndex);
|
||||||
|
launchCurrent();
|
||||||
|
} else {
|
||||||
|
// Serial.printf("Chain stop [x]\n", currentIndex);
|
||||||
|
chainPlaying = false; // вся цепочка закончилась
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onTweenUpdate(Tween& /*t*/) override {
|
||||||
|
if (chainPlaying) {
|
||||||
|
current = tween.current; // даём наружу актуальное значение
|
||||||
|
if(currentUserPtr != nullptr) *currentUserPtr = current;
|
||||||
|
} else {
|
||||||
|
current = *currentUserPtr;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user