CmResources.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "CmResources.h"
  2. #include "CmResource.h"
  3. #include "CmException.h"
  4. #include "CmFileSerializer.h"
  5. namespace CamelotEngine
  6. {
  7. Resources::Resources()
  8. {
  9. }
  10. Resources::~Resources()
  11. {
  12. }
  13. ResourcePtr Resources::load(const String& filePath)
  14. {
  15. FileSerializer fs;
  16. std::shared_ptr<IReflectable> loadedData = fs.decode(filePath);
  17. // TODO - Low priority. Check is file path valid?
  18. if(loadedData == nullptr)
  19. CM_EXCEPT(InternalErrorException, "Unable to load resource.");
  20. if(!loadedData->isDerivedFrom(Resource::getRTTIStatic()))
  21. CM_EXCEPT(InternalErrorException, "Loaded class doesn't derive from Resource.");
  22. ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
  23. resource->load();
  24. return resource;
  25. }
  26. ResourcePtr Resources::load(const UUID& uuid)
  27. {
  28. CM_EXCEPT(NotImplementedException, "Not implemented");
  29. }
  30. void Resources::save(ResourcePtr resource, const String& filePath)
  31. {
  32. assert(resource != nullptr);
  33. // TODO - Low priority. Check is file path valid?
  34. FileSerializer fs;
  35. fs.encode(resource.get(), filePath);
  36. }
  37. CM_EXPORT Resources& gResources()
  38. {
  39. return Resources::instance();
  40. }
  41. }