implemented image reader and asset manager

This commit is contained in:
devZoGok
2022-03-02 20:24:04 +02:00
parent f64a3e13df
commit 82bf653e68
11 changed files with 171 additions and 22 deletions
+37
View File
@@ -0,0 +1,37 @@
#include "assetManager.h"
#include "imageReader.h"
#include "util.h"
#include <algorithm>
using namespace std;
namespace vb01{
AssetManager *assetManager = nullptr;
AssetManager* AssetManager::getSingleton(){
if(!assetManager)
assetManager = new AssetManager();
return assetManager;
}
void AssetManager::load(string path){
if(getAsset(path))
return;
string format = path.substr(path.find_last_of(".") + 1, string::npos);
vector<string> imageFormats = vector<string>{"png", "jpg", "jpeg"};
if(*find(imageFormats.begin(), imageFormats.end(), format) == format)
assets.push_back(ImageReader::getSingleton()->readImage(path, true));
}
Asset* AssetManager::getAsset(string path){
for(Asset *a : assets)
if(a->path == path)
return a;
return nullptr;
}
}