43 lines
738 B
C++
43 lines
738 B
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <map>
|
|
|
|
namespace sf { class Texture; class Font; }
|
|
|
|
template <typename Resource, typename Id>
|
|
class ResourceHolder
|
|
{
|
|
public:
|
|
bool load(Id id, const std::string& filename)
|
|
{
|
|
auto resource = std::make_unique<Resource>();
|
|
if (!resource->loadFromFile(filename))
|
|
return false;
|
|
|
|
_resources[id] = std::move(resource);
|
|
|
|
return true;
|
|
}
|
|
|
|
Resource& get(Id id) const
|
|
{
|
|
const auto found = _resources.find(id);
|
|
return *found->second;
|
|
}
|
|
|
|
private:
|
|
std::map<Id, std::unique_ptr<Resource>> _resources;
|
|
};
|
|
|
|
namespace Fonts
|
|
{
|
|
enum class Id
|
|
{
|
|
GUI
|
|
};
|
|
}
|
|
|
|
using FontHolder = ResourceHolder<sf::Font, Fonts::Id>;
|
|
|