TailorMade 2.0
Tailor Made is a high-performance C++20 ECS library with on-the-fly entity creation and JSON-based definitions for entities, components, and their relationships.
 
Loading...
Searching...
No Matches
EntityManager Class Reference

#include <EntityManager.h>

Public Member Functions

 EntityManager ()
 Default constructor of the EntityManager.
 
 EntityManager (const std::string &directory)
 Constructor of the EntityManager, take the root directory with the entities as a parameter.
 
int getEntity (const std::string &name)
 Return the ID of an Entity based on its name.
 
std::vector< int > getEntities (const std::string &prefixOrTag, bool isPrefix=true)
 Return every entities with a name which start by the given prefix or all the entities of a tag.
 
std::vector< std::string > getNames ()
 Return a vector with the names of all the entities.
 
const std::string & getName (int entity)
 Return the name of an entity based on its ID.
 
int createEntity (const std::string &name, bool createFile=false)
 Create a new entity and return its ID.
 
void removeEntity (const std::string &name)
 Remove an entity from the EntityManager.
 
void toString (std::ostream &stream)
 Append a serialized version of the EntityManager to the given stream.
 
bool hasTag (int entity, const std::string &tag)
 Return true if the entity have the given tag, false otherwise.
 
void addTag (int entity, const std::string &tag)
 Add a tag to an entity.
 

Constructor & Destructor Documentation

◆ EntityManager() [1/2]

EntityManager::EntityManager ( )

Default constructor of the EntityManager.

◆ EntityManager() [2/2]

EntityManager::EntityManager ( const std::string & directory)

Constructor of the EntityManager, take the root directory with the entities as a parameter.

Parameters
directoryThe root directory with all the entities, files in subfolders are include.

Member Function Documentation

◆ addTag()

void EntityManager::addTag ( int entity,
const std::string & tag )

Add a tag to an entity.

Parameters
entityThe ID of the entity.
tagThe tag to add.

◆ createEntity()

int EntityManager::createEntity ( const std::string & name,
bool createFile = false )

Create a new entity and return its ID.

If createFile is true, the entity's file will be create in the root directory.

Parameters
nameEntity's name.
createFileIf true, an entity's file is created in the root directory.

◆ getEntities()

std::vector< int > EntityManager::getEntities ( const std::string & prefixOrTag,
bool isPrefix = true )

Return every entities with a name which start by the given prefix or all the entities of a tag.

You can generate multiple entities in the JSON file and manage them from their common prefix.

If isPrefix is false, prefixOrTag is considered a tag and all entities with the given tag will be returned.

Parameters
prefixOrTagPrefix or tag for the research.
isPrefixTells if the precedent parameter should be considered as a prefix or a tag.

◆ getEntity()

int EntityManager::getEntity ( const std::string & name)

Return the ID of an Entity based on its name.

Parameters
nameName of the entity.

◆ getName()

const std::string & EntityManager::getName ( int entity)

Return the name of an entity based on its ID.

Parameters
entityThe ID of the entity.

◆ getNames()

std::vector< std::string > EntityManager::getNames ( )

Return a vector with the names of all the entities.

◆ hasTag()

bool EntityManager::hasTag ( int entity,
const std::string & tag )

Return true if the entity have the given tag, false otherwise.

Parameters
entityThe ID of the entity.
tagThe tag to search for.

◆ removeEntity()

void EntityManager::removeEntity ( const std::string & name)

Remove an entity from the EntityManager.

Warning
The removed entity's ID will be reused.
Parameters
nameEntity's name.

◆ toString()

void EntityManager::toString ( std::ostream & stream)

Append a serialized version of the EntityManager to the given stream.

Consist of the name of the entities and their ID.

Parameters
streamThe stream on which the serialized version of the EntityManager is append to.

The documentation for this class was generated from the following file: