add blueprint & property implementation
This commit is contained in:
parent
ef27673846
commit
71964229e7
6 changed files with 772 additions and 43 deletions
|
|
@ -80,6 +80,8 @@ IkarusEntity * ikarus_entity_copy(IkarusEntity * entity, IkarusEntityCopyFlags f
|
|||
entity->id
|
||||
));
|
||||
|
||||
auto const id = entity->project->db->last_insert_rowid();
|
||||
|
||||
CPPBASE_TRY(entity->project->db->execute(
|
||||
"INSERT INTO `entity_values`(`entity`, `name`, `value`) "
|
||||
"SELECT ?1, `name`, `value` FROM `entity_values` WHERE "
|
||||
|
|
@ -101,7 +103,7 @@ IkarusEntity * ikarus_entity_copy(IkarusEntity * entity, IkarusEntityCopyFlags f
|
|||
entity->id
|
||||
))
|
||||
|
||||
return cppbase::ok(entity->project->db->last_insert_rowid());
|
||||
return cppbase::ok(id);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -189,8 +191,8 @@ bool ikarus_entity_is_linked_to_blueprint(
|
|||
|
||||
struct IkarusBlueprint **
|
||||
ikarus_entity_get_linked_blueprints(IkarusEntity * entity, size_t * size_out, IkarusErrorData * error_out) {
|
||||
IKARUS_ASCERTAIN(false, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
IKARUS_VCALL(auto count, false, ikarus_entity_get_linked_blueprints_count, entity);
|
||||
IKARUS_ASCERTAIN(nullptr, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
IKARUS_VCALL(auto count, nullptr, ikarus_entity_get_linked_blueprints_count, entity);
|
||||
|
||||
std::int64_t ids[count];
|
||||
|
||||
|
|
@ -495,7 +497,7 @@ bool ikarus_entity_has_property_value(
|
|||
|
||||
IkarusEntityPropertyValue *
|
||||
ikarus_entity_get_property_values(IkarusEntity * entity, size_t * size_out, IkarusErrorData * error_out) {
|
||||
IKARUS_ASCERTAIN(false, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
IKARUS_ASCERTAIN(nullptr, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto values_plain,
|
||||
|
|
@ -503,9 +505,12 @@ ikarus_entity_get_property_values(IkarusEntity * entity, size_t * size_out, Ikar
|
|||
"failed to get property values for entity: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
entity->project->db->query_many<int64_t, char const *>(
|
||||
"SELECT `e`.`property`, IFNULL(`e`.`value`, ikarus_default_value(`p`.`schema`)) FROM `entity_property_values` AS `e` "
|
||||
"INNER JOIN `properties` AS `p` ON `p`.`id` = `e`.`property` "
|
||||
" WHERE `e`.`entity` = ?",
|
||||
"SELECT `p`.`id`, IFNULL(`v`.`value`, ikarus_default_value(`p`.`schema`)) "
|
||||
"FROM `entities` AS `e` "
|
||||
"INNER JOIN `entity_blueprint_links` as `l` ON `l`.`entity` = `e`.`id` "
|
||||
"INNER JOIN `properties` AS `p` ON `p`.`blueprint` = `l`.`blueprint` "
|
||||
"LEFT JOIN `entity_property_values` AS `v` ON `e`.`entity` = `e`.`id` "
|
||||
"WHERE `e`.`entity` = ?",
|
||||
entity->id
|
||||
)
|
||||
);
|
||||
|
|
@ -527,9 +532,9 @@ ikarus_entity_get_property_values(IkarusEntity * entity, size_t * size_out, Ikar
|
|||
|
||||
char const *
|
||||
ikarus_entity_get_property_value(IkarusEntity * entity, struct IkarusProperty * property, IkarusErrorData * error_out) {
|
||||
IKARUS_ASCERTAIN(false, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
IKARUS_ASCERTAIN(nullptr, "entity doesn't exist", IkarusErrorInfo_Client_NonExistent, ikarus_entity_exists, entity);
|
||||
IKARUS_ASCERTAIN(
|
||||
false,
|
||||
nullptr,
|
||||
"property doesn't exist",
|
||||
IkarusErrorInfo_Client_NonExistent,
|
||||
ikarus_property_exists,
|
||||
|
|
@ -543,6 +548,15 @@ ikarus_entity_get_property_value(IkarusEntity * entity, struct IkarusProperty *
|
|||
IkarusErrorInfo_Client_NotLinked
|
||||
);
|
||||
|
||||
IKARUS_ASCERTAIN(
|
||||
nullptr,
|
||||
"entity doesn't have property value",
|
||||
IkarusErrorInfo_Client_NotLinked,
|
||||
ikarus_entity_has_property_value,
|
||||
entity,
|
||||
property
|
||||
);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
auto value,
|
||||
nullptr,
|
||||
|
|
@ -567,6 +581,8 @@ void ikarus_entity_set_property_value(
|
|||
IkarusEntitySetPropertyValueFlags flags,
|
||||
IkarusErrorData * error_out
|
||||
) {
|
||||
IKARUS_FAIL_IF_NULL(value, IKARUS_VOID_RETURN);
|
||||
|
||||
IKARUS_ASCERTAIN(
|
||||
IKARUS_VOID_RETURN,
|
||||
"entity doesn't exist",
|
||||
|
|
@ -581,7 +597,6 @@ void ikarus_entity_set_property_value(
|
|||
ikarus_property_exists,
|
||||
property
|
||||
);
|
||||
IKARUS_FAIL_IF_NULL(value, IKARUS_VOID_RETURN);
|
||||
|
||||
IKARUS_FAIL_IF(
|
||||
entity->project != property->project,
|
||||
|
|
@ -650,6 +665,7 @@ void ikarus_entity_clear_property_value(
|
|||
"property does not belong to entity's project",
|
||||
IkarusErrorInfo_Client_NotLinked
|
||||
);
|
||||
|
||||
IKARUS_ASCERTAIN(
|
||||
IKARUS_VOID_RETURN,
|
||||
"entity doesn't have property",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue