42 :
EntityNode(entityId), _collisionInfo(entityId)
47 :
EntityNode(entityId), _collisionInfo(entityId)
53 :
EntityNode(entityId), _collisionInfo(entityId)
60 :
EntityNode(entityId), _collisionInfo(entityId)
76 _texture = std::make_shared<sf::Texture>();
77 const bool loadStatus = _texture->loadFromFile(filePath);
78 if (loadStatus !=
true) {
84 sf::Vector2u node = _texture->getSize();
85 _collisionInfo.setDimension({ node.x, node.y });
92 if (!texture.has_value()) {
96 if (texture.type() ==
typeid(std::shared_ptr<sf::Texture>)) {
98 if (!textureCapsule.has_value()) {
99 PRETTY_ERROR <<
"BaseId: '" <<
Recoded::myToString(getEntityNodeId()) <<
"' " <<
"There is no std::shared_ptr<sf::Texture> to be processed" << std::endl;
102 PRETTY_INFO <<
"Updating texture with the new one as a copy." << std::endl;
103 _texture = std::make_shared<sf::Texture>(*(textureCapsule.value()));
105 PRECISE_SUCCESS <<
"Updated the texture with the new one as a copy." << std::endl;
106 }
else if (texture.type() ==
typeid(sf::Texture)) {
108 if (!textCapsule.has_value()) {
112 PRETTY_INFO <<
"Updating texture with the new one using the '=' operator and not the .update function" << std::endl;
113 _texture = std::make_shared<sf::Texture>(textCapsule.value());
115 PRETTY_SUCCESS <<
"Updated the texture with a copy of the passed structure." << std::endl;
120 PRETTY_INFO <<
"Getting the texture size" << std::endl;
121 sf::Vector2u node = _texture->getSize();
122 PRETTY_INFO <<
"Setting the collision info with the new texture size" << std::endl;
123 _collisionInfo.setDimension({ node.x, node.y });
124 PRETTY_SUCCESS <<
"Dimensions for the collisionInfo is set." << std::endl;
129 _collisionInfo.update(collisionInfo);
134 _collisionInfo.setPosition(position);
140 PRETTY_WARNING <<
"There are no textures set from wich to calculate the rescale factor." << std::endl;
141 _collisionInfo.setDimension(size);
144 std::pair<float, float> result;
145 sf::Vector2u originalSize = _texture->getSize();
147 PRETTY_DEBUG <<
"Converting the texture width and height to floats" << std::endl;
148 const float originalWidth =
static_cast<float>(originalSize.x);
149 const float originalHeight =
static_cast<float>(originalSize.y);
150 PRETTY_DEBUG <<
"The values of the converted texture are: width: '" << originalWidth <<
"', height: '" << originalHeight <<
"'" << std::endl;
152 PRETTY_DEBUG <<
"Calculating the scale factors for the resulting image." << std::endl;
153 result.first = size.first / originalWidth;
154 result.second = size.second / originalHeight;
155 PRETTY_SUCCESS <<
"The calculated scale is: " << result << std::endl;
158 PRETTY_DEBUG <<
"Setting the scale factors for the resulting image." << std::endl;
159 _collisionInfo.setDimension(result);
160 PRETTY_SUCCESS <<
"The dimensions for the collisionInfo is set." << std::endl;
165 PRETTY_INFO <<
"Updating texture component" << std::endl;
175 PRETTY_SUCCESS <<
"Out of updating texture component " << std::endl;
180 PRETTY_INFO <<
"Creating an any pointer from the std::shared_ptr<sf::Texture>" << std::endl;
182 PRETTY_CRITICAL <<
"BaseId: '" <<
Recoded::myToString(getEntityNodeId()) <<
"' " <<
"The texture is not set, texture collisions '" << _collisionInfo <<
"'" << std::endl;
185 return std::make_any<std::shared_ptr<sf::Texture>>(_texture);
195 return _collisionInfo;
200 std::string indentation =
"";
201 for (
unsigned int i = 0; i < indent; ++i) {
204 std::string result = indentation +
"Texture:\n";
207 result += indentation +
"- Collision Info: {\n" + _collisionInfo.
getInfo(indent + 1) + indentation +
"}\n";
#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 PRECISE_SUCCESS
Success log with precise details.
#define PRETTY_SUCCESS
Success log with details and colour.
This file contains the declaration of the TextureComponent class which manages textures.
This is the class in charge of informing the user that the provided file path could not be found.
This is the class in charge of informing the user that they tried to access a non-existant texture in...
Represents a texture component used in an entity component system.
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 ...
TextureComponent & operator=(const GUI::ECS::Components::TextureComponent ©)
Assignment operator for copying data from another TextureComponent.
~TextureComponent()
Destructor. Cleans up resources when the component is destroyed.
void setTexture(const std::any &texture)
Sets the texture using a std::any object.
void setCollisionInfo(const GUI::ECS::Systems::Collision &collisionInfo)
Sets the collision information for the texture.
void setPosition(const std::pair< int, int > &position)
Sets the position of the texture.
const std::any getTexture() const
Retrieves the texture as a std::any object.
const bool getVisible() const
Retrieves the visibility status of the texture.
TextureComponent()
Default constructor. Initializes the component with default values.
void update(const TextureComponent ©)
Updates the texture component by copying data from another component.
void setVisible(const bool visible)
Sets the visibility of the texture.
void setFilePath(const std::string &filePath)
Sets the file path for the texture.
void setSize(const std::pair< float, float > &size)
Sets the size of the texture.
const GUI::ECS::Systems::Collision getCollisionInfo() const
Retrieves the collision information for the texture.
Represents a rectangular component that can detect collisions and mouse interactions,...
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 ...
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.