summaryrefslogtreecommitdiffhomepage
path: root/src/resources.cpp
diff options
context:
space:
mode:
authorarngo <[email protected]>2022-11-02 14:28:51 -0400
committerarngo <[email protected]>2022-11-02 14:28:51 -0400
commitf8f6d0d2e3e2a21bf48e0ae131015e2542f0f840 (patch)
treee4145f1db8c6de2515c3c801b0ad70275e57c7dd /src/resources.cpp
parentfde8ab552350217592ac77123e9fec394741727e (diff)
downloadorbital_game-f8f6d0d2e3e2a21bf48e0ae131015e2542f0f840.tar.gz
orbital_game-f8f6d0d2e3e2a21bf48e0ae131015e2542f0f840.zip
implement resource loader
Diffstat (limited to 'src/resources.cpp')
-rw-r--r--src/resources.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/resources.cpp b/src/resources.cpp
new file mode 100644
index 0000000..141e4ca
--- /dev/null
+++ b/src/resources.cpp
@@ -0,0 +1,27 @@
+#include <unordered_map>
+#include <string>
+#include <stdexcept>
+#include "raylib.h"
+#include "resources.h"
+
+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;
+ }
+}