R-Type  2
Doom but in better
Loading...
Searching...
No Matches
AnimationComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** AnimationComponent.hpp
6*/
7
13#pragma once
14
15#include <vector>
16#include <chrono>
17#include <utility>
18#include <cstdint>
19#include <SFML/Graphics/Texture.hpp>
20
21#include "Log.hpp"
22#include "LogMacros.hpp"
23#include "Utilities.hpp"
24#include "CustomExceptions.hpp"
28
29namespace GUI
30{
31 namespace ECS
32 {
33 namespace Components
34 {
36 public:
47 AnimationComponent(const std::uint32_t entityId);
54 AnimationComponent(const std::vector<Recoded::IntRect> &rects);
69 AnimationComponent(const std::string &path, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
84 AnimationComponent(const GUI::ECS::Components::TextureComponent &spritesheet, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
93 AnimationComponent(const std::uint32_t entityId, const std::vector<Recoded::IntRect> &rects);
110 AnimationComponent(const std::uint32_t entityId, const std::string &path, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
127 AnimationComponent(const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &spritesheet, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
128
134
140 void setLoop(bool loop);
146 void setReadReverse(bool reverse);
152 void setDelay(float frameDuration);
158 void setInitialFrame(std::uint32_t frameIndex);
159
165 void setAnimation(const std::vector<Recoded::IntRect> &rects);
175 void setAnimation(const std::string &path, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
185 void setAnimation(const GUI::ECS::Components::TextureComponent &spritesheet, const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
186
191 void checkTick();
192
197 void forceTick();
198
203 void start();
204
209 void pause();
214 void resume();
215
220 void stop();
221
228 const bool hasTicked();
229
236 const bool hasLooped() const;
237
244 const bool isLooping() const;
245
252 const bool isPaused() const;
259 const bool isPlaying() const;
266 const bool isStopped() const;
267
274
285 const bool getTicked() const;
286
297 const bool getPaused() const;
298
309 const bool getPlaying() const;
310
321 const bool getStopped() const;
322
333 const bool getLooped() const;
334
341 const bool getLoop() const;
348 const bool getReadReverse() const;
354 const float getDelay() const;
360 const std::uint32_t getFrameCount() const;
366 const std::uint32_t getInitialFrame() const;
372 const std::uint32_t getCurrentFrameIndex() const;
378 const Recoded::IntRect getCurrentFrame() const;
392 const std::pair<int, int> getFrameDimensions() const;
404 const std::vector<Recoded::IntRect> getFrames() const;
414 const std::string getInfo(const unsigned int indent = 0) const;
415
426
428
429 protected:
442 void _tick();
452 void _tickReverse();
462 void _tickRegular();
471 void _processAnimation(const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame = 0, const int endFrame = (-1));
472 const short int _getIndexUpdater(const bool startBegining = true) const;
473 const bool _continueLoop(const bool startBegining, const unsigned int position, const unsigned int maxValue) const;
474 bool _looped = false;
475 bool _loop = false;
476 bool _paused = false;
477 bool _playing = false;
478 bool _stopped = false;
479 bool _hasTicked = false;
480 bool _readReverse = false;
481 std::uint32_t _frameDelay = 100;
482 std::uint32_t _frameInitial = 0;
483 std::uint32_t _currentFrameIndex = 0;
484 std::uint32_t _totalFrames = 0;
486 std::vector<Recoded::IntRect> _frames;
489 };
490
499 std::ostream &operator<<(std::ostream &os, const AnimationComponent &item);
500
501 }
502 }
503}
This is the file that contains the Clock class.
File in charge of containing the custom errors that are going to be used for custom description error...
This is the file that links the EntityNode children.
Macro definitions for logging messages with varying levels of detail and formatting.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
This file contains the declaration of the TextureComponent class which manages textures.
bool _paused
A boolean instance in charge of informing the program to not play the animation but retain the curren...
const std::vector< Recoded::IntRect > getFrames() const
Get all the frames loaded in the animation component.
GUI::ECS::Components::TextureComponent _baseTexture
A Texture component to store the base texture that is used to derive all the animations rectangles.
void stop()
A function to stop the animation, and reset the index to the default frame.
const std::uint32_t getCurrentFrameIndex() const
Get the index of the frame that is currently in use.
const Recoded::IntRect getCurrentRectangle() const
Get the Rectangle that is currently in use.
const std::string getInfo(const unsigned int indent=0) const
This is a function meant for debugging purposes It will dump the current state of the variables upon ...
bool _readReverse
A boolean instance in charge of informing the program to read the animation backwards.
bool _hasTicked
A boolean instance in charge of informing the user that the frame has been changed.
void _tick()
Main function to process the ticking of the animation.
const bool isLooping() const
Get the information about if the component is set to loop the animation.
bool _looped
A boolean instance in charge of informing the user that the program has looped (valid for the first 2...
void _tickReverse()
Advances the animation by one frame in reverse.
const GUI::ECS::Components::TextureComponent getBaseTexture() const
Get the Base Texture object.
void start()
Start the playing of the animation from the current index in memory.
std::uint32_t _frameDelay
An unsigned integer to store the delay to wait between each frame.
bool _stopped
A boolean instance in charge of informing the program to not play the animation as well as resetting ...
const bool isStopped() const
Get the information about the state of the animation (stopped)
const bool isPlaying() const
Get the information about the state of the animation (playing)
void _tickRegular()
Advances the animation by one frame in regular (forward) order.
void setAnimation(const std::vector< Recoded::IntRect > &rects)
Set the Animation object.
const bool getTicked() const
A function to check if the frame has changed.
AnimationComponent & operator=(const GUI::ECS::Components::AnimationComponent &copy)
void resume()
Resume the playing of the animation (has no effect if already playing)
const bool _continueLoop(const bool startBegining, const unsigned int position, const unsigned int maxValue) const
bool _playing
A boolean instance in charge of informing the program to play or resume the animation.
const std::pair< int, int > getFrameDimensions() const
Get the dimension of the first frame under an std::pair<int, int> instance.
const float getDelay() const
Get the Delay object that is used before changing frames.
void checkTick()
Check if it is time to change the frame of the animation.
void forceTick()
Force the animation to tick regardless of the delay.
void update(const GUI::ECS::Components::AnimationComponent &copy)
Update the current Animation component with another Animation class.
const bool getLoop() const
Get the info about if the animation is being read in a loop or not (once at the end,...
void pause()
Pause the playing of the animation but does not reset the index to the default frame.
Recoded::IntRect _currentRectangle
A Rectangle component to store the frame that is to be displayed.
const bool isPaused() const
Get the information about the state of the animation (paused)
std::vector< Recoded::IntRect > _frames
An std::vector of Rectangle components to store all the derived frames of the animation.
std::uint32_t _currentFrameIndex
An unsigned integer to store the index of the frame that is currently active.
AnimationComponent()
Construct a new Animation Component object.
const GUI::ECS::Systems::Clock getClock() const
Get the Clock object.
~AnimationComponent()
Destroy the Animation Component object.
const bool getLooped() const
Get the information about if the animation has completed a loop (valid for the 1rst frame of the new ...
void setLoop(bool loop)
Set the Loop object.
bool _loop
A boolean instance in charge of informing the program to play the animation as a loop.
const bool getReadReverse() const
Get the info about if the order of the frames are being read from right to left instead of left to ri...
std::uint32_t _frameInitial
An unsigned integer to store the index of the initial frame (the default frame)
void setInitialFrame(std::uint32_t frameIndex)
Set the Initial Frame object.
void _processAnimation(const unsigned int frameWidth, const unsigned int frameHeight, const bool startLeft, const bool startTop, const unsigned int initialFrame=0, const int endFrame=(-1))
Function in charge of generating the animation frames based on the provided information.
const bool hasTicked()
A function to check if the frame has changed.
void setReadReverse(bool reverse)
Set the Read Reverse object.
std::uint32_t _totalFrames
An unsigned integer to store the total amount of frames in the animation.
void setDelay(float frameDuration)
Set the Delay object.
const std::uint32_t getInitialFrame() const
Get the index of the frame considered as the first in the series of the animation.
const bool hasLooped() const
A function to check if the animation has looped around (valid for the 1rst frame of the new loop)
const short int _getIndexUpdater(const bool startBegining=true) const
const std::uint32_t getFrameCount() const
Get the total number of frames contained in the animation.
const bool getStopped() const
Get the information about the state of the animation (paused/playing)
GUI::ECS::Systems::Clock _clock
A clock component that allows the Animation component to track time and know when to change frames.
const bool getPaused() const
Get the information about the state of the animation (paused/playing)
const Recoded::IntRect getCurrentFrame() const
Get the index of the frame that is currently in use.
const bool getPlaying() const
Get the information about the state of the animation (paused/playing)
Represents a texture component used in an entity component system.
A class for managing time tracking within the ECS system.
Definition Clock.hpp:36
A generic 2D rectangle class that holds position and size as pairs.
Definition Rect.hpp:38
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.