Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
entity_builder.inl
Go to the documentation of this file.
1
11const Self& set_json(
12 flecs::id_t e,
13 const char *json,
14 flecs::from_json_desc_t *desc = nullptr) const
15{
16 flecs::entity_t type = ecs_get_typeid(world_, e);
17 if (!type) {
18 ecs_err("id is not a type");
19 return to_base();
20 }
21
22 void *ptr = ecs_ensure_id(world_, id_, e);
23 ecs_assert(ptr != NULL, ECS_INTERNAL_ERROR, NULL);
24 ecs_ptr_from_json(world_, type, ptr, json, desc);
25 ecs_modified_id(world_, id_, e);
26
27 return to_base();
28}
29
35const Self& set_json(
36 flecs::entity_t r,
37 flecs::entity_t t,
38 const char *json,
39 flecs::from_json_desc_t *desc = nullptr) const
40{
41 return set_json(ecs_pair(r, t), json, desc);
42}
43
49template <typename T>
50const Self& set_json(
51 const char *json,
52 flecs::from_json_desc_t *desc = nullptr) const
53{
54 return set_json(_::type<T>::id(world_), json, desc);
55}
56
62template <typename R, typename T>
63const Self& set_json(
64 const char *json,
65 flecs::from_json_desc_t *desc = nullptr) const
66{
67 return set_json(
68 _::type<R>::id(world_),
69 _::type<T>::id(world_),
70 json, desc);
71}
72
78template <typename R>
79const Self& set_json(
80 flecs::entity_t t,
81 const char *json,
82 flecs::from_json_desc_t *desc = nullptr) const
83{
84 return set_json(
85 _::type<R>::id(world_), t,
86 json, desc);
87}
88
94template <typename T>
95const Self& set_json_second(
96 flecs::entity_t r,
97 const char *json,
98 flecs::from_json_desc_t *desc = nullptr) const
99{
100 return set_json(
101 r, _::type<T>::id(world_),
102 json, desc);
103}
FLECS_API const char * ecs_ptr_from_json(const ecs_world_t *world, ecs_entity_t type, void *ptr, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON string into value.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
const Self & set_json_second(flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
const Self & set_json(flecs::entity_t r, flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
const Self & set_json(flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
const Self & set_json(const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set component from JSON.
const Self & set_json(flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
Set pair from JSON.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:37
Type class.
Definition type.hpp:21