From 7f22882900b14c6aee74eaaf81cd7c3d1b8028a8 Mon Sep 17 00:00:00 2001 From: DashyFox Date: Wed, 24 Dec 2025 17:26:26 +0300 Subject: [PATCH] forceUpdate methods --- Tween.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/Tween.h b/Tween.h index 5b2fa86..e058ac3 100644 --- a/Tween.h +++ b/Tween.h @@ -184,6 +184,92 @@ public: 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 { return isPlayingF || triggerLastTick; // Учитываем последний тик }