2021-10-02 21:17:03 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 03.10.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_TIMELINE_H
|
|
|
|
#define SHOOTER_TIMELINE_H
|
2021-11-09 22:54:20 +03:00
|
|
|
|
2021-11-03 19:22:14 +03:00
|
|
|
#include <memory>
|
2021-11-09 22:54:20 +03:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2021-11-05 00:05:06 +03:00
|
|
|
|
2021-10-02 21:17:03 +03:00
|
|
|
#include "Animation.h"
|
|
|
|
|
2021-10-17 11:41:58 +03:00
|
|
|
class AnimationListTag final {
|
2021-10-17 10:21:10 +03:00
|
|
|
private:
|
|
|
|
const std::string _name;
|
|
|
|
public:
|
|
|
|
explicit AnimationListTag(std::string name = "") : _name(std::move(name)) {}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 10:21:10 +03:00
|
|
|
[[nodiscard]] std::string str() const { return _name; }
|
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
bool operator==(const AnimationListTag &tag) const { return _name == tag._name; }
|
|
|
|
|
|
|
|
bool operator!=(const AnimationListTag &tag) const { return _name != tag._name; }
|
|
|
|
|
|
|
|
bool operator<(const AnimationListTag &tag) const { return _name < tag._name; }
|
2021-10-17 10:21:10 +03:00
|
|
|
};
|
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
class Timeline {
|
|
|
|
private:
|
2021-10-30 21:07:14 +03:00
|
|
|
std::map<AnimationListTag, std::list<std::shared_ptr<Animation>>> _animations;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
static Timeline *_instance;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
Timeline() = default;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
public:
|
2021-10-31 11:39:08 +03:00
|
|
|
Timeline(const Timeline &) = delete;
|
|
|
|
|
|
|
|
Timeline &operator=(Timeline &) = delete;
|
2021-10-02 21:17:03 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void update();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void deleteAllAnimations();
|
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
static void deleteAnimationList(const AnimationListTag &listName);
|
|
|
|
|
|
|
|
[[nodiscard]] static bool isInAnimList(const AnimationListTag &listName);
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
static void init();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void free();
|
2021-11-09 22:54:20 +03:00
|
|
|
|
|
|
|
template <typename T, typename... Arguments>
|
|
|
|
static void addAnimation(const AnimationListTag &listName, Arguments... args) {
|
|
|
|
if (_instance == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_instance->_animations[listName].emplace_back(std::make_shared<T>(args...));
|
|
|
|
}
|
2022-02-23 07:51:53 +03:00
|
|
|
|
|
|
|
template <typename T, typename... Arguments>
|
|
|
|
static void addAnimation(Arguments... args) {
|
|
|
|
if (_instance == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_instance->_animations[AnimationListTag("timeline_0")].emplace_back(std::make_shared<T>(args...));
|
|
|
|
}
|
2021-10-17 19:38:16 +03:00
|
|
|
};
|
2021-10-02 21:17:03 +03:00
|
|
|
|
|
|
|
#endif //SHOOTER_TIMELINE_H
|