R-Type  2
Doom but in better
Loading...
Searching...
No Matches
SpriteComponent.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** SpriteComponent.hpp
6*/
7
13#pragma once
14
15#include <any>
16#include <memory>
17#include <optional>
18#include <SFML/Graphics/Sprite.hpp>
19
20#include "Log.hpp"
21#include "LogMacros.hpp"
22#include "Utilities.hpp"
23#include "CustomExceptions.hpp"
29
30namespace GUI
31{
32 namespace ECS
33 {
34 namespace Components
35 {
44 class SpriteComponent : public EntityNode {
45 public:
57 SpriteComponent(const std::string &name);
84 SpriteComponent(const std::string &name, const std::string &spritesheetPath);
93 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision);
102 SpriteComponent(const std::string &name, const GUI::ECS::Components::AnimationComponent &animation);
111 SpriteComponent(const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture);
122 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation);
133 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture);
146 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
161 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
176 SpriteComponent(const std::string &name, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
191 SpriteComponent(const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
208 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
225 SpriteComponent(const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
226
232 SpriteComponent(const std::uint32_t entityId);
241 SpriteComponent(const std::uint32_t entityId, const std::string &name);
250 SpriteComponent(const std::uint32_t entityId, const GUI::ECS::Systems::Collision &collision);
259 SpriteComponent(const std::uint32_t entityId, const GUI::ECS::Components::AnimationComponent &animation);
268 SpriteComponent(const std::uint32_t entityId, const GUI::ECS::Components::TextureComponent &spritesheetTexture);
279 SpriteComponent(const std::uint32_t entityId, const std::string &name, const std::string &spritesheetPath);
290 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision);
301 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::AnimationComponent &animation);
312 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture);
325 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation);
338 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture);
353 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
370 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
387 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
404 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
423 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::AnimationComponent &animation, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
442 SpriteComponent(const std::uint32_t entityId, const std::string &name, const GUI::ECS::Systems::Collision &collision, const GUI::ECS::Components::TextureComponent &spritesheetTexture, const GUI::ECS::Systems::Colour &normalColor, const GUI::ECS::Systems::Colour &hoverColor, const GUI::ECS::Systems::Colour &clickedColor);
443
448
454 void setName(const std::string &name);
460 void setApplication(const std::string &application);
469
475 void setNormalColor(const GUI::ECS::Systems::Colour &color);
481 void setHoverColor(const GUI::ECS::Systems::Colour &color);
488
494 void setSpritesheet(const std::string &spritesheetPath);
500 void setSpritesheet(const GUI::ECS::Components::TextureComponent &spritesheetTexture);
501
508
514 void setVisible(const bool visible);
515
521 void setPosition(const std::pair<int, int> &pos);
522
528 void setDimension(const std::pair<float, float> &dim);
529
534 void toggleVisibility();
535
543 void update(const GUI::ECS::Systems::MouseInfo &mouse);
544
551
558
566 std::any render() const;
567
572 void start();
573
578 void pause();
583 void resume();
584
589 void stop();
590
596 const bool isCollisionSet() const;
602 const bool isAnimationSet() const;
608 const bool isSpritesheetSet() const;
614 const bool isSpriteSet() const;
615
622 const bool isVisible() const;
623
630 const bool isLooping() const;
631
638 const bool isPaused() const;
645 const bool isPlaying() const;
652 const bool isStopped() const;
653
660 const bool hasTicked();
661
668 const bool hasLooped() const;
669
673 void checkTick();
674
678 void forceTick();
679
686 const bool getVisible() const;
692 const std::string getName() const;
698 const std::string getApplication() const;
723
751 const std::string getInfo(const unsigned int indent = 0) const;
752
761
762 private:
767 void _initialiseSprite();
771 void _processSprite();
772
776 void _processCollision();
777
781 void _processSpriteColor();
782
783 bool _visible = true;
784 std::string _application = "";
785 std::string _spriteName = "";
786 bool _spritesheetSet = false;
788 bool _collisionSet = false;
790 bool _animationSet = false;
792 bool _spriteSet = false;
793 std::optional<sf::Sprite> _sfSprite;
794 GUI::ECS::Systems::Colour _hoverColor;
795 GUI::ECS::Systems::Colour _normalColor;
796 GUI::ECS::Systems::Colour _clickedColor;
797 };
798
807 std::ostream &operator<<(std::ostream &os, const SpriteComponent &item);
808 }
809 }
810}
This is the file that contains the class in charge of tracking sprite animations.
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.
Represents a drawable and interactive sprite in the ECS system.
void setNormalColor(const GUI::ECS::Systems::Colour &color)
Set the default colour of the sprite.
const bool isSpriteSet() const
Checks if the sprite is initialized.
const GUI::ECS::Systems::Collision getCollision() const
Gets the collision component associated with the sprite.
void update(const GUI::ECS::Systems::MouseInfo &mouse)
Updates the sprite based on mouse input.
void checkTick()
Processes and updates sprite properties based on tick state of the clock internal to it's animation c...
void setSpritesheet(const std::string &spritesheetPath)
Sets the texture of the sprite using a file path.
void setAnimation(const GUI::ECS::Components::AnimationComponent &animation)
Associates an animation component with the sprite.
const std::string getApplication() const
Gets the application name associated with the sprite.
const bool isAnimationSet() const
Checks if animation data is set.
void setClickedColor(const GUI::ECS::Systems::Colour &color)
Set the Clicked Color of the sprite.
const bool hasTicked()
A function to check if the frame has changed.
const GUI::ECS::Systems::Colour getNormalColor() const
Get the colour of the default state for the class.
void toggleVisibility()
Change the visibility of the sprite, if visible becomes invisible and vise versa.
const GUI::ECS::Systems::Colour getHoverColor() const
Get the colour of the hover state for the class.
void setName(const std::string &name)
Sets the name of the sprite.
const bool isStopped() const
Get the information about the state of the animation (stopped)
SpriteComponent & operator=(const GUI::ECS::Components::SpriteComponent &copy)
Overloads the assignment operator to copy from another SpriteComponent.
void pause()
Pause the playing of the animation but does not reset the index to the default frame.
void setVisible(const bool visible)
Set the visible of the sprite.
const bool getVisible() const
Check if the sprite is set to be rendred or not.
void setApplication(const std::string &application)
Sets the application name (the name is based on the configuration file) associated with the sprite.
void setHoverColor(const GUI::ECS::Systems::Colour &color)
Set the Hover Color of the sprite.
void stop()
A function to stop the animation, and reset the index to the default frame.
const bool isSpritesheetSet() const
Checks if a spritesheet texture is set.
const std::string getName() const
Gets the name of the sprite.
void setCollision(const GUI::ECS::Systems::Collision &copy)
Associates a collision component with the sprite.
void setDimension(const std::pair< float, float > &dim)
Set the dimensions of the sprite.
const GUI::ECS::Systems::Colour getClickedColor() const
Get the colour of the clicked state for the class.
std::any render() const
Renders the sprite to a window.
void setPosition(const std::pair< int, int > &pos)
Set the Position of the sprite.
const bool isLooping() const
Get the information about if the component is set to loop the animation.
const bool isCollisionSet() const
Checks if collision data is set.
void start()
Start the playing of the animation from the current index in memory.
void forceTick()
Updates the animation frame regardless of the delay.
const bool isPlaying() const
Get the information about the state of the animation (playing)
const GUI::ECS::Components::AnimationComponent getAnimation() const
Gets the animation component associated with the sprite.
const GUI::ECS::Components::TextureComponent getSpritesheet() const
Gets the texture component associated with the sprite.
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 ...
const bool hasLooped() const
A function to check if the animation has looped around (valid for the 1rst frame of the new loop)
void resume()
Resume the playing of the animation (has no effect if already playing)
const bool isPaused() const
Get the information about the state of the animation (paused)
const bool isVisible() const
Check if the sprite is set to be rendred or not.
Represents a texture component used in an entity component system.
Represents a rectangular component that can detect collisions and mouse interactions,...
Definition Collision.hpp:39
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
Definition Colour.hpp:37
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.