2022-04-23 14:16:02 +02:00
|
|
|
#include "AnimatedVariable.hpp"
|
|
|
|
#include "../managers/AnimationManager.hpp"
|
2022-07-28 13:28:43 +02:00
|
|
|
#include "../config/ConfigManager.hpp"
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
CAnimatedVariable::CAnimatedVariable() {
|
|
|
|
; // dummy var
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
void CAnimatedVariable::create(ANIMATEDVARTYPE type, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) {
|
2022-04-23 14:16:02 +02:00
|
|
|
m_eVarType = type;
|
2022-05-05 14:02:30 +02:00
|
|
|
m_eDamagePolicy = policy;
|
2022-07-28 13:28:43 +02:00
|
|
|
m_pConfig = pAnimConfig;
|
2022-04-23 14:16:02 +02:00
|
|
|
m_pWindow = pWindow;
|
|
|
|
|
|
|
|
m_bDummy = false;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
void CAnimatedVariable::create(ANIMATEDVARTYPE type, std::any val, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) {
|
|
|
|
create(type, pAnimConfig, pWindow, policy);
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
switch (type) {
|
|
|
|
case AVARTYPE_FLOAT: {
|
|
|
|
const auto V = std::any_cast<float>(val);
|
|
|
|
m_fValue = V;
|
|
|
|
m_fGoal = V;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AVARTYPE_VECTOR: {
|
|
|
|
const auto V = std::any_cast<Vector2D>(val);
|
|
|
|
m_vValue = V;
|
|
|
|
m_vGoal = V;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AVARTYPE_COLOR: {
|
|
|
|
const auto V = std::any_cast<CColor>(val);
|
|
|
|
m_cValue = V;
|
|
|
|
m_cGoal = V;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(ERR, "CAnimatedVariable create error: %s", e.what());
|
|
|
|
RASSERT(false, "CAnimatedVariable create error: %s", e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CAnimatedVariable::~CAnimatedVariable() {
|
2022-05-12 11:27:31 +02:00
|
|
|
unregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAnimatedVariable::unregister() {
|
2022-04-23 14:16:02 +02:00
|
|
|
g_pAnimationManager->m_lAnimatedVariables.remove(this);
|
2022-11-05 14:37:29 +01:00
|
|
|
m_bIsRegistered = false;
|
2022-07-28 13:28:43 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 16:56:31 +01:00
|
|
|
void CAnimatedVariable::registerVar() {
|
2022-11-05 14:37:29 +01:00
|
|
|
if (!m_bIsRegistered)
|
|
|
|
g_pAnimationManager->m_lAnimatedVariables.push_back(this);
|
|
|
|
m_bIsRegistered = true;
|
2022-11-04 16:56:31 +01:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
int CAnimatedVariable::getDurationLeftMs() {
|
2022-09-26 21:10:24 +02:00
|
|
|
return std::max((int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count(), 0);
|
2022-07-28 13:28:43 +02:00
|
|
|
}
|