Skip to content

File AssetManager.hpp

File List > Assets > AssetManager.hpp

Go to the documentation of this file

#ifndef ENGINE_CORE_ASSETMANAGER_HPP_
#define ENGINE_CORE_ASSETMANAGER_HPP_

#include "Music.hpp"
#include "Sound.hpp"
#include "Sprites.hpp"
#include <memory>
#include <string>
#include <unordered_map>

namespace Engine {
class AssetManager {
  public:
    AssetManager() = default;

    ~AssetManager() {
        ClearAll();
    }

    AssetManager(const AssetManager&) = delete;

    AssetManager& operator=(const AssetManager&) = delete;

    AssetManager(AssetManager&&) = delete;

    AssetManager& operator=(AssetManager&&) = delete;

    void LoadSound(const std::string& alias, const std::string& filePath, bool isLoop = false);

    void LoadSoundFromMemory(const std::string& alias, const char* fileType,
                             const unsigned char* data, int dataSize, bool isLoop = false);

    std::shared_ptr<Sound> GetSound(const std::string& alias);

    void UnloadSound(const std::string& alias);

    void LoadSprite(const std::string& alias, const std::string& filePath);

    std::shared_ptr<Sprite> GetSprite(const std::string& alias);

    void UnloadSprite(const std::string& alias);

    void LoadMusic(const std::string& alias, const std::string& filePath, bool isLoop = false);

    void LoadMusicFromMemory(const std::string& alias, const char* fileType,
                             const unsigned char* data, int dataSize, bool isLoop = false);

    std::shared_ptr<Music> GetMusic(const std::string& alias);

    void UnloadMusic(const std::string& alias);

    void ClearAll();

    void LoadFontFromMemory(const std::string& alias, const std::string& fileType,
                            const unsigned char* fileData, int dataSize, int fontSize = 12,
                            int* fontChars = nullptr, int charsCount = 0);

    std::shared_ptr<raylib::Font> GetFont(const std::string& alias);

    std::unordered_map<std::string, std::shared_ptr<Music>>& GetAllMusic() {
        return m_Musics;
    }

    std::unordered_map<std::string, std::shared_ptr<Sound>>& GetAllSounds() {
        return m_Sounds;
    }

  private:
    std::unordered_map<std::string, std::shared_ptr<Sound>> m_Sounds;
    std::unordered_map<std::string, std::shared_ptr<Sprite>> m_Sprites;
    std::unordered_map<std::string, std::shared_ptr<Music>> m_Musics;
    std::unordered_map<std::string, std::shared_ptr<raylib::Font>> m_Fonts;
};
} // namespace Engine

#endif // ENGINE_CORE_ASSETMANAGER_HPP_