2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 06.04.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_AFUNCTION_H
|
|
|
|
#define ENGINE_AFUNCTION_H
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
#include <utility>
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
#include "Animation.h"
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class AFunction final : public Animation {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-28 16:58:02 +03:00
|
|
|
int _callsCounter = 0;
|
|
|
|
const int _allCalls = 1;
|
|
|
|
const std::function<void()> _callBack;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
void update() override {
|
2021-11-03 22:57:48 +03:00
|
|
|
if (_allCalls != 0 && progress() >= (double) (_callsCounter + 1) / _allCalls) {
|
2021-10-28 16:58:02 +03:00
|
|
|
_callsCounter++;
|
2021-09-13 15:53:43 +03:00
|
|
|
_callBack();
|
|
|
|
}
|
2021-10-28 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-10-31 11:39:08 +03:00
|
|
|
explicit AFunction(std::function<void()> function, int calls = 1, double duration = 1,
|
|
|
|
LoopOut looped = LoopOut::None, InterpolationType interpolationType = InterpolationType::Linear)
|
|
|
|
: Animation(duration, looped, interpolationType), _callBack(std::move(function)), _allCalls(calls) {
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //MINECRAFT_3DZAVR_AFUNCTION_H
|