Dicewars-Siedler/src/game/hexWorld/building/BuildingFactory.cpp
2026-02-14 09:44:32 +01:00

47 lines
1.6 KiB
C++

//
// Created by sebastian on 13.02.26.
//
#include "BuildingFactory.h"
#include "../../../engine/core/ECS/ModelComponent.h"
#include "../../../engine/core/ECS/ModelStateComponent.h"
#include "../../../engine/core/ECS/TransformComponent.h"
#include "../../../engine/renderer/loader/AssetManager.h"
#include "../ecs/components/ProducingComponent.h"
EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &def,
const TransformComponent &tileTransform, EntityID tileEntity, PlayerID owner) {
EntityID e = em.createEntity();
em.addComponent(e, std::make_shared<ModelComponent>(AssetManager::getModelStages(def.model), def.model));
if (def.type == BuildingType::FOREST_HUT) {
em.addComponent(e, std::make_shared<TransformComponent>(
tileTransform.position, glm::vec3(0), 1.f
));
} else {
em.addComponent(e, std::make_shared<TransformComponent>(
tileTransform.position, glm::vec3(0), 2.f
));
}
em.addComponent(e, std::make_shared<BuildingComponent>(def.type, tileEntity));
em.addComponent(e, std::make_shared<OwnerComponent>(owner));
auto modelStateComponent = std::make_shared<ModelStateComponent>();
modelStateComponent->params["fillRatio"] = 0.f;
auto producingComponent = std::make_shared<ProducingComponent>( ProducingComponent(def.produces, def.baseAmountPerTurn, false));
producingComponent->setMaxStorage(def.maxStorage);
em.addComponent(e, modelStateComponent);
em.addComponent(e, producingComponent);
return e;
}