Builds entities from JSON blueprints and registered component builders.
More...
#include <factoryDataDriven/factoryDataDriven.hpp>
|
|
using | ArchetypeID = rtk::ArchetypeID |
| | 16-bit identifier of an entity blueprint.
|
| |
|
using | json = nlohmann::json |
| | JSON document type.
|
| |
| using | ComponentBuilder |
| | Function that adds one component to an entity from its JSON data.
|
| |
|
| void | registerBuilder (const std::string &name, ComponentBuilder builder) |
| | Associates a blueprint component key with a builder.
|
| |
| ArchetypeID | registerBlueprint (const std::string &blueprintName, const json &blueprintJson) |
| | Stores a blueprint under a name.
|
| |
| ArchetypeID | loadBlueprintFromPath (const std::string &blueprintName, const std::string &filepath) |
| | Loads a blueprint from a JSON file and stores it.
|
| |
| ArchetypeID | getArchetypeID (const std::string &blueprintName) const |
| | Returns the archetype id of a blueprint name.
|
| |
| const std::string & | getBlueprintName (ArchetypeID archetypeId) const |
| | Returns the blueprint name of an archetype id.
|
| |
| bool | hasArchetype (ArchetypeID archetypeId) const |
| | Tells whether a blueprint with this archetype id is loaded.
|
| |
| bool | hasBlueprint (const std::string &blueprintName) const |
| | Tells whether a blueprint with this name is loaded.
|
| |
| void | buildComponents (rtk::ecs::Registry ®, std::size_t entity, const json &componentsJson) |
| | Adds every component listed in a JSON object, unknown keys are ignored.
|
| |
| std::size_t | createEntity (rtk::ecs::Registry ®, const json &entityJson) |
| | Spawns an entity from a blueprint document.
|
| |
| std::size_t | createFromBlueprint (rtk::ecs::Registry ®, const std::string &blueprintName) |
| | Spawns an entity from a loaded blueprint.
|
| |
| std::size_t | createFromBlueprint (rtk::ecs::Registry ®, ArchetypeID archetypeId) |
| | Spawns an entity from a loaded blueprint.
|
| |
| std::size_t | createNetwork (rtk::ecs::Registry ®, ArchetypeID archetypeId, std::uint32_t networkId) |
| | Spawns a replicated entity and attaches its NetworkEntity.
|
| |
| std::size_t | createNetwork (rtk::ecs::Registry ®, const std::string &blueprintName, std::uint32_t networkId) |
| | Spawns a replicated entity and attaches its NetworkEntity.
|
| |
Builds entities from JSON blueprints and registered component builders.
◆ ComponentBuilder
Initial value:
std::function<void(rtk::ecs::Registry &, std::size_t,
const json &)>
nlohmann::json json
JSON document type.
Definition factoryDataDriven.hpp:59
Function that adds one component to an entity from its JSON data.
◆ registerBuilder()
| void rtk::factory::EntityFactory::registerBuilder |
( |
const std::string & | name, |
|
|
ComponentBuilder | builder ) |
|
inline |
Associates a blueprint component key with a builder.
- Parameters
-
| name | Key used in the components object of a blueprint. |
| builder | Function that adds the component. |
◆ registerBlueprint()
| ArchetypeID rtk::factory::EntityFactory::registerBlueprint |
( |
const std::string & | blueprintName, |
|
|
const json & | blueprintJson ) |
|
inline |
Stores a blueprint under a name.
- Parameters
-
| blueprintName | Blueprint name, hashed to get its archetype id. |
| blueprintJson | Blueprint document. |
- Returns
- The archetype id of the blueprint.
◆ loadBlueprintFromPath()
| ArchetypeID rtk::factory::EntityFactory::loadBlueprintFromPath |
( |
const std::string & | blueprintName, |
|
|
const std::string & | filepath ) |
|
inline |
Loads a blueprint from a JSON file and stores it.
- Parameters
-
| blueprintName | Blueprint name, hashed to get its archetype id. |
| filepath | Path of the JSON file. |
- Returns
- The archetype id of the blueprint.
- Exceptions
-
| std::runtime_error | If the file cannot be opened. |
◆ getArchetypeID()
| ArchetypeID rtk::factory::EntityFactory::getArchetypeID |
( |
const std::string & | blueprintName | ) |
const |
|
inlinenodiscard |
Returns the archetype id of a blueprint name.
- Parameters
-
| blueprintName | Blueprint name. |
- Returns
- The archetype id, whether or not the blueprint is loaded.
◆ getBlueprintName()
| const std::string & rtk::factory::EntityFactory::getBlueprintName |
( |
ArchetypeID | archetypeId | ) |
const |
|
inlinenodiscard |
Returns the blueprint name of an archetype id.
- Parameters
-
- Returns
- The blueprint name.
- Exceptions
-
| std::runtime_error | If no loaded blueprint has this id. |
◆ hasArchetype()
| bool rtk::factory::EntityFactory::hasArchetype |
( |
ArchetypeID | archetypeId | ) |
const |
|
inlinenodiscard |
Tells whether a blueprint with this archetype id is loaded.
- Parameters
-
- Returns
- True if the blueprint is loaded.
◆ hasBlueprint()
| bool rtk::factory::EntityFactory::hasBlueprint |
( |
const std::string & | blueprintName | ) |
const |
|
inlinenodiscard |
Tells whether a blueprint with this name is loaded.
- Parameters
-
| blueprintName | Blueprint name. |
- Returns
- True if the blueprint is loaded.
◆ buildComponents()
| void rtk::factory::EntityFactory::buildComponents |
( |
rtk::ecs::Registry & | reg, |
|
|
std::size_t | entity, |
|
|
const json & | componentsJson ) |
|
inline |
Adds every component listed in a JSON object, unknown keys are ignored.
- Parameters
-
| reg | Registry owning the entity. |
| entity | Target entity. |
| componentsJson | Object mapping builder keys to component data. |
◆ createEntity()
| std::size_t rtk::factory::EntityFactory::createEntity |
( |
rtk::ecs::Registry & | reg, |
|
|
const json & | entityJson ) |
|
inline |
Spawns an entity from a blueprint document.
- Parameters
-
| reg | Registry receiving the entity. |
| entityJson | Document with an optional components object. |
- Returns
- The new entity.
◆ createFromBlueprint() [1/2]
| std::size_t rtk::factory::EntityFactory::createFromBlueprint |
( |
rtk::ecs::Registry & | reg, |
|
|
const std::string & | blueprintName ) |
|
inline |
Spawns an entity from a loaded blueprint.
- Parameters
-
| reg | Registry receiving the entity. |
| blueprintName | Blueprint name. |
- Returns
- The new entity.
- Exceptions
-
| std::runtime_error | If the blueprint is not loaded. |
◆ createFromBlueprint() [2/2]
| std::size_t rtk::factory::EntityFactory::createFromBlueprint |
( |
rtk::ecs::Registry & | reg, |
|
|
ArchetypeID | archetypeId ) |
|
inline |
Spawns an entity from a loaded blueprint.
- Parameters
-
| reg | Registry receiving the entity. |
| archetypeId | Archetype id of the blueprint. |
- Returns
- The new entity.
- Exceptions
-
| std::runtime_error | If the blueprint is not loaded. |
◆ createNetwork() [1/2]
| std::size_t rtk::factory::EntityFactory::createNetwork |
( |
rtk::ecs::Registry & | reg, |
|
|
ArchetypeID | archetypeId, |
|
|
std::uint32_t | networkId ) |
|
inline |
Spawns a replicated entity and attaches its NetworkEntity.
- Parameters
-
| reg | Registry receiving the entity. |
| archetypeId | Archetype id of the blueprint. |
| networkId | Network id of the entity. |
- Returns
- The new entity.
- Exceptions
-
| std::runtime_error | If the blueprint is not loaded. |
◆ createNetwork() [2/2]
| std::size_t rtk::factory::EntityFactory::createNetwork |
( |
rtk::ecs::Registry & | reg, |
|
|
const std::string & | blueprintName, |
|
|
std::uint32_t | networkId ) |
|
inline |
Spawns a replicated entity and attaches its NetworkEntity.
- Parameters
-
| reg | Registry receiving the entity. |
| blueprintName | Blueprint name. |
| networkId | Network id of the entity. |
- Returns
- The new entity.
- Exceptions
-
| std::runtime_error | If the blueprint is not loaded. |