mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
38 lines
840 B
C++
38 lines
840 B
C++
#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;
|
|
}
|
|
}
|