mod children list of subprefabs

This commit is contained in:
BlackMATov
2020-04-24 05:28:09 +07:00
parent b82b743f76
commit 8c28cab788
3 changed files with 99 additions and 17 deletions

View File

@@ -117,6 +117,7 @@ namespace
const bool success = the<factory>().validate_json(
component_root->name.GetString(),
component_root->value);
if ( !success ) {
throw prefab_asset_loading_exception();
}
@@ -125,10 +126,12 @@ namespace
factory_loader<>::collect_context ctx(
str(parent_address),
component_root->value);
const bool success = the<factory>().collect_dependencies(
component_root->name.GetString(),
dependencies,
ctx);
if ( !success ) {
throw prefab_asset_loading_exception();
}
@@ -170,11 +173,7 @@ namespace
const asset_group& dependencies)
{
if ( root.HasMember("uuid") ) {
str uuid = content.uuid();
if ( !json_utils::try_parse_value(root["uuid"], uuid) ) {
the<debug>().error("PREFAB: Incorrect formatting of 'uuid' property");
throw prefab_asset_loading_exception();
}
str uuid = root["uuid"].GetString();
content.set_uuid(std::move(uuid));
}
@@ -196,20 +195,18 @@ namespace
if ( root.HasMember("children") ) {
const rapidjson::Value& children_root = root["children"];
vector<prefab> children;
children.reserve(children_root.Size());
for ( rapidjson::SizeType i = 0; i < children_root.Size(); ++i ) {
const rapidjson::Value& child_root = children_root[i];
prefab child;
parse_prefab_inplace(
child,
parent_address,
children_root[i],
child_root,
dependencies);
children.push_back(std::move(child));
}
content.set_children(std::move(children));
content.children().push_back(std::move(child));
}
}
if ( root.HasMember("mod_children") ) {

View File

@@ -13,19 +13,52 @@
"offset" : [8,4]
}
},
"children" : [{
"uuid" : "C07CDC21-8D1A-45E5-9321-AC7B6FADA847",
"components" : {
"named" : {
"name" : "child(3)"
}
}
}],
"mod_children" : [{
"uuid" : "4A93547E-4635-4C2F-9C59-3546E11B1722",
"components" : {
"widget" : {
"size" : [10,10]
}
}
},
"children" : [{
"uuid" : "EA1F7728-8061-495E-9E8A-280C5E2979B3",
"prefab" : "prefab_root.json",
"components" : {
"named" : {
"name" : "subchild(1)"
}
}
}]
}, {
"uuid" : "58063213-9FC1-457C-B773-B826BE1BE6D7",
"components" : {
"widget" : {
"size" : [20,20]
}
},
"children" : [{
"uuid" : "4DDDD08D-F7B9-4588-8597-3E38051AC433",
"prefab" : "prefab_root.json",
"components" : {
"named" : {
"name" : "subchild(2)"
}
}
}]
}, {
"uuid" : "C07CDC21-8D1A-45E5-9321-AC7B6FADA847",
"components" : {
"widget" : {
"size" : [30,30]
}
}
}]
}

View File

@@ -74,6 +74,22 @@ TEST_CASE("prefab"){
REQUIRE(child2_go.component<named>());
REQUIRE(child2_go.component<named>()->name() == "child(2)");
node_iptr child1_node = child1_go.component<actor>()
? child1_go.component<actor>()->node()
: node_iptr();
node_iptr child2_node = child2_go.component<actor>()
? child2_go.component<actor>()->node()
: node_iptr();
REQUIRE(child1_node);
REQUIRE(child1_node->owner() == child1_go);
REQUIRE(child1_node->child_count() == 0u);
REQUIRE(child2_node);
REQUIRE(child2_node->owner() == child2_go);
REQUIRE(child2_node->child_count() == 0u);
}
}
@@ -84,9 +100,10 @@ TEST_CASE("prefab"){
const prefab& prefab_child = prefab_child_res->content();
REQUIRE(prefab_child.uuid().empty());
REQUIRE(prefab_child.children().size() == 2u);
REQUIRE(prefab_child.children().size() == 3u);
REQUIRE(prefab_child.children()[0].uuid() == "4A93547E-4635-4C2F-9C59-3546E11B1722");
REQUIRE(prefab_child.children()[1].uuid() == "58063213-9FC1-457C-B773-B826BE1BE6D7");
REQUIRE(prefab_child.children()[2].uuid() == "C07CDC21-8D1A-45E5-9321-AC7B6FADA847");
auto go = the<world>().instantiate(prefab_child);
@@ -114,29 +131,64 @@ TEST_CASE("prefab"){
REQUIRE(go_node);
REQUIRE(go_node->owner() == go);
REQUIRE(go_node->child_count() == 2u);
REQUIRE(go_node->child_count() == 3u);
node_iptr child1 = go_node->child_at(0u);
node_iptr child2 = go_node->child_at(1u);
node_iptr child3 = go_node->child_at(2u);
REQUIRE(child1);
REQUIRE(child2);
REQUIRE(child3);
gobject child1_go = child1->owner();
gobject child2_go = child2->owner();
gobject child3_go = child3->owner();
REQUIRE(child1_go);
REQUIRE(child2_go);
REQUIRE(child3_go);
REQUIRE(child1_go.component<named>());
REQUIRE(child1_go.component<named>()->name() == "child(1)");
REQUIRE(child1_go.component<widget>());
REQUIRE(child1_go.component<named>()->name() == "child(1)");
REQUIRE(child1_go.component<widget>()->size() == v2f(10.f, 10.f));
REQUIRE(child2_go.component<named>());
REQUIRE(child2_go.component<widget>());
REQUIRE(child2_go.component<named>()->name() == "child(2)");
REQUIRE(child2_go.component<widget>()->size() == v2f(20.f, 20.f));
REQUIRE(child3_go.component<named>());
REQUIRE(child3_go.component<widget>());
REQUIRE(child3_go.component<named>()->name() == "child(3)");
REQUIRE(child3_go.component<widget>()->size() == v2f(30.f, 30.f));
node_iptr child1_node = child1_go.component<actor>()
? child1_go.component<actor>()->node()
: node_iptr();
node_iptr child2_node = child2_go.component<actor>()
? child2_go.component<actor>()->node()
: node_iptr();
node_iptr child3_node = child3_go.component<actor>()
? child3_go.component<actor>()->node()
: node_iptr();
REQUIRE(child1_node);
REQUIRE(child1_node->owner() == child1_go);
REQUIRE(child1_node->child_count() == 1u);
REQUIRE(child1_node->first_child()->child_count() == 2u);
REQUIRE(child2_node);
REQUIRE(child2_node->owner() == child2_go);
REQUIRE(child2_node->child_count() == 1u);
REQUIRE(child2_node->first_child()->child_count() == 2u);
REQUIRE(child3_node);
REQUIRE(child3_node->owner() == child3_go);
REQUIRE(child3_node->child_count() == 0u);
}
}
}