82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <frostbite2D/2d/actor.h>
|
|
#include <frostbite2D/animation/animation_data.h>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
namespace frostbite2D {
|
|
|
|
class Sprite;
|
|
|
|
class Animation : public Actor {
|
|
public:
|
|
struct ReplaceData {
|
|
int param1 = 0;
|
|
int param2 = 0;
|
|
ReplaceData() = default;
|
|
ReplaceData(int p1, int p2) : param1(p1), param2(p2) {}
|
|
};
|
|
|
|
public:
|
|
Animation();
|
|
explicit Animation(const std::string& aniPath);
|
|
Animation(const std::string& aniPath,
|
|
std::function<std::string(std::string, ReplaceData)> additionalOptions,
|
|
ReplaceData data);
|
|
~Animation();
|
|
|
|
void Init(const std::string& aniPath);
|
|
|
|
void Update(float deltaTime) override;
|
|
void OnAdded(Actor* parent);
|
|
void SetVisible(bool visible);
|
|
|
|
public:
|
|
void FlushFrame(int index);
|
|
void Reset();
|
|
animation::AniFrame GetCurrentFrameInfo();
|
|
void SetFrameIndex(int index);
|
|
void InterpolationLogic();
|
|
|
|
Vec2 GetMaxSize() const;
|
|
|
|
bool IsUsable() const { return usable_; }
|
|
void SetUsable(bool usable) { usable_ = usable; }
|
|
|
|
int GetCurrentFrameIndex() const { return currentFrameIndex_; }
|
|
int GetTotalFrameCount() const { return totalFrameCount_; }
|
|
|
|
public:
|
|
bool usable_ = true;
|
|
int currentFrameIndex_ = 0;
|
|
int totalFrameCount_ = 0;
|
|
float currentFrameTime_ = 0.0f;
|
|
Ptr<Sprite> currentFrame_ = nullptr;
|
|
float nextFrameDelay_ = 9999999.0f;
|
|
|
|
bool isLooping_ = true;
|
|
|
|
std::function<void(int)> changeFrameCallback_;
|
|
std::function<void()> endCallback_;
|
|
|
|
std::vector<animation::AniFrame> frames_;
|
|
std::vector<Ptr<Sprite>> spriteFrames_;
|
|
|
|
std::unordered_map<std::string, animation::AniFlag> animationFlag_;
|
|
|
|
std::string type_ = "normal";
|
|
std::string aniPath_;
|
|
|
|
std::function<std::string(std::string, ReplaceData)> additionalOptions_;
|
|
ReplaceData additionalOptionsData_;
|
|
|
|
Vec2 maxSize_ = Vec2::Zero();
|
|
|
|
std::vector<animation::AniFrame> interpolationData_;
|
|
};
|
|
|
|
} // namespace frostbite2D
|