#include "texture_manager.hpp" #include "../logging/easylogging++.h" std::shared_ptr TextureManager::getInstance() { if (TextureManager::singleton == nullptr) { TextureManager::singleton = std::make_shared(); } return TextureManager::singleton; } bool TextureManager::loadTexture(const std::string& textureName, const std::string& texturePath) { if (this->doesTextureExist(textureName)) { LOG(WARNING) << "Texture " << textureName << " already loaded"; return false; } sf::Texture texture; if (!texture.loadFromFile(texturePath)) { LOG(ERROR) << "Could not load texture " << textureName << " from " << texturePath; LOG(ERROR) << "Error: " << strerror(errno); return false; } LOG(INFO) << "Loaded texture " << textureName << " from " << texturePath; this->textures[textureName] = std::make_shared(texture); return true; } bool TextureManager::doesTextureExist(const std::string& textureName) { return this->textures.find(textureName) != this->textures.end(); } TextureManager::~TextureManager() { // Unload all textures // Shared pointers will take care of the rest textures.clear(); } std::shared_ptr TextureManager::getTexture(const std::string &textureName) { if (!this->doesTextureExist(textureName)) { return nullptr; } return this->textures[textureName]; }