mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Started quake map importer
This commit is contained in:
@@ -2231,6 +2231,11 @@ namespace Nuake {
|
||||
{
|
||||
m_ShowTrenchbroomConfigurator = !m_ShowTrenchbroomConfigurator;
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Map Importer", NULL, m_ShowMapImporter))
|
||||
{
|
||||
m_ShowMapImporter = !m_ShowMapImporter;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("View"))
|
||||
@@ -2421,6 +2426,11 @@ namespace Nuake {
|
||||
m_TrenchhbroomConfigurator.Draw();
|
||||
}
|
||||
|
||||
if (m_ShowMapImporter)
|
||||
{
|
||||
m_MapImporter.Draw();
|
||||
}
|
||||
|
||||
DrawMenuBar();
|
||||
DrawMenuBars();
|
||||
DrawStatusBar();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../Windows/TrenchbroomConfiguratorWindow.h"
|
||||
#include "../Commands/CommandBuffer.h"
|
||||
#include "../Commands/ICommand.h"
|
||||
#include "MapImporterWindow.h"
|
||||
|
||||
using namespace NuakeEditor;
|
||||
|
||||
@@ -36,6 +37,7 @@ namespace Nuake
|
||||
bool m_IsHoveringViewport = false;
|
||||
bool m_IsViewportFocused = false;
|
||||
bool m_ShowTrenchbroomConfigurator = false;
|
||||
bool m_ShowMapImporter = false;
|
||||
|
||||
Vector2 m_ViewportPos = {0, 0};
|
||||
Vector2 m_ViewportSize = {};
|
||||
@@ -56,6 +58,7 @@ namespace Nuake
|
||||
EditorSelection Selection;
|
||||
EditorSelectionPanel SelectionPanel;
|
||||
TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator;
|
||||
MapImporterWindow m_MapImporter;
|
||||
|
||||
EditorInterface(CommandBuffer& commandBuffer);
|
||||
|
||||
|
||||
107
Editor/src/Windows/MapImporterWindow.cpp
Normal file
107
Editor/src/Windows/MapImporterWindow.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "MapImporterWindow.h"
|
||||
#include <imgui/imgui.h>
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
#include <src/UI/ImUI.h>
|
||||
#include <src/Core/Logger.h>
|
||||
#include <regex>
|
||||
|
||||
void MapImporterWindow::Draw()
|
||||
{
|
||||
auto& io = ImGui::GetIO();
|
||||
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(600, 400), ImVec2(1920, 1080));
|
||||
if (ImGui::Begin("Map Importer"))
|
||||
{
|
||||
ImGui::PushFont(FontManager::GetFont(Bold));
|
||||
ImGui::Text("What is this?");
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::TextWrapped("This imported will convert any Quake .map file into a .map that uses Nuake Material system.");
|
||||
|
||||
ImGui::PushFont(FontManager::GetFont(Bold));
|
||||
ImGui::Text("1. Select a quake .map to import");
|
||||
ImGui::PopFont();
|
||||
|
||||
std::string buttonLbl = "Empty";
|
||||
|
||||
if (m_MapToImport)
|
||||
{
|
||||
buttonLbl = m_MapToImport->GetRelativePath();
|
||||
}
|
||||
|
||||
using namespace Nuake;
|
||||
if (ImGui::Button(buttonLbl.c_str()))
|
||||
{
|
||||
std::string selectedFile = FileDialog::OpenFile("*.map");
|
||||
std::string relativePath = FileSystem::AbsoluteToRelative(selectedFile);
|
||||
if (FileSystem::FileExists(relativePath))
|
||||
{
|
||||
if (Ref<File> file = FileSystem::GetFile(relativePath); file)
|
||||
{
|
||||
m_MapToImport = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map"))
|
||||
{
|
||||
std::string fullPath = std::string(reinterpret_cast<char*>(payload->Data), 256);
|
||||
std::string relPath = FileSystem::AbsoluteToRelative(fullPath);
|
||||
if (FileSystem::FileExists(relPath))
|
||||
{
|
||||
if (Ref<File> file = FileSystem::GetFile(relPath); file)
|
||||
{
|
||||
m_MapToImport = file;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Log("Failed to import map file. File doesn't exists", "map importer", CRITICAL);
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
auto wads = ScanUsedWads();
|
||||
|
||||
if (Nuake::UI::PrimaryButton("Export"))
|
||||
{
|
||||
m_MapToImport = nullptr;
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
std::vector<std::string> MapImporterWindow::ScanUsedWads()
|
||||
{
|
||||
if (!m_MapToImport)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
const std::string mapContent = m_MapToImport->Read();
|
||||
|
||||
std::vector<std::string> usedWads;
|
||||
std::regex pattern("\"wad\"\\s*\"([^\"]+)\"");
|
||||
std::smatch match;
|
||||
|
||||
// Search the input string using the regular expression
|
||||
if (std::regex_search(mapContent, match, pattern))
|
||||
{
|
||||
const std::string fullString = match[1].str();
|
||||
|
||||
// Split multiple wads in case.
|
||||
auto separatedWads = String::Split(fullString, ';');
|
||||
for (auto& wad : separatedWads)
|
||||
{
|
||||
usedWads.push_back(wad);
|
||||
}
|
||||
}
|
||||
|
||||
// If no match is found, return an empty string
|
||||
return usedWads;
|
||||
}
|
||||
19
Editor/src/Windows/MapImporterWindow.h
Normal file
19
Editor/src/Windows/MapImporterWindow.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <src/Core/FileSystem.h>
|
||||
#include <src/Core/FileSystem.h>
|
||||
|
||||
class MapImporterWindow
|
||||
{
|
||||
public:
|
||||
MapImporterWindow() = default;
|
||||
~MapImporterWindow() = default;
|
||||
|
||||
void Update();
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
Ref<Nuake::File> m_MapToImport = nullptr;
|
||||
|
||||
std::vector<std::string> ScanUsedWads();
|
||||
};
|
||||
@@ -180,7 +180,7 @@ namespace Nuake
|
||||
|
||||
bool FileSystem::MakeDirectory(const std::string& path, bool absolute)
|
||||
{
|
||||
return std::filesystem::create_directory(absolute ? path : FileSystem::Root + path);
|
||||
return std::filesystem::create_directories(absolute ? path : FileSystem::Root + path);
|
||||
}
|
||||
|
||||
bool FileSystem::FileExists(const std::string& path, bool absolute)
|
||||
|
||||
@@ -203,9 +203,10 @@ namespace Nuake
|
||||
|
||||
return "File";
|
||||
}
|
||||
|
||||
std::string Read()
|
||||
{
|
||||
return FileSystem::ReadFile(AbsolutePath);
|
||||
return FileSystem::ReadFile(AbsolutePath, true);
|
||||
}
|
||||
|
||||
bool IsValid()
|
||||
|
||||
Reference in New Issue
Block a user