a8c0386355
This reverts commit ebfcad6f22.
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
class Menu;
|
|
class Text;
|
|
class Texture;
|
|
namespace Ja {
|
|
struct Music;
|
|
struct Sound;
|
|
} // namespace Ja
|
|
|
|
// Precarga y posee todos los recursos del juego durante toda la vida de la app.
|
|
// Singleton inicializado desde Director; las escenas consultan handles via get*().
|
|
class Resource {
|
|
public:
|
|
static void init(SDL_Renderer *renderer);
|
|
static void destroy();
|
|
static auto get() -> Resource *;
|
|
|
|
auto getTexture(const std::string &name) -> Texture *;
|
|
auto getSound(const std::string &name) -> Ja::Sound *;
|
|
auto getMusic(const std::string &name) -> Ja::Music *;
|
|
auto getAnimationLines(const std::string &name) -> std::vector<std::string> &;
|
|
auto getText(const std::string &name) -> Text *; // name sin extensión: "smb2", "nokia2", ...
|
|
auto getMenu(const std::string &name) -> Menu *; // name sin extensión: "title", "options", ...
|
|
auto getDemoBytes() const -> const std::vector<uint8_t> & { return demo_bytes_; }
|
|
|
|
private:
|
|
explicit Resource(SDL_Renderer *renderer);
|
|
~Resource();
|
|
|
|
void preloadAll();
|
|
|
|
// Helpers de preloadAll
|
|
void preloadResources();
|
|
void loadDataAsset(const std::string &bname, const std::vector<uint8_t> &bytes);
|
|
void preloadFonts();
|
|
void preloadMenus();
|
|
|
|
SDL_Renderer *renderer_;
|
|
|
|
std::unordered_map<std::string, Texture *> textures_;
|
|
std::unordered_map<std::string, Ja::Sound *> sounds_;
|
|
std::unordered_map<std::string, Ja::Music *> musics_;
|
|
std::unordered_map<std::string, std::vector<std::string>> animation_lines_;
|
|
std::unordered_map<std::string, Text *> texts_;
|
|
std::unordered_map<std::string, Menu *> menus_;
|
|
std::vector<uint8_t> demo_bytes_;
|
|
|
|
static Resource *instance;
|
|
};
|