|
|
|
|
@ -41,6 +41,11 @@ namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
return mUUID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entt::entity Entity::GetEnttHandle() const
|
|
|
|
|
{
|
|
|
|
|
return mHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Entity::GetName() const
|
|
|
|
|
{
|
|
|
|
|
@ -53,9 +58,10 @@ namespace lunarium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Entity::HasChildren() const
|
|
|
|
|
bool Entity::HasChildren()
|
|
|
|
|
{
|
|
|
|
|
return mChildren.size() > 0;
|
|
|
|
|
return HasComponent<ChildrenComponent>();
|
|
|
|
|
//return mChildren.size() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +69,16 @@ namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
Entity* e = mWorld.GetEntity(child);
|
|
|
|
|
e->AddComponent<ParentEntityComponent>(mUUID);
|
|
|
|
|
mChildren.push_back(child);
|
|
|
|
|
|
|
|
|
|
if (!HasComponent<ChildrenComponent>())
|
|
|
|
|
{
|
|
|
|
|
AddComponent<ChildrenComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChildrenComponent& ccomp = GetComponent<ChildrenComponent>();
|
|
|
|
|
ccomp.Children.push_back(child);
|
|
|
|
|
|
|
|
|
|
//mChildren.push_back(child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -71,40 +86,61 @@ namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
Entity* e = mWorld.GetEntity(child);
|
|
|
|
|
e->ClearParent();
|
|
|
|
|
for (auto iter = mChildren.begin(); iter != mChildren.end(); iter++)
|
|
|
|
|
|
|
|
|
|
if (!HasChildren())
|
|
|
|
|
{
|
|
|
|
|
Logger::Error(LogCategory::GAME_SYSTEM, "RemoveChild called on entity that does not have children");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChildrenComponent& ccomp = GetComponent<ChildrenComponent>();
|
|
|
|
|
for (auto iter = ccomp.Children.begin(); iter != ccomp.Children.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
if ((*iter) == child)
|
|
|
|
|
{
|
|
|
|
|
mChildren.erase(iter);
|
|
|
|
|
ccomp.Children.erase(iter);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ccomp.Children.size() < 1)
|
|
|
|
|
{
|
|
|
|
|
RemoveComponent<ChildrenComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<LUUID>& Entity::GetChildren() const
|
|
|
|
|
std::vector<LUUID>& Entity::GetChildren()
|
|
|
|
|
{
|
|
|
|
|
return mChildren;
|
|
|
|
|
if (!HasChildren())
|
|
|
|
|
{
|
|
|
|
|
Logger::Error(LogCategory::GAME_SYSTEM, "GetChildren called on entity that does not have children");
|
|
|
|
|
return std::move(std::vector<LUUID>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChildrenComponent& ccomp = GetComponent<ChildrenComponent>();
|
|
|
|
|
return ccomp.Children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Entity::HasParent() const
|
|
|
|
|
{
|
|
|
|
|
return mParentSet;
|
|
|
|
|
}
|
|
|
|
|
// bool Entity::HasParent() const
|
|
|
|
|
// {
|
|
|
|
|
// return mParentSet;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
LUUID Entity::GetParent() const
|
|
|
|
|
{
|
|
|
|
|
return mParent;
|
|
|
|
|
}
|
|
|
|
|
// LUUID Entity::GetParent() const
|
|
|
|
|
// {
|
|
|
|
|
// return mParent;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
void Entity::SetParent(LUUID parent)
|
|
|
|
|
{
|
|
|
|
|
mParent = parent;
|
|
|
|
|
}
|
|
|
|
|
// void Entity::SetParent(LUUID parent)
|
|
|
|
|
// {
|
|
|
|
|
// mParent = parent;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
void Entity::ClearParent()
|
|
|
|
|
{
|
|
|
|
|
mParentSet = false;
|
|
|
|
|
RemoveComponent<ParentEntityComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,6 +155,15 @@ namespace lunarium
|
|
|
|
|
node["name"] = mName;
|
|
|
|
|
|
|
|
|
|
auto& components = node["components"];
|
|
|
|
|
|
|
|
|
|
if (HasComponent<UUIDComponent>())
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json uuid;
|
|
|
|
|
uuid["type_name"] = "UUIDComponent";
|
|
|
|
|
uuid["UUID"] = (u64)GetComponent<UUIDComponent>().UUID;
|
|
|
|
|
components.emplace_back(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HasComponent<TagComponent>())
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json tag;
|
|
|
|
|
@ -210,22 +255,39 @@ namespace lunarium
|
|
|
|
|
nlohmann::ordered_json parent;
|
|
|
|
|
ParentEntityComponent& comp = GetComponent<ParentEntityComponent>();
|
|
|
|
|
parent["type_name"] = "ParentEntityComponent";
|
|
|
|
|
parent["UUID"] = (u64)comp.parent;
|
|
|
|
|
parent["UUID"] = (u64)comp.Parent;
|
|
|
|
|
components.emplace_back(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HasComponent<ChildrenComponent>())
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json children_node;
|
|
|
|
|
ChildrenComponent& comp = GetComponent<ChildrenComponent>();
|
|
|
|
|
children_node["type_name"] = "ChildrenComponent";
|
|
|
|
|
|
|
|
|
|
auto& children = children_node["children"];
|
|
|
|
|
for (int i = 0; i < comp.Children.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json child;
|
|
|
|
|
child["UUID"] = comp.Children[i];
|
|
|
|
|
children.emplace_back(child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
components.emplace_back(children_node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: ADD CODE TO SERIALIZE ANY NEW COMPONENTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Children
|
|
|
|
|
auto& children = node["children"];
|
|
|
|
|
for (int i = 0; i < mChildren.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json child;
|
|
|
|
|
child["UUID"] = mChildren[i];
|
|
|
|
|
children.emplace_back(child);
|
|
|
|
|
}
|
|
|
|
|
// auto& children = node["children"];
|
|
|
|
|
// for (int i = 0; i < mChildren.size(); i++)
|
|
|
|
|
// {
|
|
|
|
|
// nlohmann::ordered_json child;
|
|
|
|
|
// child["UUID"] = mChildren[i];
|
|
|
|
|
// children.emplace_back(child);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return OpRes::OK();
|
|
|
|
|
@ -246,6 +308,12 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
std::string comp_type_name = comp["type_name"].get<std::string>();
|
|
|
|
|
|
|
|
|
|
if ("UUIDComponent" == comp_type_name)
|
|
|
|
|
{
|
|
|
|
|
LUUID uuid = comp["UUID"].get<u64>();
|
|
|
|
|
AddComponent<UUIDComponent>(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("TagComponent" == comp_type_name)
|
|
|
|
|
{
|
|
|
|
|
std::string info = comp["info"].get<std::string>();
|
|
|
|
|
@ -325,20 +393,35 @@ namespace lunarium
|
|
|
|
|
AddComponent<ParentEntityComponent>(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("ChildrenComponent" == comp_type_name)
|
|
|
|
|
{
|
|
|
|
|
auto& children = comp["children"];
|
|
|
|
|
std::vector<LUUID> children_vec;
|
|
|
|
|
for (auto iter = children.begin(); iter != children.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
auto& child = *iter;
|
|
|
|
|
|
|
|
|
|
LUUID ne = child["UUID"].get<u64>();
|
|
|
|
|
children_vec.push_back(ne);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddComponent<ChildrenComponent>(children_vec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: ADD CODE TO DESERIALIZE ANY NEW COMPONENTS
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Load children
|
|
|
|
|
auto& children = node["children"];
|
|
|
|
|
for (auto iter = children.begin(); iter != children.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
auto& child = *iter;
|
|
|
|
|
|
|
|
|
|
LUUID ne = child["UUID"].get<u64>();
|
|
|
|
|
mChildren.push_back(ne);
|
|
|
|
|
}
|
|
|
|
|
// auto& children = node["children"];
|
|
|
|
|
// for (auto iter = children.begin(); iter != children.end(); iter++)
|
|
|
|
|
// {
|
|
|
|
|
// auto& child = *iter;
|
|
|
|
|
|
|
|
|
|
// LUUID ne = child["UUID"].get<u64>();
|
|
|
|
|
// mChildren.push_back(ne);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return OpRes::OK();
|
|
|
|
|
|