mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
add uuid property to prefab, rename prototype to parent
This commit is contained in:
@@ -27,22 +27,30 @@ namespace e2d
|
|||||||
prefab& assign(prefab&& other) noexcept;
|
prefab& assign(prefab&& other) noexcept;
|
||||||
prefab& assign(const prefab& other);
|
prefab& assign(const prefab& other);
|
||||||
|
|
||||||
prefab& set_prototype(ecs::prototype&& proto) noexcept;
|
prefab& set_uuid(str&& uuid) noexcept;
|
||||||
prefab& set_prototype(const ecs::prototype& proto);
|
prefab& set_uuid(const str& uuid);
|
||||||
|
|
||||||
prefab& set_children(vector<prefab>&& children) noexcept;
|
prefab& set_children(vector<prefab>&& children) noexcept;
|
||||||
prefab& set_children(const vector<prefab>& children);
|
prefab& set_children(const vector<prefab>& children);
|
||||||
|
|
||||||
|
prefab& set_prototype(ecs::prototype&& prototype) noexcept;
|
||||||
|
prefab& set_prototype(const ecs::prototype& prototype);
|
||||||
|
|
||||||
|
str& uuid() noexcept;
|
||||||
|
const str& uuid() const noexcept;
|
||||||
|
|
||||||
|
vector<prefab>& children() noexcept;
|
||||||
|
const vector<prefab>& children() const noexcept;
|
||||||
|
|
||||||
ecs::prototype& prototype() noexcept;
|
ecs::prototype& prototype() noexcept;
|
||||||
const ecs::prototype& prototype() const noexcept;
|
const ecs::prototype& prototype() const noexcept;
|
||||||
|
|
||||||
const vector<prefab>& children() const noexcept;
|
|
||||||
private:
|
private:
|
||||||
ecs::prototype prototype_;
|
str uuid_;
|
||||||
vector<prefab> children_;
|
vector<prefab> children_;
|
||||||
|
ecs::prototype prototype_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void swap(prefab& l, prefab& r) noexcept;
|
void swap(prefab& l, prefab& r) noexcept;
|
||||||
bool operator==(const prefab& l, const prefab& r) noexcept;
|
bool operator==(const prefab& l, const prefab& r) = delete;
|
||||||
bool operator!=(const prefab& l, const prefab& r) noexcept;
|
bool operator!=(const prefab& l, const prefab& r) = delete;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,10 @@ namespace
|
|||||||
"required" : [],
|
"required" : [],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"prototype" : { "$ref": "#/common_definitions/address" },
|
"uuid" : { "$ref": "#/common_definitions/uuid" },
|
||||||
"components" : { "type" : "object" },
|
"parent" : { "$ref": "#/common_definitions/address" },
|
||||||
"children" : {
|
"children" : { "$ref": "#/definitions/children" },
|
||||||
"type" : "array",
|
"components" : { "type" : "object" }
|
||||||
"items" : { "$ref": "#/definitions/child" }
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"definitions" : {
|
"definitions" : {
|
||||||
"child" : {
|
"child" : {
|
||||||
@@ -37,13 +35,15 @@ namespace
|
|||||||
"required" : [],
|
"required" : [],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"prototype" : { "$ref": "#/common_definitions/address" },
|
"uuid" : { "$ref": "#/common_definitions/uuid" },
|
||||||
"components" : { "type" : "object" },
|
"parent" : { "$ref": "#/common_definitions/address" },
|
||||||
"children" : {
|
"children" : { "$ref": "#/definitions/children" },
|
||||||
"type" : "array",
|
"components" : { "type" : "object" }
|
||||||
"items" : { "$ref": "#/definitions/child" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"children" : {
|
||||||
|
"type" : "array",
|
||||||
|
"items" : { "$ref": "#/definitions/child" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})json";
|
})json";
|
||||||
@@ -71,9 +71,16 @@ namespace
|
|||||||
const rapidjson::Value& root,
|
const rapidjson::Value& root,
|
||||||
asset_dependencies& dependencies)
|
asset_dependencies& dependencies)
|
||||||
{
|
{
|
||||||
if ( root.HasMember("prototype") ) {
|
if ( root.HasMember("parent") ) {
|
||||||
dependencies.add_dependency<prefab_asset>(
|
dependencies.add_dependency<prefab_asset>(
|
||||||
path::combine(parent_address, root["prototype"].GetString()));
|
path::combine(parent_address, root["parent"].GetString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("children") ) {
|
||||||
|
const rapidjson::Value& children_root = root["children"];
|
||||||
|
for ( rapidjson::SizeType i = 0; i < children_root.Size(); ++i ) {
|
||||||
|
collect_dependencies(parent_address, children_root[i], dependencies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( root.HasMember("components") ) {
|
if ( root.HasMember("components") ) {
|
||||||
@@ -83,7 +90,7 @@ namespace
|
|||||||
++component_root )
|
++component_root )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
bool success = the<factory>().validate_json(
|
const bool success = the<factory>().validate_json(
|
||||||
component_root->name.GetString(),
|
component_root->name.GetString(),
|
||||||
component_root->value);
|
component_root->value);
|
||||||
if ( !success ) {
|
if ( !success ) {
|
||||||
@@ -94,7 +101,7 @@ namespace
|
|||||||
factory_loader<>::collect_context ctx(
|
factory_loader<>::collect_context ctx(
|
||||||
str(parent_address),
|
str(parent_address),
|
||||||
component_root->value);
|
component_root->value);
|
||||||
bool success = the<factory>().collect_dependencies(
|
const bool success = the<factory>().collect_dependencies(
|
||||||
component_root->name.GetString(),
|
component_root->name.GetString(),
|
||||||
dependencies,
|
dependencies,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -104,13 +111,6 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( root.HasMember("children") ) {
|
|
||||||
const rapidjson::Value& children_root = root["children"];
|
|
||||||
for ( rapidjson::SizeType i = 0; i < children_root.Size(); ++i ) {
|
|
||||||
collect_dependencies(parent_address, children_root[i], dependencies);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdex::promise<asset_group> collect_dependencies(
|
stdex::promise<asset_group> collect_dependencies(
|
||||||
@@ -130,38 +130,28 @@ namespace
|
|||||||
{
|
{
|
||||||
prefab content;
|
prefab content;
|
||||||
|
|
||||||
if ( root.HasMember("prototype") ) {
|
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();
|
||||||
|
}
|
||||||
|
content.set_uuid(std::move(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("parent") ) {
|
||||||
auto proto_res = dependencies.find_asset<prefab_asset>(
|
auto proto_res = dependencies.find_asset<prefab_asset>(
|
||||||
path::combine(parent_address, root["prototype"].GetString()));
|
path::combine(parent_address, root["parent"].GetString()));
|
||||||
if ( !proto_res ) {
|
if ( !proto_res ) {
|
||||||
the<debug>().error("PREFAB: Dependency 'prototype' is not found:\n"
|
the<debug>().error("PREFAB: Dependency 'parent' is not found:\n"
|
||||||
"--> Parent address: %0\n"
|
"--> Parent address: %0\n"
|
||||||
"--> Dependency address: %1",
|
"--> Dependency address: %1",
|
||||||
parent_address,
|
parent_address,
|
||||||
root["prototype"].GetString());
|
root["parent"].GetString());
|
||||||
throw prefab_asset_loading_exception();
|
throw prefab_asset_loading_exception();
|
||||||
}
|
}
|
||||||
content = proto_res->content();
|
content.set_children(proto_res->content().children());
|
||||||
}
|
content.set_prototype(proto_res->content().prototype());
|
||||||
|
|
||||||
if ( root.HasMember("components") ) {
|
|
||||||
const rapidjson::Value& components_root = root["components"];
|
|
||||||
for ( rapidjson::Value::ConstMemberIterator component_root = components_root.MemberBegin();
|
|
||||||
component_root != components_root.MemberEnd();
|
|
||||||
++component_root )
|
|
||||||
{
|
|
||||||
factory_loader<>::fill_context ctx(
|
|
||||||
str(parent_address),
|
|
||||||
component_root->value,
|
|
||||||
dependencies);
|
|
||||||
bool success = the<factory>().fill_prototype(
|
|
||||||
component_root->name.GetString(),
|
|
||||||
content.prototype(),
|
|
||||||
ctx);
|
|
||||||
if ( !success ) {
|
|
||||||
throw prefab_asset_loading_exception();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( root.HasMember("children") ) {
|
if ( root.HasMember("children") ) {
|
||||||
@@ -178,6 +168,26 @@ namespace
|
|||||||
content.set_children(std::move(children));
|
content.set_children(std::move(children));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("components") ) {
|
||||||
|
const rapidjson::Value& components_root = root["components"];
|
||||||
|
for ( rapidjson::Value::ConstMemberIterator component_root = components_root.MemberBegin();
|
||||||
|
component_root != components_root.MemberEnd();
|
||||||
|
++component_root )
|
||||||
|
{
|
||||||
|
factory_loader<>::fill_context ctx(
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,16 @@ namespace e2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
void prefab::clear() noexcept {
|
void prefab::clear() noexcept {
|
||||||
prototype_.clear();
|
uuid_.clear();
|
||||||
children_.clear();
|
children_.clear();
|
||||||
|
prototype_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void prefab::swap(prefab& other) noexcept {
|
void prefab::swap(prefab& other) noexcept {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(prototype_, other.prototype_);
|
swap(uuid_, other.uuid_);
|
||||||
swap(children_, other.children_);
|
swap(children_, other.children_);
|
||||||
|
swap(prototype_, other.prototype_);
|
||||||
}
|
}
|
||||||
|
|
||||||
prefab& prefab::assign(prefab&& other) noexcept {
|
prefab& prefab::assign(prefab&& other) noexcept {
|
||||||
@@ -46,20 +48,21 @@ namespace e2d
|
|||||||
prefab& prefab::assign(const prefab& other) {
|
prefab& prefab::assign(const prefab& other) {
|
||||||
if ( this != &other ) {
|
if ( this != &other ) {
|
||||||
prefab s;
|
prefab s;
|
||||||
s.prototype_ = other.prototype_;
|
s.uuid_ = other.uuid_;
|
||||||
s.children_ = other.children_;
|
s.children_ = other.children_;
|
||||||
|
s.prototype_ = other.prototype_;
|
||||||
swap(s);
|
swap(s);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefab& prefab::set_prototype(ecs::prototype&& proto) noexcept {
|
prefab& prefab::set_uuid(str&& uuid) noexcept {
|
||||||
prototype_ = std::move(proto);
|
uuid_ = std::move(uuid);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefab& prefab::set_prototype(const ecs::prototype& proto) {
|
prefab& prefab::set_uuid(const str& uuid) {
|
||||||
prototype_ = proto;
|
uuid_ = uuid;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +76,32 @@ namespace e2d
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefab& prefab::set_prototype(ecs::prototype&& prototype) noexcept {
|
||||||
|
prototype_ = std::move(prototype);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefab& prefab::set_prototype(const ecs::prototype& prototype) {
|
||||||
|
prototype_ = prototype;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
str& prefab::uuid() noexcept {
|
||||||
|
return uuid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const str& prefab::uuid() const noexcept {
|
||||||
|
return uuid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<prefab>& prefab::children() noexcept {
|
||||||
|
return children_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vector<prefab>& prefab::children() const noexcept {
|
||||||
|
return children_;
|
||||||
|
}
|
||||||
|
|
||||||
ecs::prototype& prefab::prototype() noexcept {
|
ecs::prototype& prefab::prototype() noexcept {
|
||||||
return prototype_;
|
return prototype_;
|
||||||
}
|
}
|
||||||
@@ -80,10 +109,6 @@ namespace e2d
|
|||||||
const ecs::prototype& prefab::prototype() const noexcept {
|
const ecs::prototype& prefab::prototype() const noexcept {
|
||||||
return prototype_;
|
return prototype_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<prefab>& prefab::children() const noexcept {
|
|
||||||
return children_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
@@ -91,13 +116,4 @@ namespace e2d
|
|||||||
void swap(prefab& l, prefab& r) noexcept {
|
void swap(prefab& l, prefab& r) noexcept {
|
||||||
l.swap(r);
|
l.swap(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const prefab& l, const prefab& r) noexcept {
|
|
||||||
return l.prototype().empty() && l.children().empty()
|
|
||||||
&& r.prototype().empty() && r.children().empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const prefab& l, const prefab& r) noexcept {
|
|
||||||
return !(l == r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,12 @@ namespace
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
"guid" : {
|
||||||
|
"type" : "string",
|
||||||
|
"minLength" : 36,
|
||||||
|
"maxLength" : 36,
|
||||||
|
"pattern" : "^[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}$"
|
||||||
|
},
|
||||||
"name" : {
|
"name" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"minLength" : 1
|
"minLength" : 1
|
||||||
|
|||||||
12
untests/bin/library/parent.json
Normal file
12
untests/bin/library/parent.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"uuid" : "73740BC4-CE9F-4A7F-A029-4AB65027A8AE",
|
||||||
|
"components" : {
|
||||||
|
"named" : {
|
||||||
|
"name" : "parent"
|
||||||
|
},
|
||||||
|
"circle_collider" : {
|
||||||
|
"radius" : 5,
|
||||||
|
"offset" : [4,2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
{
|
{
|
||||||
|
"parent" : "prototype.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"touchable" : {},
|
"named" : {
|
||||||
|
"name" : "prefab"
|
||||||
|
},
|
||||||
"rect_collider" : {
|
"rect_collider" : {
|
||||||
"size" : [1,2],
|
"size" : [1,2],
|
||||||
"offset" : [2,4]
|
"offset" : [2,4]
|
||||||
},
|
},
|
||||||
|
|
||||||
"circle_collider" : {
|
|
||||||
"radius" : 5,
|
|
||||||
"offset" : [4,2]
|
|
||||||
},
|
|
||||||
|
|
||||||
"polygon_collider" : {
|
"polygon_collider" : {
|
||||||
"points" : [[1,2],[2,3],[3,4]],
|
"points" : [[1,2],[2,3],[3,4]],
|
||||||
"offset" : [8,4]
|
"offset" : [8,4]
|
||||||
|
|||||||
Reference in New Issue
Block a user