mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
rename prefab "parent" property to "prefab"
This commit is contained in:
@@ -25,7 +25,7 @@ namespace
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"uuid" : { "$ref": "#/common_definitions/uuid" },
|
||||
"parent" : { "$ref": "#/common_definitions/address" },
|
||||
"prefab" : { "$ref": "#/common_definitions/address" },
|
||||
"children" : { "$ref": "#/definitions/children" },
|
||||
"mod_children" : { "$ref": "#/definitions/mod_children" },
|
||||
"components" : { "type" : "object" }
|
||||
@@ -41,7 +41,7 @@ namespace
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"uuid" : { "$ref": "#/common_definitions/uuid" },
|
||||
"parent" : { "$ref": "#/common_definitions/address" },
|
||||
"prefab" : { "$ref": "#/common_definitions/address" },
|
||||
"children" : { "$ref": "#/definitions/children" },
|
||||
"mod_children" : { "$ref": "#/definitions/mod_children" },
|
||||
"components" : { "type" : "object" }
|
||||
@@ -88,9 +88,9 @@ namespace
|
||||
const rapidjson::Value& root,
|
||||
asset_dependencies& dependencies)
|
||||
{
|
||||
if ( root.HasMember("parent") ) {
|
||||
if ( root.HasMember("prefab") ) {
|
||||
dependencies.add_dependency<prefab_asset>(
|
||||
path::combine(parent_address, root["parent"].GetString()));
|
||||
path::combine(parent_address, root["prefab"].GetString()));
|
||||
}
|
||||
|
||||
if ( root.HasMember("children") ) {
|
||||
@@ -147,14 +147,14 @@ namespace
|
||||
return dependencies.load_async(library);
|
||||
}
|
||||
|
||||
prefab* find_prefab_child(prefab& parent, str_view child_uuid) noexcept {
|
||||
for ( prefab& child : parent.children() ) {
|
||||
prefab* find_prefab_child(prefab& root, str_view child_uuid) noexcept {
|
||||
for ( prefab& child : root.children() ) {
|
||||
if ( child.uuid() == child_uuid ) {
|
||||
return &child;
|
||||
}
|
||||
}
|
||||
|
||||
for ( prefab& child : parent.children() ) {
|
||||
for ( prefab& child : root.children() ) {
|
||||
if ( prefab* sub_child = find_prefab_child(child, child_uuid) ) {
|
||||
return sub_child;
|
||||
}
|
||||
@@ -178,15 +178,15 @@ namespace
|
||||
content.set_uuid(std::move(uuid));
|
||||
}
|
||||
|
||||
if ( root.HasMember("parent") ) {
|
||||
if ( root.HasMember("prefab") ) {
|
||||
auto proto_res = dependencies.find_asset<prefab_asset>(
|
||||
path::combine(parent_address, root["parent"].GetString()));
|
||||
path::combine(parent_address, root["prefab"].GetString()));
|
||||
if ( !proto_res ) {
|
||||
the<debug>().error("PREFAB: Dependency 'parent' is not found:\n"
|
||||
the<debug>().error("PREFAB: Dependency 'prefab' is not found:\n"
|
||||
"--> Parent address: %0\n"
|
||||
"--> Dependency address: %1",
|
||||
parent_address,
|
||||
root["parent"].GetString());
|
||||
root["prefab"].GetString());
|
||||
throw prefab_asset_loading_exception();
|
||||
}
|
||||
content.set_children(proto_res->content().children());
|
||||
@@ -217,14 +217,22 @@ namespace
|
||||
|
||||
for ( rapidjson::SizeType i = 0; i < mod_children_root.Size(); ++i ) {
|
||||
const rapidjson::Value& mod_child_root = mod_children_root[i];
|
||||
E2D_ASSERT(mod_child_root.HasMember("uuid") && mod_child_root["uuid"].IsString());
|
||||
prefab* child_prefab = find_prefab_child(content, mod_child_root["uuid"].GetString());
|
||||
|
||||
E2D_ASSERT(
|
||||
mod_child_root.HasMember("uuid") &&
|
||||
mod_child_root["uuid"].IsString());
|
||||
|
||||
prefab* const child_prefab = find_prefab_child(
|
||||
content,
|
||||
mod_child_root["uuid"].GetString());
|
||||
|
||||
if ( !child_prefab ) {
|
||||
the<debug>().error("PREFAB: Modifiable child is not found:\n"
|
||||
"--> Child UUID: %0",
|
||||
mod_child_root["uuid"].GetString());
|
||||
throw prefab_asset_loading_exception();
|
||||
}
|
||||
|
||||
parse_prefab_inplace(
|
||||
*child_prefab,
|
||||
parent_address,
|
||||
@@ -243,10 +251,12 @@ namespace
|
||||
str(parent_address),
|
||||
component_root->value,
|
||||
dependencies);
|
||||
|
||||
const bool success = the<factory>().fill_prototype(
|
||||
component_root->name.GetString(),
|
||||
content.prototype(),
|
||||
ctx);
|
||||
|
||||
if ( !success ) {
|
||||
throw prefab_asset_loading_exception();
|
||||
}
|
||||
@@ -260,7 +270,10 @@ namespace
|
||||
const asset_group& dependencies)
|
||||
{
|
||||
prefab content;
|
||||
parse_prefab_inplace(content, parent_address, root, dependencies);
|
||||
parse_prefab_inplace(
|
||||
content,
|
||||
parent_address,
|
||||
root, dependencies);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"parent" : "parent.json",
|
||||
"prefab" : "prefab_root.json",
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "prefab"
|
||||
"name" : "child"
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [1,2],
|
||||
@@ -2,7 +2,7 @@
|
||||
"uuid" : "73740BC4-CE9F-4A7F-A029-4AB65027A8AE",
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "parent"
|
||||
"name" : "root"
|
||||
},
|
||||
"circle_collider" : {
|
||||
"radius" : 5,
|
||||
@@ -27,23 +27,26 @@ TEST_CASE("prefab"){
|
||||
safe_starter_initializer initializer;
|
||||
library& l = the<library>();
|
||||
{
|
||||
auto parent_res = l.load_asset<prefab_asset>("parent.json");
|
||||
REQUIRE(parent_res);
|
||||
REQUIRE(parent_res->content().uuid() == "73740BC4-CE9F-4A7F-A029-4AB65027A8AE");
|
||||
auto prefab_root_res = l.load_asset<prefab_asset>("prefab_root.json");
|
||||
REQUIRE(prefab_root_res);
|
||||
|
||||
REQUIRE(parent_res->content().children().size() == 2u);
|
||||
REQUIRE(parent_res->content().children()[0].uuid() == "4A93547E-4635-4C2F-9C59-3546E11B1722");
|
||||
REQUIRE(parent_res->content().children()[1].uuid() == "58063213-9FC1-457C-B773-B826BE1BE6D7");
|
||||
const prefab& prefab_root = prefab_root_res->content();
|
||||
REQUIRE(prefab_root.uuid() == "73740BC4-CE9F-4A7F-A029-4AB65027A8AE");
|
||||
|
||||
auto go = the<world>().instantiate(parent_res->content());
|
||||
REQUIRE(go);
|
||||
REQUIRE(prefab_root.children().size() == 2u);
|
||||
REQUIRE(prefab_root.children()[0].uuid() == "4A93547E-4635-4C2F-9C59-3546E11B1722");
|
||||
REQUIRE(prefab_root.children()[1].uuid() == "58063213-9FC1-457C-B773-B826BE1BE6D7");
|
||||
|
||||
auto go = the<world>().instantiate(prefab_root);
|
||||
|
||||
{
|
||||
REQUIRE(go.component<named>());
|
||||
REQUIRE(go.component<named>()->name() == "parent");
|
||||
REQUIRE(go.component<named>()->name() == "root");
|
||||
|
||||
REQUIRE(go.component<circle_collider>());
|
||||
REQUIRE(math::approximately(go.component<circle_collider>()->radius(), 5.f));
|
||||
REQUIRE(go.component<circle_collider>()->radius() == Approx(5.f));
|
||||
REQUIRE(go.component<circle_collider>()->offset() == v2f(4.f,2.f));
|
||||
}
|
||||
|
||||
{
|
||||
node_iptr go_node = go.component<actor>()
|
||||
@@ -75,31 +78,34 @@ TEST_CASE("prefab"){
|
||||
}
|
||||
|
||||
{
|
||||
auto prefab_res = l.load_asset<prefab_asset>("prefab.json");
|
||||
REQUIRE(prefab_res);
|
||||
REQUIRE(prefab_res->content().uuid().empty());
|
||||
auto prefab_child_res = l.load_asset<prefab_asset>("prefab_child.json");
|
||||
REQUIRE(prefab_child_res);
|
||||
|
||||
REQUIRE(prefab_res->content().children().size() == 2u);
|
||||
REQUIRE(prefab_res->content().children()[0].uuid() == "4A93547E-4635-4C2F-9C59-3546E11B1722");
|
||||
REQUIRE(prefab_res->content().children()[1].uuid() == "58063213-9FC1-457C-B773-B826BE1BE6D7");
|
||||
const prefab& prefab_child = prefab_child_res->content();
|
||||
REQUIRE(prefab_child.uuid().empty());
|
||||
|
||||
auto go = the<world>().instantiate(prefab_res->content());
|
||||
REQUIRE(go);
|
||||
REQUIRE(prefab_child.children().size() == 2u);
|
||||
REQUIRE(prefab_child.children()[0].uuid() == "4A93547E-4635-4C2F-9C59-3546E11B1722");
|
||||
REQUIRE(prefab_child.children()[1].uuid() == "58063213-9FC1-457C-B773-B826BE1BE6D7");
|
||||
|
||||
auto go = the<world>().instantiate(prefab_child);
|
||||
|
||||
{
|
||||
REQUIRE(go.component<named>());
|
||||
REQUIRE(go.component<named>()->name() == "prefab");
|
||||
REQUIRE(go.component<named>()->name() == "child");
|
||||
|
||||
REQUIRE(go.component<rect_collider>());
|
||||
REQUIRE(go.component<rect_collider>()->size() == v2f(1.f,2.f));
|
||||
REQUIRE(go.component<rect_collider>()->offset() == v2f(2.f,4.f));
|
||||
|
||||
REQUIRE(go.component<circle_collider>());
|
||||
REQUIRE(math::approximately(go.component<circle_collider>()->radius(), 5.f));
|
||||
REQUIRE(go.component<circle_collider>()->radius() == Approx(5.f));
|
||||
REQUIRE(go.component<circle_collider>()->offset() == v2f(4.f,2.f));
|
||||
|
||||
REQUIRE(go.component<polygon_collider>());
|
||||
REQUIRE(go.component<polygon_collider>()->points() == vector<v2f>{{1,2},{2,3},{3,4}});
|
||||
REQUIRE(go.component<polygon_collider>()->offset() == v2f(8.f,4.f));
|
||||
}
|
||||
|
||||
{
|
||||
node_iptr go_node = go.component<actor>()
|
||||
|
||||
Reference in New Issue
Block a user