From 7846a667a2ed4e9ddc5a31f0ca5217c0e1881780 Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 15 Sep 2024 00:11:12 +0100 Subject: [PATCH] Quake Map Component reflected --- Editor/src/ComponentsPanel/QuakeMapPanel.h | 124 ++++++++++---------- Nuake/src/Scene/Components/QuakeMap.h | 30 ++++- Nuake/src/Scene/Scene.cpp | 4 +- Nuake/src/Scene/Systems/QuakeMapBuilder.cpp | 2 +- 4 files changed, 89 insertions(+), 71 deletions(-) diff --git a/Editor/src/ComponentsPanel/QuakeMapPanel.h b/Editor/src/ComponentsPanel/QuakeMapPanel.h index f326b4ff..56546b70 100644 --- a/Editor/src/ComponentsPanel/QuakeMapPanel.h +++ b/Editor/src/ComponentsPanel/QuakeMapPanel.h @@ -13,67 +13,67 @@ public: void Draw(Nuake::Entity entity) override { - using namespace Nuake; - - if (!entity.HasComponent()) - return; - - Nuake::QuakeMapComponent& component = entity.GetComponent(); - BeginComponentTable(QUAKEMAP, Nuake::QuakeMapComponent); - { - { - ImGui::Text("Map"); - ImGui::TableNextColumn(); - - std::string path = component.Path; - ImGui::Button(component.Path.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = Nuake::FileSystem::AbsoluteToRelative(fullPath); - - component.Path = path; - } - ImGui::EndDragDropTarget(); - } - - ImGui::TableNextColumn(); - - ComponentTableReset(component.Path, ""); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Collision"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##Collison", &component.HasCollisions); - ImGui::TableNextColumn(); - ComponentTableReset(component.HasCollisions, true); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Auto Rebuild"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##AutoRebuild", &component.AutoRebuild); - ImGui::TableNextColumn(); - ComponentTableReset(component.AutoRebuild, false); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Build"); - ImGui::TableNextColumn(); - - if (UI::SecondaryButton("Build Geometry")) - { - Nuake::QuakeMapBuilder builder; - builder.BuildQuakeMap(entity, component.HasCollisions); - } - } - } - EndComponentTable(); + // using namespace Nuake; + // + // if (!entity.HasComponent()) + // return; + // + // Nuake::QuakeMapComponent& component = entity.GetComponent(); + // BeginComponentTable(QUAKEMAP, Nuake::QuakeMapComponent); + // { + // { + // ImGui::Text("Map"); + // ImGui::TableNextColumn(); + // + // std::string path = component.Path; + // ImGui::Button(component.Path.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + // if (ImGui::BeginDragDropTarget()) + // { + // if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map")) + // { + // char* file = (char*)payload->Data; + // std::string fullPath = std::string(file, 256); + // path = Nuake::FileSystem::AbsoluteToRelative(fullPath); + // + // component.Path = path; + // } + // ImGui::EndDragDropTarget(); + // } + // + // ImGui::TableNextColumn(); + // + // ComponentTableReset(component.Path, ""); + // } + // ImGui::TableNextColumn(); + // { + // ImGui::Text("Collision"); + // ImGui::TableNextColumn(); + // + // ImGui::Checkbox("##Collison", &component.HasCollisions); + // ImGui::TableNextColumn(); + // ComponentTableReset(component.HasCollisions, true); + // } + // ImGui::TableNextColumn(); + // { + // ImGui::Text("Auto Rebuild"); + // ImGui::TableNextColumn(); + // + // ImGui::Checkbox("##AutoRebuild", &component.AutoRebuild); + // ImGui::TableNextColumn(); + // ComponentTableReset(component.AutoRebuild, false); + // } + // ImGui::TableNextColumn(); + // { + // ImGui::Text("Build"); + // ImGui::TableNextColumn(); + // + // if (UI::SecondaryButton("Build Geometry")) + // { + // Nuake::QuakeMapBuilder builder; + // builder.BuildQuakeMap(entity, component.HasCollisions); + // } + // } + // } + // EndComponentTable(); } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Components/QuakeMap.h b/Nuake/src/Scene/Components/QuakeMap.h index e777febf..f99c4d3b 100644 --- a/Nuake/src/Scene/Components/QuakeMap.h +++ b/Nuake/src/Scene/Components/QuakeMap.h @@ -1,7 +1,9 @@ #pragma once #include "Component.h" +#include "FieldTypes.h" +#include "src/FileSystem/File.h" #include "src/Rendering/Mesh/Mesh.h" #include "src/Resource/Serializable.h" #include "src/Scene/Systems/QuakeMapBuilder.h" @@ -11,27 +13,39 @@ #include #include + namespace Nuake { class QuakeMapComponent : public Component { NUAKECOMPONENT(QuakeMapComponent, "Quake Map") + static void InitializeComponentClass() + { + BindComponentField<&QuakeMapComponent::HasCollisions>("HasCollisions", "Has Collisions"); + BindComponentField<&QuakeMapComponent::Path>("Path", "Path"); + BindComponentField<&QuakeMapComponent::AutoRebuild>("AutoRebuild", "Auto Rebuild"); + + BindAction<&QuakeMapComponent::ActionRebuild>("Rebuild", "Rebuild"); + } + public: + bool HasCollisions = false; + ResourceFile Path; + bool AutoRebuild = false; + float ScaleFactor = 1.f; + std::vector> m_Meshes; std::vector m_Brushes; std::vector m_SerializedBrushIDs; - std::string Path; - float ScaleFactor = 1.0f; - bool HasCollisions = false; - bool AutoRebuild = false; + void ActionRebuild(); json Serialize() { BEGIN_SERIALIZE(); SERIALIZE_VAL(HasCollisions); - SERIALIZE_VAL(Path); + SERIALIZE_RES_FILE(Path); SERIALIZE_VAL(AutoRebuild); for (uint32_t i = 0; i < std::size(m_Brushes); i++) @@ -64,7 +78,7 @@ namespace Nuake { } } - this->Path = j["Path"]; + DESERIALIZE_RES_FILE(Path); this->HasCollisions = j["HasCollisions"]; return true; } @@ -81,4 +95,8 @@ namespace Nuake { m_SerializedBrushIDs.clear(); } }; + + inline void QuakeMapComponent::ActionRebuild() + { + } } diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index a48f3e6b..f7b73998 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -273,9 +273,9 @@ namespace Nuake for (const auto& e : view) { auto& map = view.get(e); - if (map.AutoRebuild && !map.Path.empty() && FileSystem::FileExists(map.Path)) + if (map.AutoRebuild && map.Path.Exist()) { - if (auto file = FileSystem::GetFile(map.Path); file->Exist() && file->GetHasBeenModified()) + if (auto file = FileSystem::GetFile(map.Path.GetRelativePath()); file->Exist() && file->GetHasBeenModified()) { file->SetHasBeenModified(false); diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index cb1ad4f7..67b9be85 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -67,7 +67,7 @@ namespace Nuake { m_Scene->DestroyEntity(e); } - map_parser_load((FileSystem::Root + quakeMapC.Path).c_str()); + map_parser_load(quakeMapC.Path.GetAbsolutePath().c_str()); geo_generator_run(); DefaultMaterial = MaterialManager::Get()->GetMaterial("default");