R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::wrapper::EntityBuilder Class Reference

Builder pattern for creating entities with multiple components. More...

#include <EntityBuilder.hpp>

Collaboration diagram for ecs::wrapper::EntityBuilder:
Collaboration graph

Public Member Functions

 EntityBuilder (ECSWorld *world)
 Construct an EntityBuilder.
 
template<typename T >
EntityBuilderwith (const T &component)
 Add a component to the entity being built.
 
template<typename T >
EntityBuilderwith (std::function< T()> factory)
 Add a component using a factory function.
 
EntityBuilderconfigure (std::function< void(Entity &)> configurator)
 Apply a configuration function to the entity.
 
Entity build ()
 Finalize and return the built entity.
 
 operator Entity ()
 Implicit conversion to Entity.
 

Private Attributes

ECSWorld_world
 
Entity _entity
 

Detailed Description

Builder pattern for creating entities with multiple components.

Provides a fluent interface for constructing complex entities. Useful for creating game objects with multiple components in a clean way.

Definition at line 23 of file EntityBuilder.hpp.

Constructor & Destructor Documentation

◆ EntityBuilder()

ecs::wrapper::EntityBuilder::EntityBuilder ( ECSWorld world)
explicit

Construct an EntityBuilder.

Parameters
worldPointer to the ECS world

Definition at line 12 of file EntityBuilder.cpp.

Member Function Documentation

◆ build()

Entity ecs::wrapper::EntityBuilder::build ( )

Finalize and return the built entity.

Returns
Entity The constructed entity

Definition at line 19 of file EntityBuilder.cpp.

References _entity.

◆ configure()

EntityBuilder & ecs::wrapper::EntityBuilder::configure ( std::function< void(Entity &)>  configurator)

Apply a configuration function to the entity.

Parameters
configuratorFunction that configures the entity
Returns
EntityBuilder& Reference for chaining
builder.configure([](Entity e) {
e.get<Transform>().position = {100, 200};
});
Component representing position, rotation and scale in 2D space.
Definition Transform.hpp:20
High-level entity wrapper providing fluent interface.
Definition ECSWorld.hpp:33
T & get()
Get a component from this entity.

Definition at line 14 of file EntityBuilder.cpp.

References _entity.

◆ operator Entity()

ecs::wrapper::EntityBuilder::operator Entity ( )

Implicit conversion to Entity.

Definition at line 23 of file EntityBuilder.cpp.

◆ with() [1/2]

template<typename T >
EntityBuilder & ecs::wrapper::EntityBuilder::with ( const T &  component)

Add a component to the entity being built.

Template Parameters
TComponent type
Parameters
componentThe component data
Returns
EntityBuilder& Reference for chaining

◆ with() [2/2]

template<typename T >
EntityBuilder & ecs::wrapper::EntityBuilder::with ( std::function< T()>  factory)

Add a component using a factory function.

Template Parameters
TComponent type
Parameters
factoryFunction that creates the component
Returns
EntityBuilder& Reference for chaining

Member Data Documentation

◆ _entity

Entity ecs::wrapper::EntityBuilder::_entity
private

Definition at line 28 of file EntityBuilder.hpp.

Referenced by build(), and configure().

◆ _world

ECSWorld* ecs::wrapper::EntityBuilder::_world
private

Definition at line 27 of file EntityBuilder.hpp.


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