From 765485ced528ca2f4cf644a1503b9446c5826731 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Sun, 22 Sep 2024 10:58:21 +0200 Subject: spritesheet werkt --- resource-manager/resource_manager.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'resource-manager/resource_manager.h') 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 #include #include #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 + T* Load(const Constants::FILE_PATH& file_path){ + + if (m_resources.find(file_path) != m_resources.end()) { + return static_cast(m_resources[file_path]); + } + + Resource* resource = ResourceFactory::create_resource(file_path); + if (resource) { + m_resources[file_path] = std::move(resource); + } + return static_cast(m_resources[file_path]); + } + void Unload(const Constants::FILE_PATH& file_path); private: std::unordered_map m_resources; -- cgit v1.2.3