Handles entity meta (de)serialization.
More...
#include <EntityFactory.hpp>
|
| template<valid_component ToValidate, valid_component... Dependencies> |
| void | register_dependencies () |
| | Defines a dependency validation for components.
|
| |
| template<valid_component Component> |
| void | register_component (const std::string &name) |
| | Registers a component definition.
|
| |
| void | json_factory (const std::string &type, const entt::entity entity, entt::registry ®istry, const nlohmann::json &json) |
| | Construct component from json and assign to provided entity and registry.
|
| |
| entt::any | any_from_json (const std::string &type, const nlohmann::json &json) |
| | Construct an entt::any from a json object.
|
| |
| nlohmann::json | serialize_entity (const entt::entity entity, entt::registry ®istry) |
| | Serialise a single entity.
|
| |
| entt::entity | deserialize_entity (const nlohmann::json &json, entt::registry ®istry) |
| | Create an entity from a JSON object.
|
| |
| const std::string & | get_type (const entt::id_type id) |
| | Get a string representation of an entity type id.
|
| |
| entt::id_type | get_typeid (const std::string &name) |
| | Get an entity type id from a string.
|
| |
| Validations & | get_validations () |
| | Get a list of configurations.
|
| |
| const std::vector< entt::id_type > & | get_validation_list () const |
| | Get a list of validations to run.
|
| |
|
| using | Validations = ankerl::unordered_dense::map<entt::id_type, std::move_only_function<bool(const entt::entity, entt::registry&)>> |
| |
| using | ComponentJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<void(const entt::entity, entt::registry&, const nlohmann::json&)>> |
| |
| using | AnyJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<entt::any(const nlohmann::json&)>> |
| |
| using | SerializeFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<EntityFactory::SerializationData(void*)>> |
| |
Handles entity meta (de)serialization.
Definition at line 26 of file EntityFactory.hpp.
◆ Validations
◆ ComponentJSONFactory
◆ AnyJSONFactory
◆ SerializeFactory
◆ register_dependencies()
template<valid_component ToValidate, valid_component... Dependencies>
| void galaxy::meta::EntityFactory::register_dependencies |
( |
| ) |
|
|
inline |
Defines a dependency validation for components.
- Template Parameters
-
| ToValidate | The component to validate. |
| Dependencies | The components required by ToValidate. |
Definition at line 188 of file EntityFactory.hpp.
◆ register_component()
template<valid_component Component>
| void galaxy::meta::EntityFactory::register_component |
( |
const std::string & | name | ) |
|
|
inline |
Registers a component definition.
- Template Parameters
-
| Component | A valid component type is required. Must be move assignable/constructible and a class with a json constructor. |
- Parameters
-
| name | Name of component class in string format i.e. "Transform" or "Tag". |
Definition at line 215 of file EntityFactory.hpp.
◆ json_factory()
| void galaxy::meta::EntityFactory::json_factory |
( |
const std::string & | type, |
|
|
const entt::entity | entity, |
|
|
entt::registry & | registry, |
|
|
const nlohmann::json & | json ) |
Construct component from json and assign to provided entity and registry.
- Parameters
-
| type | Type of component as a string. |
| entity | Entity to assign component to. |
| registry | Registry that the entity belong to and where to create the component. |
| json | Component data as a json object. |
Definition at line 23 of file EntityFactory.cpp.
◆ any_from_json()
| entt::any galaxy::meta::EntityFactory::any_from_json |
( |
const std::string & | type, |
|
|
const nlohmann::json & | json ) |
|
nodiscard |
Construct an entt::any from a json object.
- Parameters
-
| type | Component type as a string. |
| json | Component data as a json object. |
- Returns
- Newly constructed entt::any.
Definition at line 35 of file EntityFactory.cpp.
◆ serialize_entity()
| nlohmann::json galaxy::meta::EntityFactory::serialize_entity |
( |
const entt::entity | entity, |
|
|
entt::registry & | registry ) |
|
nodiscard |
Serialise a single entity.
- Parameters
-
| entity | Entity to serialize. |
| registry | Registry entity belongs to. |
- Returns
- JSON entity data.
Definition at line 40 of file EntityFactory.cpp.
◆ deserialize_entity()
| entt::entity galaxy::meta::EntityFactory::deserialize_entity |
( |
const nlohmann::json & | json, |
|
|
entt::registry & | registry ) |
Create an entity from a JSON object.
If your using this make sure you have called register_component().
- Parameters
-
| json | Preloaded JSON object. |
| registry | Registry entity belongs to. |
- Returns
- Created entity, or entt::null if failed.
Definition at line 60 of file EntityFactory.cpp.
◆ get_type()
| const std::string & galaxy::meta::EntityFactory::get_type |
( |
const entt::id_type | id | ) |
|
|
nodiscard |
Get a string representation of an entity type id.
- Parameters
-
| id | Entt meta type id of a component. |
- Returns
- String name of component.
Definition at line 77 of file EntityFactory.cpp.
◆ get_typeid()
| entt::id_type galaxy::meta::EntityFactory::get_typeid |
( |
const std::string & | name | ) |
|
|
nodiscard |
Get an entity type id from a string.
- Parameters
-
| name | String name of component. |
- Returns
- Entt meta type id of a component.
Definition at line 82 of file EntityFactory.cpp.
◆ get_validations()
Get a list of configurations.
- Returns
- Reference to validations map.
Definition at line 87 of file EntityFactory.cpp.
◆ get_validation_list()
| const std::vector< entt::id_type > & galaxy::meta::EntityFactory::get_validation_list |
( |
| ) |
const |
|
nodiscard |
Get a list of validations to run.
- Returns
- Const reference to list of validations to run.
Definition at line 92 of file EntityFactory.cpp.
◆ m_id_to_name
| ankerl::unordered_dense::map<entt::id_type, std::string> galaxy::meta::EntityFactory::m_id_to_name |
|
private |
◆ m_name_to_id
| ankerl::unordered_dense::map<std::string, entt::id_type> galaxy::meta::EntityFactory::m_name_to_id |
|
private |
◆ m_json_factory
◆ m_json_any_factory
◆ m_serialize_factory
◆ m_validations
◆ m_validations_to_run
| std::vector<entt::id_type> galaxy::meta::EntityFactory::m_validations_to_run |
|
private |
The documentation for this class was generated from the following files: