| 77 | } |
| 78 | |
| 79 | std::shared_ptr<const sf::Image> ResourceManager::GetImage( const std::string& path ) { |
| 80 | auto image_iter = m_images.find( path ); |
| 81 | |
| 82 | if( image_iter != m_images.end() ) { |
| 83 | return image_iter->second; |
| 84 | } |
| 85 | |
| 86 | // Try to load. |
| 87 | auto loader = GetMatchingLoader( path ); |
| 88 | |
| 89 | if( !loader ) { |
| 90 | return std::shared_ptr<const sf::Image>(); |
| 91 | } |
| 92 | |
| 93 | auto image = loader->LoadImage( GetFilename( path, *loader ) ); |
| 94 | |
| 95 | if( !image ) { |
| 96 | return std::shared_ptr<const sf::Image>(); |
| 97 | } |
| 98 | |
| 99 | // Cache. |
| 100 | m_images[path] = image; |
| 101 | return image; |
| 102 | } |
| 103 | |
| 104 | std::shared_ptr<const ResourceLoader> ResourceManager::GetMatchingLoader( const std::string& path ) { |
| 105 | if( path.empty() || ( path == "Default" ) ) { |