#include "ResourceManager.h" #include "MazeMap.h" #include #include #include #include #include #include #include #include bool ResourceManager::loadTexture(const std::string& textureName, const std::filesystem::path& texturePath) { auto texture = std::make_unique(); if (!texture->loadFromFile(texturePath)) return false; textures[textureName] = std::move(texture); return true; }; bool ResourceManager::loadFont(const std::string& fontName, const std::filesystem::path& fontPath) { sf::Font font; if (!font.openFromFile(fontPath)) return false; fonts[fontName] = font; return true; }; bool ResourceManager::loadMap(const std::string& mapName, const std::filesystem::path& mapPath) { std::ifstream file(mapPath); if (!file.is_open()) return false; std::vector mapData; int value; while (file >> value) { mapData.push_back(value); } file.close(); if (mapName == "mazeMap") mazeMap = mapData; if (mapName == "pelletMap") pelletMap = mapData; return !mapData.empty(); }; bool ResourceManager::loadSound(const std::string& soundName, const std::filesystem::path& soundPath) { sounds[soundName] = sf::SoundBuffer(soundPath); return true; }; void ResourceManager::resizeTexture(const std::string& textureName, unsigned int newTextureTileSize) { auto it = textures.find(textureName); if (it == textures.end()) return; sf::Texture& originalTexture = *it->second; originalTexture.setSmooth(false); float scaleFactor = static_cast(newTextureTileSize) / static_cast(textureTileSize); sf::Vector2u originalSize = originalTexture.getSize(); sf::Vector2u newSize( static_cast(originalSize.x * scaleFactor), static_cast(originalSize.y * scaleFactor) ); sf::RenderTexture renderTexture(newSize); renderTexture.clear(sf::Color::Transparent); sf::Sprite sprite(originalTexture); sprite.setScale({scaleFactor, scaleFactor}); renderTexture.draw(sprite); renderTexture.display(); auto newTexture = std::make_unique(renderTexture.getTexture()); newTexture->setSmooth(false); textures[textureName] = std::move(newTexture); };