aboutsummaryrefslogtreecommitdiff
path: root/resource-manager/resource_manager.h
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-09-22 10:58:21 +0200
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-09-22 10:58:21 +0200
commit765485ced528ca2f4cf644a1503b9446c5826731 (patch)
treee9d35c04a8768afb38873daa31d1b47a3da93e54 /resource-manager/resource_manager.h
parent507a97739726feb74ffa91e317ead1773183ccbf (diff)
spritesheet werkt
Diffstat (limited to 'resource-manager/resource_manager.h')
-rw-r--r--resource-manager/resource_manager.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/resource-manager/resource_manager.h b/resource-manager/resource_manager.h
index 7a86360..fd6657c 100644
--- a/resource-manager/resource_manager.h
+++ b/resource-manager/resource_manager.h
@@ -2,12 +2,14 @@
+#include <algorithm>
#include <string>
#include <unordered_map>
#include "resource.h"
#include "constants.h"
+#include "resource_fabricator.h"
using namespace crepe;
@@ -20,9 +22,21 @@ public:
ResourceManager();
~ResourceManager();
- Resource* Load(const Constants::FILE_PATH& file_path);
- void Unload(const Constants::FILE_PATH& file_path);
+ template<typename T>
+ T* Load(const Constants::FILE_PATH& file_path){
+
+ if (m_resources.find(file_path) != m_resources.end()) {
+ return static_cast<T*>(m_resources[file_path]);
+ }
+
+ Resource* resource = ResourceFactory::create_resource(file_path);
+ if (resource) {
+ m_resources[file_path] = std::move(resource);
+ }
+ return static_cast<T*>(m_resources[file_path]);
+ }
+ void Unload(const Constants::FILE_PATH& file_path);
private:
std::unordered_map<Constants::FILE_PATH, Resource*> m_resources;