R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
AnimationSet.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** AnimationSet
6*/
7
8#pragma once
9
10#include <string>
11#include <unordered_map>
12#include <vector>
13#include "IComponent.hpp"
14#include "Sprite.hpp"
15
16namespace ecs {
25 std::vector<Rectangle> frames;
27 bool loop;
28 std::string nextClip;
29
33 AnimationClip() : frameDuration(0.1f), loop(true), nextClip("") {}
34
42 AnimationClip(const std::vector<Rectangle> &frames, float duration = 0.1f, bool loop = true,
43 const std::string &nextClip = "")
45 };
46
54 class AnimationSet : public IComponent {
55 public:
60 explicit AnimationSet(const std::string &textureKey) : _textureKey(textureKey) {}
61
62 ~AnimationSet() override = default;
63
68 std::string getTextureKey() const { return _textureKey; }
69
74 const std::unordered_map<std::string, AnimationClip> &getClips() const { return _clips; }
75
81 const AnimationClip *getClip(const std::string &clipName) const {
82 auto it = _clips.find(clipName);
83 return (it != _clips.end()) ? &it->second : nullptr;
84 }
85
91 bool hasClip(const std::string &clipName) const { return _clips.find(clipName) != _clips.end(); }
92
97 void setTextureKey(const std::string &textureKey) { _textureKey = textureKey; }
98
104 void addClip(const std::string &clipName, const AnimationClip &clip) { _clips[clipName] = clip; }
105
110 void removeClip(const std::string &clipName) { _clips.erase(clipName); }
111
116 ComponentType getType() const override { return getComponentType<AnimationSet>(); }
117
118 private:
119 std::string _textureKey;
120 std::unordered_map<std::string, AnimationClip> _clips;
121 };
122} // namespace ecs
Component containing all available animations for an entity.
AnimationSet(const std::string &textureKey)
Constructor with texture key.
std::unordered_map< std::string, AnimationClip > _clips
Map of animation clips.
const std::unordered_map< std::string, AnimationClip > & getClips() const
Get all animation clips.
ComponentType getType() const override
Get the component type ID.
void removeClip(const std::string &clipName)
Remove an animation clip.
void setTextureKey(const std::string &textureKey)
Set the texture key.
void addClip(const std::string &clipName, const AnimationClip &clip)
Add an animation clip.
bool hasClip(const std::string &clipName) const
Check if a clip exists.
~AnimationSet() override=default
std::string _textureKey
Texture identifier for animations.
std::string getTextureKey() const
Get the texture key.
const AnimationClip * getClip(const std::string &clipName) const
Get a specific animation clip.
Base interface for all ECS components.
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::size_t ComponentType
Type alias for component identification.
Defines a sequence of frames for an animation.
std::string nextClip
Next clip name after completion (optional)
AnimationClip()
Default constructor.
AnimationClip(const std::vector< Rectangle > &frames, float duration=0.1f, bool loop=true, const std::string &nextClip="")
Constructor with all parameters.
bool loop
Whether animation loops.
float frameDuration
Duration per frame in seconds.
std::vector< Rectangle > frames
Frame rectangles in the texture.