|
|
|
|
@ -14,7 +14,7 @@
|
|
|
|
|
namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
Entity::Entity(World& w)
|
|
|
|
|
: mHandle(entt::null), mWorld(w)
|
|
|
|
|
: mHandle(entt::null), mWorld(w), mParent(0), mParentSet(false)
|
|
|
|
|
{
|
|
|
|
|
mUUID = UUID::GetNewID();
|
|
|
|
|
Init();
|
|
|
|
|
@ -42,6 +42,16 @@ namespace lunarium
|
|
|
|
|
return mUUID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Entity::GetName() const
|
|
|
|
|
{
|
|
|
|
|
return mName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Entity::SetName(std::string name)
|
|
|
|
|
{
|
|
|
|
|
mName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Entity::HasChildren() const
|
|
|
|
|
{
|
|
|
|
|
@ -49,9 +59,52 @@ namespace lunarium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Entity::AddChild(Entity* pChild)
|
|
|
|
|
void Entity::AddChild(LUUID child)
|
|
|
|
|
{
|
|
|
|
|
Entity* e = mWorld.GetEntity(child);
|
|
|
|
|
e->AddComponent<ParentEntityComponent>(mUUID);
|
|
|
|
|
mChildren.push_back(child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Entity::RemoveChild(LUUID child)
|
|
|
|
|
{
|
|
|
|
|
Entity* e = mWorld.GetEntity(child);
|
|
|
|
|
e->ClearParent();
|
|
|
|
|
for (auto iter = mChildren.begin(); iter != mChildren.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
if ((*iter) == child)
|
|
|
|
|
{
|
|
|
|
|
mChildren.erase(iter);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<LUUID>& Entity::GetChildren() const
|
|
|
|
|
{
|
|
|
|
|
mChildren.push_back(pChild);
|
|
|
|
|
return mChildren;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Entity::HasParent() const
|
|
|
|
|
{
|
|
|
|
|
return mParentSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LUUID Entity::GetParent() const
|
|
|
|
|
{
|
|
|
|
|
return mParent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Entity::SetParent(LUUID parent)
|
|
|
|
|
{
|
|
|
|
|
mParent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Entity::ClearParent()
|
|
|
|
|
{
|
|
|
|
|
mParentSet = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,6 +116,7 @@ namespace lunarium
|
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
|
|
|
|
|
|
node["UUID"] = mUUID;
|
|
|
|
|
node["name"] = mName;
|
|
|
|
|
|
|
|
|
|
auto& components = node["components"];
|
|
|
|
|
if (HasComponent<TagComponent>())
|
|
|
|
|
@ -151,6 +205,15 @@ namespace lunarium
|
|
|
|
|
components.emplace_back(blockout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HasComponent<ParentEntityComponent>())
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json parent;
|
|
|
|
|
ParentEntityComponent& comp = GetComponent<ParentEntityComponent>();
|
|
|
|
|
parent["type_name"] = "ParentEntityComponent";
|
|
|
|
|
parent["UUID"] = (u64)comp.parent;
|
|
|
|
|
components.emplace_back(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: ADD CODE TO SERIALIZE ANY NEW COMPONENTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -160,7 +223,7 @@ namespace lunarium
|
|
|
|
|
for (int i = 0; i < mChildren.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
nlohmann::ordered_json child;
|
|
|
|
|
mChildren[i]->Serialize(child).LogIfFailed(LogCategory::GAME_SYSTEM);
|
|
|
|
|
child["UUID"] = mChildren[i];
|
|
|
|
|
children.emplace_back(child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -173,6 +236,7 @@ namespace lunarium
|
|
|
|
|
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
|
|
|
|
|
|
|
|
|
|
mUUID = node["UUID"].get<u64>();
|
|
|
|
|
mName = node["name"].get<std::string>();
|
|
|
|
|
|
|
|
|
|
// TODO: Load components
|
|
|
|
|
auto& components = node["components"];
|
|
|
|
|
@ -255,6 +319,12 @@ namespace lunarium
|
|
|
|
|
AddComponent<BlockOutComponent>(Color, Size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("ParentEntityComponent" == comp_type_name)
|
|
|
|
|
{
|
|
|
|
|
LUUID parent = comp["UUID"].get<u64>();
|
|
|
|
|
AddComponent<ParentEntityComponent>(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: ADD CODE TO DESERIALIZE ANY NEW COMPONENTS
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -266,8 +336,7 @@ namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
auto& child = *iter;
|
|
|
|
|
|
|
|
|
|
Entity* ne = new Entity(mWorld);
|
|
|
|
|
ne->Deserialize(child).LogIfFailed(LogCategory::GAME_SYSTEM);
|
|
|
|
|
LUUID ne = child["UUID"].get<u64>();
|
|
|
|
|
mChildren.push_back(ne);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|