diff --git a/src/run_modes/editor/component_guis.cpp b/src/run_modes/editor/component_guis.cpp index 147cf75..75798e3 100644 --- a/src/run_modes/editor/component_guis.cpp +++ b/src/run_modes/editor/component_guis.cpp @@ -15,6 +15,10 @@ namespace lunarium { namespace editor { + // TODO: Add an X button on the right of the title line to remove components + // Will need to have the functions return a bool indicating when this + // button is pressed + ///////////////////////////////////////////////////////////////////// // COMMON SECTIONS ///////////////////////////////////////////////////////////////////// diff --git a/src/run_modes/editor/panels/properties_view.cpp b/src/run_modes/editor/panels/properties_view.cpp index 362918f..3fc2597 100644 --- a/src/run_modes/editor/panels/properties_view.cpp +++ b/src/run_modes/editor/panels/properties_view.cpp @@ -151,7 +151,8 @@ namespace lunarium { namespace editor void PropertiesView::ShowEntity() { - ImGui::Text("UUID: %ull", (u64)mpSelectedEntity->GetUUID()); + LUUID id = mpSelectedEntity->GetUUID(); + ImGui::Text("UUID: %llu", (u64)id); char buffer[256] = { 0 }; strcpy(buffer, mpSelectedEntity->GetName().c_str()); ImGui::Text("Name:"); diff --git a/src/world/entity.cpp b/src/world/entity.cpp index 73407fd..bbe85b2 100644 --- a/src/world/entity.cpp +++ b/src/world/entity.cpp @@ -16,15 +16,14 @@ namespace lunarium Entity::Entity(World& w) : mHandle(entt::null), mWorld(w), mParent(0), mParentSet(false) { - mUUID = UUID::GetNewID(); Init(); } - Entity::Entity(World& w, LUUID uuid, entt::entity handle) - : mHandle(handle), mWorld(w), mUUID(uuid) - { - Init(); - } + // Entity::Entity(World& w, entt::entity handle) + // : mHandle(handle), mWorld(w) + // { + // Init(); + // } void Entity::Init() { @@ -35,11 +34,14 @@ namespace lunarium { Logger::Warn(LogCategory::GAME_SYSTEM, "Requested entity handle was not used"); } + + AddComponent(UUID::GetNewID()); } - LUUID Entity::GetUUID() const + LUUID Entity::GetUUID() { - return mUUID; + return GetComponent().UUID; + // return mUUID; } entt::entity Entity::GetEnttHandle() const @@ -68,7 +70,7 @@ namespace lunarium void Entity::AddChild(LUUID child) { Entity* e = mWorld.GetEntity(child); - e->AddComponent(mUUID); + e->AddComponent(GetUUID()); if (!HasComponent()) { @@ -151,7 +153,7 @@ namespace lunarium { #if !BUILD_NO_EDITOR // Only does this when this is an editor build - node["UUID"] = mUUID; + // node["UUID"] = mUUID; node["name"] = mName; auto& components = node["components"]; @@ -299,7 +301,7 @@ namespace lunarium { #if !BUILD_NO_EDITOR // Only does this when this is an editor build - mUUID = node["UUID"].get(); + //mUUID = node["UUID"].get(); mName = node["name"].get(); // TODO: Load components @@ -313,7 +315,11 @@ namespace lunarium if ("UUIDComponent" == comp_type_name) { LUUID uuid = comp["UUID"].get(); - AddComponent(uuid); + //AddComponent(uuid); + if (HasComponent()) + { + GetComponent().UUID = uuid; + } } if ("TagComponent" == comp_type_name) @@ -433,8 +439,8 @@ namespace lunarium bool Entity::IsValidNode(nlohmann::ordered_json& node) { - if (node["UUID"].is_null()) { return false; } - if (!node["UUID"].is_number()) { return false; } + // if (node["UUID"].is_null()) { return false; } + // if (!node["UUID"].is_number()) { return false; } return true; } diff --git a/src/world/entity.h b/src/world/entity.h index 0923a87..4e0d17e 100644 --- a/src/world/entity.h +++ b/src/world/entity.h @@ -22,7 +22,7 @@ namespace lunarium // TODO: : public JSONSerializable { public: Entity(World& w); - Entity(World& w, LUUID uuid, entt::entity handle = entt::null); + //Entity(World& w, entt::entity handle = entt::null); // These component methods are based on methods from the Hazel engine, written by Cherno // https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Entity.h @@ -64,7 +64,7 @@ namespace lunarium // TODO: : public JSONSerializable mWorld.GetEntityRegistry()->remove(mHandle); } - LUUID GetUUID() const; + LUUID GetUUID(); entt::entity GetEnttHandle() const; std::string GetName() const; void SetName(std::string name); @@ -86,7 +86,7 @@ namespace lunarium // TODO: : public JSONSerializable [[nodiscard]] virtual nlohmann::ordered_json AsJSON(); private: - LUUID mUUID; + //LUUID mUUID; LUUID mParent; bool mParentSet; std::string mName; diff --git a/src/world/world.cpp b/src/world/world.cpp index 825a66e..2c9e245 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -111,9 +111,16 @@ namespace lunarium Rectangle rect(transform.Position.x, transform.Position.y, blockout.Size.x, blockout.Size.y); Color color(blockout.Color.x, blockout.Color.y, blockout.Color.z, blockout.Color.w); - // TODO: Get and apply parent transforms + // Get and apply parent transforms + LUUID uuid = mECSRegistry.get(entity).UUID; + Entity* pEnt = GetEntity(uuid); + glm::mat4 parent_transform = glm::mat4(1.0f); + if (pEnt->HasComponent()) + { + parent_transform = GetParentTransform(uuid); + } - pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), glm::mat4(1.0f)); + pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), parent_transform); } }