-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entity_builder::set_json, remove redundant template parameter fro…
…m world::from_json
- Loading branch information
1 parent
d8dadaa
commit fbb237f
Showing
8 changed files
with
374 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ | |
const char* from_json(const char *json) { | ||
return ecs_entity_from_json(m_world, m_id, json, nullptr); | ||
} | ||
|
103 changes: 103 additions & 0 deletions
103
include/flecs/addons/cpp/mixins/json/entity_builder.inl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @file addons/cpp/mixins/json/entity_builder.inl | ||
* @brief JSON entity mixin. | ||
*/ | ||
|
||
/** Set component from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
Self& set_json( | ||
flecs::id_t e, | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
flecs::entity_t type = ecs_get_typeid(m_world, e); | ||
if (!type) { | ||
ecs_err("id is not a type"); | ||
return to_base(); | ||
} | ||
|
||
void *ptr = ecs_get_mut_id(m_world, m_id, e); | ||
ecs_assert(ptr != NULL, ECS_INTERNAL_ERROR, NULL); | ||
ecs_ptr_from_json(m_world, type, ptr, json, desc); | ||
ecs_modified_id(m_world, m_id, e); | ||
|
||
return to_base(); | ||
} | ||
|
||
/** Set pair from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
Self& set_json( | ||
flecs::entity_t r, | ||
flecs::entity_t t, | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
return set_json(ecs_pair(r, t), json, desc); | ||
} | ||
|
||
/** Set component from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
template <typename T> | ||
Self& set_json( | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
return set_json(_::cpp_type<T>::id(m_world), json, desc); | ||
} | ||
|
||
/** Set pair from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
template <typename R, typename T> | ||
Self& set_json( | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
return set_json( | ||
_::cpp_type<R>::id(m_world), | ||
_::cpp_type<T>::id(m_world), | ||
json, desc); | ||
} | ||
|
||
/** Set pair from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
template <typename R> | ||
Self& set_json( | ||
flecs::entity_t t, | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
return set_json( | ||
_::cpp_type<R>::id(m_world), t, | ||
json, desc); | ||
} | ||
|
||
/** Set pair from JSON. | ||
* | ||
* \memberof flecs::entity_builder | ||
* \ingroup cpp_addons_json | ||
*/ | ||
template <typename T> | ||
Self& set_json_second( | ||
flecs::entity_t r, | ||
const char *json, | ||
flecs::from_json_desc_t *desc = nullptr) | ||
{ | ||
return set_json( | ||
r, _::cpp_type<T>::id(m_world), | ||
json, desc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.