Loading...
Searching...
No Matches
ml::AssetsManager< Manifest > Class Template Reference

Unified asset accessor for textures, fonts, and sound buffers. More...

#include <AssetsManager.h>

Static Public Member Functions

template<typename M = Manifest>
static std::enable_if_t< has_Font< M >::value, const sf::Font & > get (typename M::Fonts font)
 Retrieve a cached sf::Font by manifest enum value.
template<typename M = Manifest>
static std::enable_if_t< has_Image< M >::value, const sf::Texture & > get (typename M::Images image)
 Retrieve a cached sf::Texture by manifest enum value.
template<typename M = Manifest>
static std::enable_if_t< has_Sound< M >::value, const sf::SoundBuffer & > get (typename M::Sounds sound)
 Retrieve a cached sf::SoundBuffer by manifest enum value.
template<typename M = Manifest>
static std::enable_if_t< has_Font< M >::value, const sf::Font & > getDefaultFont ()
 Return the built-in Arial font.

Detailed Description

template<typename Manifest>
class ml::AssetsManager< Manifest >

Unified asset accessor for textures, fonts, and sound buffers.

AssetsManager<Manifest> combines TextureManager, FontManager, and SoundManager into a single class with overloaded get() methods. Each overload is enabled only when the manifest declares the corresponding enum (Images, Fonts, or Sounds), so attempting to retrieve an asset type the manifest does not declare is a compile error rather than a runtime failure.

When to use AssetsManager vs individual managers

Scenario Recommended
Only textures needed TextureManager<Manifest>
Only fonts needed FontManager<Manifest>
Mix of textures, fonts, sounds AssetsManager<Manifest>
Also need config values Context<Manifest>

Usage

class MyManifest : public ml::Manifest {
public:
enum class Images { Background, Player };
enum class Fonts { Main };
enum class Sounds { Jump };
private:
inline static const auto _ = [](){
set(Images::Background, "assets/bg.png");
set(Images::Player, "assets/player.png");
set(Fonts::Main, "assets/main.ttf");
set(Sounds::Jump, "assets/jump.wav");
return 0;
}();
};
// All three asset types via one manager
const sf::Texture& bg = ml::AssetsManager<MyManifest>::get(MyManifest::Images::Background);
const sf::Font& fnt = ml::AssetsManager<MyManifest>::get(MyManifest::Fonts::Main);
const sf::SoundBuffer& sfx = ml::AssetsManager<MyManifest>::get(MyManifest::Sounds::Jump);
// Default font (built-in Arial) — no manifest entry needed
static std::enable_if_t< has_Image< M >::value, const sf::Texture & > get(typename M::Images image)
Retrieve a cached sf::Texture by manifest enum value.
static std::enable_if_t< has_Font< M >::value, const sf::Font & > getDefaultFont()
Return the built-in Arial font.
Base class for all Malena manifests.
Definition Manifest.h:81
static void set(EnumType key, const char *filepath)
Register an asset file path.
Template Parameters
ManifestA Manifest subclass declaring Images, Fonts, and/or Sounds enums.
See also
TextureManager, FontManager, SoundManager, Context, Manifest

AssetsManager.

Definition at line 92 of file AssetsManager.h.

Member Function Documentation

◆ get() [1/3]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Font< M >::value, const sf::Font & > ml::AssetsManager< Manifest >::get ( typename M::Fonts font)
static

Retrieve a cached sf::Font by manifest enum value.

Only available when Manifest declares a Fonts enum.

Parameters
fontThe Fonts enum value identifying the font.
Returns
Const reference to the cached sf::Font.

◆ get() [2/3]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Image< M >::value, const sf::Texture & > ml::AssetsManager< Manifest >::get ( typename M::Images image)
static

Retrieve a cached sf::Texture by manifest enum value.

Only available when Manifest declares an Images enum.

Parameters
imageThe Images enum value identifying the texture.
Returns
Const reference to the cached sf::Texture.

◆ get() [3/3]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Sound< M >::value, const sf::SoundBuffer & > ml::AssetsManager< Manifest >::get ( typename M::Sounds sound)
static

Retrieve a cached sf::SoundBuffer by manifest enum value.

Only available when Manifest declares a Sounds enum.

Parameters
soundThe Sounds enum value identifying the sound buffer.
Returns
Const reference to the cached sf::SoundBuffer.

◆ getDefaultFont()

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Font< M >::value, const sf::Font & > ml::AssetsManager< Manifest >::getDefaultFont ( )
static

Return the built-in Arial font.

Only available when Manifest declares a Fonts enum. Delegates to FontManager::getDefault().

Returns
Const reference to the built-in sf::Font.

The documentation for this class was generated from the following file: