Skip to content

added support of cmd parser (#427) #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
[submodule "__externals/tlsf/src"]
path = __externals/tlsf/src
url = https://github.com/mattconte/tlsf
[submodule "__externals/CLI11"]
path = __externals/CLI11
url = https://github.com/CLIUtils/CLI11
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if (NOT LAUNCHER_ONLY)
add_subdirectory (${EXTERNAL_DIR}/gtest)
add_subdirectory (${EXTERNAL_DIR}/VulkanMemoryAllocator)
add_subdirectory (${EXTERNAL_DIR}/tlsf)
add_subdirectory (${EXTERNAL_DIR}/CLI11)

set (CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
Expand Down
7 changes: 6 additions & 1 deletion Tetragrama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)$(Configuration)")
endif ()

include(${EXTERNAL_DIR}/externals.cmake)

target_include_directories (${TARGET_NAME}
PRIVATE
.
Expand All @@ -54,6 +56,9 @@ target_compile_definitions(${TARGET_NAME}
_UNICODE
)

target_link_libraries(${TARGET_NAME} PRIVATE zEngineLib)
target_link_libraries(${TARGET_NAME} PRIVATE
zEngineLib
imported::External_editorLibs
)

set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "zEngineEditor")
63 changes: 63 additions & 0 deletions Tetragrama/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <MessageToken.h>
#include <Messengers/Messenger.h>
#include <fmt/format.h>
#include <nlohmann/json.hpp>

using namespace ZEngine;
using namespace ZEngine::Helpers;
Expand Down Expand Up @@ -78,4 +79,66 @@ namespace Tetragrama
{
return m_has_pending_change;
}

void EditorConfiguration::ReadConfig(std::string_view file)
{
std::ifstream f(file.data());
nlohmann::json config = nlohmann::json::parse(f);
std::string root_project_dir = std::filesystem::path(file).parent_path().string();

std::string working_space_path = config["workingSpace"];
if (working_space_path == ".")
{
std::string_view lookup_key("$(workingSpace)");
size_t length = lookup_key.size();

auto& texture_path = config["defaultImportDir"]["textureDir"];
auto& sound_path = config["defaultImportDir"]["soundDir"];
auto& scene_path = config["sceneDir"];
auto& scene_data_path = config["sceneDataDir"];

if (texture_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["defaultImportDir"]["textureDir"] = texture_path.get<std::string>().replace(texture_path.get<std::string>().find(lookup_key), length, "");
}

if (sound_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["defaultImportDir"]["soundDir"] = sound_path.get<std::string>().replace(sound_path.get<std::string>().find(lookup_key), length, "");
}

if (scene_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["sceneDir"] = scene_path.get<std::string>().replace(scene_path.get<std::string>().find(lookup_key), length, "");
}

if (scene_data_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["sceneDataDir"] = scene_data_path.get<std::string>().replace(scene_data_path.get<std::string>().find(lookup_key), length, "");
}

config["workingSpace"] = root_project_dir;
}

ProjectName = config["projectName"];
WorkingSpacePath = config["workingSpace"];
DefaultImportTexturePath = config["defaultImportDir"]["textureDir"];
DefaultImportSoundPath = config["defaultImportDir"]["soundDir"];
ScenePath = config["sceneDir"];
SceneDataPath = config["sceneDataDir"];

/*
* Retreiving the Active Scene
*/
for (const auto& scene : config["sceneList"])
{
bool is_default = scene["isDefault"].get<bool>();
if (!is_default)
{
continue;
}
ActiveSceneName = scene["name"];
break;
}
}
} // namespace Tetragrama
2 changes: 2 additions & 0 deletions Tetragrama/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace Tetragrama
std::string SceneDataPath;
std::string ProjectName;
std::string ActiveSceneName;

void ReadConfig(std::string_view file);
};

struct EditorContext : public ZEngine::Helpers::RefCounted
Expand Down
105 changes: 11 additions & 94 deletions Tetragrama/EntryPoint.cpp
Original file line number Diff line number Diff line change
@@ -1,109 +1,26 @@
#include <pch.h>
#include <CLI/CLI.hpp>
#include "Editor.h"
#include "nlohmann/json.hpp"

#ifdef ZENGINE_PLATFORM

namespace fs = std::filesystem;

static void ConfigureWorkingSpace(nlohmann::json& config, std::string_view ws_path)
{
std::string working_space_path = config["workingSpace"];
if (working_space_path == ".")
{
std::string_view lookup_key("$(workingSpace)");
size_t length = lookup_key.size();

auto& texture_path = config["defaultImportDir"]["textureDir"];
auto& sound_path = config["defaultImportDir"]["soundDir"];
auto& scene_path = config["sceneDir"];
auto& scene_data_path = config["sceneDataDir"];

if (texture_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["defaultImportDir"]["textureDir"] = texture_path.get<std::string>().replace(texture_path.get<std::string>().find(lookup_key), length, "");
}

if (sound_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["defaultImportDir"]["soundDir"] = sound_path.get<std::string>().replace(sound_path.get<std::string>().find(lookup_key), length, "");
}

if (scene_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["sceneDir"] = scene_path.get<std::string>().replace(scene_path.get<std::string>().find(lookup_key), length, "");
}

if (scene_data_path.get<std::string>().find(lookup_key) != std::string::npos)
{
config["sceneDataDir"] = scene_data_path.get<std::string>().replace(scene_data_path.get<std::string>().find(lookup_key), length, "");
}

config["workingSpace"] = ws_path;
}
}

int applicationEntryPoint(int argc, char* argv[])
{
std::string_view project_config_json;

if (argc == 1)
{
return -2; // Missing arguments
}
else if (argc > 1)
{
std::string_view config_file_arg = "--projectConfigFile";
for (int i = 1; i < argc; ++i)
{
if (config_file_arg == std::string_view(argv[i]))
{
project_config_json = argv[i + 1];
}
}
}
CLI::App app{"ZEngine Editor"};
argv = app.ensure_utf8(argv);

try
{
if (project_config_json.empty())
{
return -2;
}
std::string json_config_file{""};
app.add_option("--projectConfigFile", json_config_file, "The project config file");

std::ifstream f(project_config_json.data());
nlohmann::json config = nlohmann::json::parse(f);
std::string root_project_dir = std::filesystem::path(project_config_json).parent_path().string();
ConfigureWorkingSpace(config, root_project_dir);
CLI11_PARSE(app, argc, argv);

Tetragrama::EditorConfiguration editor_config = {};
editor_config.ProjectName = config["projectName"];
editor_config.WorkingSpacePath = config["workingSpace"];
editor_config.DefaultImportTexturePath = config["defaultImportDir"]["textureDir"];
editor_config.DefaultImportSoundPath = config["defaultImportDir"]["soundDir"];
editor_config.ScenePath = config["sceneDir"];
editor_config.SceneDataPath = config["sceneDataDir"];
Tetragrama::EditorConfiguration editor_config = {};
editor_config.ReadConfig(json_config_file);

/*
* Retreiving the Active Scene
*/
for (const auto& scene : config["sceneList"])
{
bool is_default = scene["isDefault"].get<bool>();
if (!is_default)
{
continue;
}
editor_config.ActiveSceneName = scene["name"];
break;
}
auto editor = ZEngine::Helpers::CreateRef<Tetragrama::Editor>(editor_config);
editor->Initialize();
editor->Run();

auto editor = ZEngine::Helpers::CreateRef<Tetragrama::Editor>(editor_config);
editor->Initialize();
editor->Run();
}
catch (const std::exception& e)
{
}
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions __externals/CLI11
Submodule CLI11 added at f75fd2
7 changes: 7 additions & 0 deletions __externals/externals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(EXTERNAL_INCLUDE_DIRS
${EXTERNAL_DIR}/SPIRV-Cross
${EXTERNAL_DIR}/VulkanMemoryAllocator
${EXTERNAL_DIR}/nlohmann_json/single_include
${EXTERNAL_DIR}/CLI11/include
)

if (MSVC)
Expand All @@ -31,6 +32,12 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()

add_library (imported::External_libs INTERFACE IMPORTED)
add_library(imported::External_editorLibs INTERFACE IMPORTED)


target_link_libraries(imported::External_editorLibs INTERFACE
CLI11::CLI11
)

target_link_libraries(imported::External_libs INTERFACE
vulkan
Expand Down