From 51b5f96cc36db647f85f885bcbf7f45c84c737cd Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 26 Dec 2018 07:19:16 -0500 Subject: [PATCH] Make remove component button functional' --- include/ecs.h | 12 +++++++++++- tools/leveleditor/src/properties.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/ecs.h b/include/ecs.h index 582815d..e8ef7bb 100644 --- a/include/ecs.h +++ b/include/ecs.h @@ -131,6 +131,16 @@ namespace ECS { template static inline void removeComponent(const EntityID id) { - delete transforms[id]; + if constexpr(std::is_same::value) { + infos.erase(infos.find(id), infos.end()); + } else if constexpr(std::is_same::value) { + transforms.erase(transforms.find(id), transforms.end()); + } else if constexpr(std::is_same::value) { + meshes.erase(meshes.find(id), meshes.end()); + } else if constexpr(std::is_same::value) { + lights.erase(lights.find(id), lights.end()); + } else if constexpr(std::is_same::value) { + cameras.erase(cameras.find(id), cameras.end()); + } } }; diff --git a/tools/leveleditor/src/properties.cpp b/tools/leveleditor/src/properties.cpp index 7e79100..266c65f 100644 --- a/tools/leveleditor/src/properties.cpp +++ b/tools/leveleditor/src/properties.cpp @@ -123,7 +123,14 @@ void Properties::addTransformSection(TransformComponent* transform) { } void Properties::addMeshSection(MeshComponent* mesh) { + const auto& entity = context.selectedEntities[0]; + CollapseSection* section = new CollapseSection("Mesh", true); + connect(section, &CollapseSection::closeRequested, [entity, this] { + ECS::removeComponent(entity); + + emit context.entitiesChanged(); + }); layout->addWidget(section); sections.push_back(section); @@ -132,7 +139,14 @@ void Properties::addMeshSection(MeshComponent* mesh) { } void Properties::addLightSection(LightComponent* light) { + const auto& entity = context.selectedEntities[0]; + CollapseSection* section = new CollapseSection("Light", true); + connect(section, &CollapseSection::closeRequested, [entity, this] { + ECS::removeComponent(entity); + + emit context.entitiesChanged(); + }); layout->addWidget(section); sections.push_back(section);