blob: 9d1834ace3cffaa50ea6d344787945ec94c6a950 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include <unordered_map>
#include <string>
#include <stdexcept>
#include "raylib.h"
#include "resources.hpp"
namespace Resources {
static std::unordered_map<std::string, std::string> textureFiles = {
{"ship", "./assets/textures/spaceShooter2_spritesheet_2X.png"}
};
static std::unordered_map<std::string, Texture> textures;
Texture useTexture(std::string id) {
Texture texture;
auto texSearch = textures.find(id);
if (texSearch != textures.end()) {
return texSearch->second;
}
auto texPathSearch = textureFiles.find(id);
if (texPathSearch != textureFiles.end()) {
texture = LoadTexture(texPathSearch->second.c_str());
textures.insert({id, texture});
} else {
throw std::invalid_argument("Texture id '" + id + "' has no assigned path.");
}
return texture;
}
}
|