17 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
18 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
23 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
24 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
30 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
31 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
38 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
39 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
46 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
47 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
54 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
55 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
63 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
64 _hoverColor(0), _normalColor(0), _clickedColor(0)
72 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
73 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
81 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
82 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
90 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
91 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
100 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
101 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
110 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
111 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
121 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
122 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
133 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
134 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
145 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
146 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
157 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
158 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
170 :
EntityNode(0), _spritesheet(0), _collision(0), _animation(0),
171 _hoverColor(0,
GUI::ECS::Systems::Colour::White), _normalColor(0,
GUI::ECS::Systems::Colour::White), _clickedColor(0,
GUI::ECS::Systems::Colour::White)
185 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
186 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
191 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
192 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
199 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
200 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
207 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
208 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
215 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
216 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
223 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
224 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
232 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
233 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
241 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
242 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
244 PRETTY_INFO <<
"In sprite constructor taking an entity id, a name and an animation." << std::endl;
251 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
252 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
254 PRETTY_INFO <<
"In sprite constructor taking an entity id, a name and a spritesheet texture." << std::endl;
261 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
262 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
271 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
272 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
281 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
282 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
292 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
293 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
304 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
305 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
316 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
317 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
328 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
329 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
341 :
EntityNode(entityId), _spritesheet(entityId), _collision(entityId), _animation(entityId),
342 _hoverColor(entityId,
GUI::ECS::Systems::Colour::White), _normalColor(entityId,
GUI::ECS::Systems::Colour::White), _clickedColor(entityId,
GUI::ECS::Systems::Colour::White)
358 PRETTY_INFO <<
"Setting sprite name to '" << name <<
"'" << std::endl;
360 PRETTY_SUCCESS <<
"Sprite name set to '" << name <<
"'" << std::endl;
365 _application = application;
370 _collision.update(copy);
372 _collisionSet =
true;
377 _spritesheet.setFilePath(spritesheetPath);
378 std::any textureCapsule = _spritesheet.getTexture();
379 if (!textureCapsule.has_value()) {
380 PRETTY_ERROR <<
"There is no texture to manage" << std::endl;
383 _spritesheetSet =
true;
384 setSpritesheet(_spritesheet);
389 _normalColor = color;
399 _clickedColor = color;
404 _spritesheet.
update(spritesheetTexture);
405 _spritesheetSet =
true;
406 if (!_sfSprite.has_value()) {
407 PRETTY_ERROR <<
"There is no sprite instance" << std::endl;
410 std::any textureCapsule = _spritesheet.getTexture();
411 if (!textureCapsule.has_value()) {
412 PRETTY_ERROR <<
"There is not texture instance" << std::endl;
415 std::shared_ptr<sf::Texture> texture = std::any_cast<std::shared_ptr<sf::Texture>>(textureCapsule);
416 _sfSprite->setTexture(*texture);
422 PRETTY_INFO <<
"Setting sprite animation." << std::endl;
423 PRETTY_INFO <<
"Updating the _animation node with the child version." << std::endl;
424 _animation.update(animation);
426 PRETTY_INFO <<
"Updating the collision node with the child version. '" << _spriteName <<
"'" << std::endl;
428 PRETTY_SUCCESS <<
"Collision updated for sprite '" << _spriteName <<
"'" << std::endl;
429 _animationSet =
true;
430 _collisionSet =
true;
442 _collision.setPosition(pos);
448 _collision.setDimension(dim);
464 _collision.update(mouse);
473 setAnimation(animation);
486 if (!_visible || !_sfSprite.has_value()) {
487 PRETTY_DEBUG <<
"Instance is hidden or no sfImage instance found, not rendering" << std::endl;
490 return std::make_any<sf::Sprite>(_sfSprite.value());
515 return _collisionSet;
520 return _animationSet;
525 return _spritesheetSet;
540 return _animation.isLooping();
545 return _animation.isPaused();
550 return _animation.isPlaying();
555 return _animation.isStopped();
560 return _animation.hasTicked();
565 return _animation.hasLooped();
572 if (!_animationSet) {
573 PRETTY_ERROR <<
"There are no animations set, skipping tick" << std::endl;
576 PRETTY_INFO <<
"Running animation.checkTick()" << std::endl;
577 _animation.checkTick();
578 PRETTY_INFO <<
"Animation checkTick ran, checking if frames need to be updated." << std::endl;
579 if (!_animation.hasTicked()) {
580 PRETTY_WARNING <<
"No tick has occurred yet, nothing to do, exiting function" << std::endl;
583 PRETTY_DEBUG <<
"Animation has ticked, Getting the updated rectangle." << std::endl;
585 PRETTY_DEBUG <<
"Got the updated rectangle, updating sprite." << std::endl;
586 if (!_sfSprite.has_value()) {
587 PRETTY_WARNING <<
"There is no sprite value, initialising sprite." << std::endl;
591 PRETTY_DEBUG <<
"Converting internal rectangle to sf::IntRect." << std::endl;
592 sf::IntRect transporter = {
598 RectComponent.
size.first,
599 RectComponent.
size.second
602 PRETTY_DEBUG <<
"sf::IntRect initialised." << std::endl;
603 _sfSprite->setTextureRect(transporter);
612 if (!_animationSet) {
613 PRETTY_ERROR <<
"There are no animations set, skipping tick" << std::endl;
616 PRETTY_INFO <<
"Running animation.forceTick()" << std::endl;
617 _animation.forceTick();
618 PRETTY_INFO <<
"Animation forceTick ran, updating the frame." << std::endl;
619 PRETTY_DEBUG <<
"Animation has ticked, Getting the updated rectangle." << std::endl;
621 PRETTY_DEBUG <<
"Got the updated rectangle, updating sprite." << std::endl;
622 if (!_sfSprite.has_value()) {
623 PRETTY_WARNING <<
"There is no sprite value, initialising sprite." << std::endl;
627 PRETTY_DEBUG <<
"Converting internal rectangle to sf::IntRect." << std::endl;
628 sf::IntRect transporter = {
634 RectComponent.
size.first,
635 RectComponent.
size.second
638 PRETTY_DEBUG <<
"sf::IntRect initialised." << std::endl;
639 _sfSprite->setTextureRect(transporter);
661 if (!_spritesheetSet) {
669 if (!_collisionSet) {
677 if (!_animationSet) {
695 return _clickedColor;
702 std::string indentation =
"";
703 for (
unsigned int i = 0; i < indent; ++i) {
706 std::string result = indentation +
"Sprite:\n";
709 result += indentation +
"- Name: '" + _spriteName +
"'\n";
710 result += indentation +
"- Application: '" + _application +
"'\n";
711 result += indentation +
"- Spritesheet Set: " +
Recoded::myToString(_spritesheetSet) +
"\n";
712 result += indentation +
"- Spritesheet: {\n" + _spritesheet.
getInfo(indent + 1) + indentation +
"}\n";
714 result += indentation +
"- Collision: {\n" + _collision.getInfo(indent + 1) + indentation +
"}\n";
716 result += indentation +
"- Animation: {\n" + _animation.getInfo(indent + 1) + indentation +
"}\n";
718 result += indentation +
"- (sfSprite) Has sprite: " +
Recoded::myToString(_sfSprite.has_value()) +
"\n";
719 result += indentation +
"- Hover Color: {\n" + _hoverColor.getInfo(indent + 1) + indentation +
"}\n";
720 result += indentation +
"- Normal Color: {\n" + _normalColor.getInfo(indent + 1) + indentation +
"}\n";
721 result += indentation +
"- Clicked Color: {\n" + _clickedColor.getInfo(indent + 1) + indentation +
"}\n";
733void GUI::ECS::Components::SpriteComponent::_initialiseSprite()
735 if (_sfSprite.has_value()) {
738 std::any textureCapsule = _spritesheet.getTexture();
739 if (textureCapsule.has_value()) {
740 std::optional<std::shared_ptr<sf::Texture>> texture = std::any_cast<std::shared_ptr<sf::Texture>>(textureCapsule);
741 if (!texture.has_value()) {
745 _sfSprite.emplace(*(texture.value()));
749void GUI::ECS::Components::SpriteComponent::_processSpriteColor()
751 if (!_sfSprite.has_value()) {
755 if (!_collisionSet) {
756 PRETTY_ERROR <<
"Collision component not set" << std::endl;
759 std::any systemColour;
760 if (_collision.isClicked()) {
762 << _clickedColor <<
"\n} and corresponds to the _clickedColour"
764 systemColour = _clickedColor.getRenderColour();
765 }
else if (_collision.isHovered()) {
767 << _hoverColor <<
"\n} and corresponds to the _hoverColour"
769 systemColour = _hoverColor.getRenderColour();
772 << _normalColor <<
"\n} and corresponds to the _normalColour"
774 systemColour = _normalColor.getRenderColour();
776 const std::string errMsg =
"<The content returned by the getRenderColour function is not of type sf::Color>, system error: ";
778 if (!color.has_value()) {
780 <<
"No Color found, " << errMsg << std::endl;
783 _sfSprite->setColor(color.value());
787void GUI::ECS::Components::SpriteComponent::_processCollision()
790 if (!_sfSprite.has_value()) {
793 std::pair<float, float> pos = _collision.getPosition();
794 std::pair<float, float> dim = _collision.getDimension();
795 _sfSprite->setPosition({ pos.first, pos.second });
796 _sfSprite->setScale({ dim.first, dim.second });
797 _processSpriteColor();
800void GUI::ECS::Components::SpriteComponent::_processSprite()
804 _processSpriteColor();
#define PRETTY_ERROR
Error log with details and colour.
#define PRETTY_DEBUG
Debug log with details and colour.
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_CRITICAL
Critical log with details and colour.
#define PRETTY_WARNING
Warning log with details and colour.
#define PRETTY_SUCCESS
Success log with details and colour.
This is the file that contains the class in charge of managing a sprite.
This is the class in charge of informing the user that they tried to access a non-existant animation ...
This is the class in charge of informing the user that they tried to access a non-existant collision ...
This is the class in charge of informing the user that they tried to access a non-existant colour ins...
This is the class in charge of informing the user that they tried to access a non-existant spriteshee...
const GUI::ECS::Components::TextureComponent getBaseTexture() const
Get the Base Texture object.
const std::pair< int, int > getFrameDimensions() const
Get the dimension of the first frame under an std::pair<int, int> instance.
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 ©)
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.
~SpriteComponent()
Destructor.
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 ©)
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)
SpriteComponent()
Default constructor.
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,...
A class for representing and manipulating colors using RGBA components. Inherits from EntityNode to a...
void update(const Colour ©)
Updates the color by copying from another Colour instance.
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 ...
A generic 2D rectangle class that holds position and size as pairs.
std::pair< T, T > size
The size of the rectangle (width, height)
std::pair< T, T > position
the position (top and left corner)
std::ostream & operator<<(std::ostream &os, const AnimationComponent &item)
Outputs the animation's info to a stream.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.
std::optional< T > unCast(const std::any &classNode, const bool raiseOnError=true, const std::string customErrorMessage="")
Casts the content of a std::any back to its original type.