ECS/Project/Project/ECS/EntityManager/EntityManager.cpp
//	Add a component of the specified type to the Entity
Add a component of the specified type to the Entity
Add a component of the specified type to the Entity
std::shared_ptr<Component> EntityManager::addComponentToEntity(const long int & givenEntity, const ComponentType & componentType)
{
	std::shared_ptr<Entity> entity = getEntity(givenEntity);
	if (entity != NULL)
	{
		if (entity->getDestroyed())
		{
			return NULL;
		}
		else
		{
			if (entity->hasComponents((long int)componentType))
			{
				return entity->getComponentByType(componentType);
			}
			else
			{
				if (checkComponentRequirements(givenEntity, componentType))
				{
					std::shared_ptr<Component> newComponent = createComponent(componentType);
					if (newComponent != NULL)
					{
						entity->addComponent(newComponent);
						eventDispatcher->dispatchToEventQueue(EventType::COMPONENT_ADDED, ModuleType::ENTITY_MANAGER, componentType, givenEntity);
						addEntityToComponentTypeList(givenEntity, componentType);
						return newComponent;
					}
					else
					{
						return NULL;
					}
				}
				else
				{
					return NULL;
				}
			}
		}
	}
	else
	{
		return NULL;
	}
}
std :: shared_ptr < Component > EntityManager :: addComponentToEntity ( const long int & givenEntity , const ComponentType & componentType ) { std :: shared_ptr < Entity > entity = getEntity ( givenEntity ) ; if ( entity != NULL ) { if ( entity -> getDestroyed ( ) ) { return NULL ; } else { if ( entity -> hasComponents ( ( long int ) componentType ) ) { return entity -> getComponentByType ( componentType ) ; } else { if ( checkComponentRequirements ( givenEntity , componentType ) ) { std :: shared_ptr < Component > newComponent = createComponent ( componentType ) ; if ( newComponent != NULL ) { entity -> addComponent ( newComponent ) ; eventDispatcher -> dispatchToEventQueue ( EventType :: COMPONENT_ADDED , ModuleType :: ENTITY_MANAGER , componentType , givenEntity ) ; addEntityToComponentTypeList ( givenEntity , componentType ) ; return newComponent ; } else { return NULL ; } } else { return NULL ; } } } } else { return NULL ; } }
Add a component of the specified type to the Entity
Add a component of the specified type to the Entity
//	Find the Entities, that have the Component of the specified type. //	Check if the entity exists. //	Check if the entity has already been destroyed. //	Check if it already has the component. //	Check if it has the appropriate components. //	Add the component. //	Add the appropriate component. //	Dispatch the Event to the EventQueue. //	Add the entity to the list of entities having this component. //	Return the new component. //	Return NULL if a new component is created. //	Return NULL if the component requirements are not met. //	Return NULL if the Entity is NULL.