59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#ifndef ASSETS_HPP
|
|
#define ASSETS_HPP
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3_image/SDL_image.h>
|
|
#include <unordered_map>
|
|
#include <string>
|
|
|
|
// Structs
|
|
struct Rect {
|
|
int x;
|
|
int y;
|
|
int width;
|
|
int height;
|
|
|
|
Rect(int x = 0, int y = 0, int width = 0, int height = 0)
|
|
: x(x), y(y), width(width), height(height) {}
|
|
Rect(const SDL_Rect& rect)
|
|
: x(rect.x), y(rect.y), width(rect.w), height(rect.h) {}
|
|
};
|
|
|
|
struct Tile {
|
|
Rect srcRect;
|
|
std::string assetName;
|
|
};
|
|
|
|
// Classes
|
|
class AssetManager {
|
|
public:
|
|
AssetManager();
|
|
~AssetManager();
|
|
|
|
void load(const std::string& name, const std::string& filePath);
|
|
SDL_Surface* getAsset(const std::string& name) const;
|
|
void unloadAsset(const std::string& name);
|
|
void clearAssets();
|
|
|
|
private:
|
|
std::unordered_map<std::string, SDL_Surface*> assets;
|
|
};
|
|
|
|
struct TileMap {
|
|
public:
|
|
TileMap(AssetManager& assetManager);
|
|
~TileMap();
|
|
|
|
void addTile(const std::string& name, const Tile& tile);
|
|
Tile getTile(const std::string& name) const;
|
|
SDL_Surface* getTileAsset(const std::string& name) const;
|
|
Rect getTileRect(const std::string& name) const;
|
|
void removeTile(const std::string& name);
|
|
void clear();
|
|
|
|
private:
|
|
std::unordered_map<std::string, Tile> tiles;
|
|
AssetManager& assetManager;
|
|
};
|
|
|
|
#endif |