ADD: Include Textures in Assetmanager
This commit is contained in:
parent
e62f3ffacc
commit
1941ee3690
@ -68,6 +68,21 @@ std::shared_ptr<ModelStageConfiguration> AssetManager::getModelStageConfiguratio
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<ModelTexture> AssetManager::loadTexture(const std::string& name, const std::string &texturePath, Loader &loader) {
|
||||
if (textures.contains(name)) {
|
||||
return textures[name];
|
||||
}
|
||||
|
||||
auto texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(texturePath));
|
||||
textures[name] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
std::shared_ptr<ModelTexture> AssetManager::getTexture(const std::string &name) {
|
||||
assert(textures.contains(name) && "Texture not found!");
|
||||
return textures.at(name);
|
||||
}
|
||||
|
||||
|
||||
json AssetManager::readJsonFile(const std::string &path) {
|
||||
if (fs::exists(path)) {
|
||||
|
||||
@ -21,9 +21,12 @@ public:
|
||||
static void loadAsset(const std::string& assetPath, Loader& loader);
|
||||
static std::shared_ptr<ModelStages> getModelStages(const std::string& modelName);
|
||||
static std::shared_ptr<ModelStageConfiguration> getModelStageConfiguration(const std::string& modelName, const std::string& stageName);
|
||||
static std::shared_ptr<ModelTexture> loadTexture(const std::string &name, const std::string &texturePath, Loader &loader);
|
||||
static std::shared_ptr<ModelTexture> getTexture(const std::string& texturePath);
|
||||
private:
|
||||
static inline std::unordered_map<std::string, std::shared_ptr<TexturedModel>> models;
|
||||
static inline std::unordered_map<std::string, std::shared_ptr<ModelStages>> modelsWithStages;
|
||||
static inline std::unordered_map<std::string, std::shared_ptr<ModelTexture>> textures;
|
||||
|
||||
static nlohmann::json readJsonFile(const std::string &path);
|
||||
};
|
||||
|
||||
@ -58,12 +58,12 @@ void GameLayer::onAttach()
|
||||
AssetManager::loadAsset("assets/buildings/stone_mason/stone_mason.json", loader);
|
||||
AssetManager::loadAsset("assets/buildings/forest_hut/cabin.json", loader);
|
||||
|
||||
ModelTexture modelTexture = loader.loadTextureFromFile("assets/worldIcons/warning.png");
|
||||
auto modelTexture = AssetManager::loadTexture("warning", "assets/worldIcons/warning.png", loader);
|
||||
|
||||
TransformComponent transformComponent(glm::vec3(0,0,0), glm::vec3(0), 1.0f);
|
||||
testEntity = BuildingFactory::create(*entityManager, TemporaryBuildingDefinitionFactory::createForestHutDefinition(), transformComponent, 0, 0);
|
||||
auto worldSpritePtr = std::make_shared<WorldSpriteComponent>();
|
||||
worldSpritePtr->texture = std::make_shared<ModelTexture>(modelTexture);
|
||||
worldSpritePtr->texture = modelTexture;
|
||||
entityManager->addComponent(testEntity, worldSpritePtr);
|
||||
|
||||
auto anim = std::make_shared<AnimationComponent>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user