7#include <libecs-cpp/json.hpp>
43 std::shared_ptr<ecs::Component>
Component(std::unique_ptr<ecs::Component> component);
49 template <
class T = ecs::Component>
52 const std::shared_ptr<ecs::Component> *found = this->componentFind(type);
57 if constexpr(std::is_same_v<T, ecs::Component>)
63 return std::dynamic_pointer_cast<T>(*found);
77 const std::shared_ptr<ecs::Component> *componentFind(
const std::string &type)
const;
A container: the entities, components, systems and resources that are updated together.
Definition Container.hpp:70
One thing in a container, to which components are attached.
Definition Entity.hpp:22
Entity(ecs::Container *container)
Creates an entity with a generated handle.
std::shared_ptr< ecs::Component > Component(std::unique_ptr< ecs::Component > component)
Attaches a component to this entity and returns the stored component.
Entity(ecs::Container *container, const std::string &handle)
Creates an entity with the given handle.
std::shared_ptr< T > ComponentGet(const std::string &type) const
Looks up this entity's component with the given type name, as class T.
Definition Entity.hpp:50
void ComponentDestroy(const std::string &type)
Removes this entity's component with the given type name.
nlohmann::json Export() const
Describes the entity and its components as JSON.
ecs::Container * Container
The container the entity belongs to.
Definition Entity.hpp:33
void Destroy()
Removes this entity and its components from the container.
const std::string Handle
The entity's handle, given at construction and never changed.
Definition Entity.hpp:35
bool ComponentHas(const std::string &type) const
Says whether this entity has a component stored under the given type name.