mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#include "assetManager.h"
|
|
#include "abstractAssetReader.h"
|
|
#include "util.h"
|
|
#include "imageReader.h"
|
|
#include "fontReader.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);
|
|
AbstractAssetReader *assetReader = nullptr;
|
|
vector<string> imageFormats = vector<string>{"png", "jpeg", "jpg"};
|
|
|
|
if(find(imageFormats.begin(), imageFormats.end(), format) != imageFormats.end())
|
|
assetReader = ImageReader::getSingleton();
|
|
|
|
vector<string> fontFormats = vector<string>{"ttf"};
|
|
|
|
if(find(fontFormats.begin(), fontFormats.end(), format) != fontFormats.end())
|
|
assetReader = FontReader::getSingleton();
|
|
|
|
assets.push_back(assetReader->readAsset(path));
|
|
}
|
|
|
|
Asset* AssetManager::getAsset(string path){
|
|
for(Asset *a : assets)
|
|
if(a->path == path)
|
|
return a;
|
|
|
|
return nullptr;
|
|
}
|
|
}
|