Skip to content

Commit e795414

Browse files
added support of cmd parser (#427)
1 parent 09be5ee commit e795414

File tree

8 files changed

+94
-95
lines changed

8 files changed

+94
-95
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@
6161
[submodule "__externals/tlsf/src"]
6262
path = __externals/tlsf/src
6363
url = https://github.com/mattconte/tlsf
64+
[submodule "__externals/CLI11"]
65+
path = __externals/CLI11
66+
url = https://github.com/CLIUtils/CLI11

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if (NOT LAUNCHER_ONLY)
5858
add_subdirectory (${EXTERNAL_DIR}/gtest)
5959
add_subdirectory (${EXTERNAL_DIR}/VulkanMemoryAllocator)
6060
add_subdirectory (${EXTERNAL_DIR}/tlsf)
61+
add_subdirectory (${EXTERNAL_DIR}/CLI11)
6162

6263
set (CMAKE_PREFIX_PATH
6364
${CMAKE_PREFIX_PATH}

Tetragrama/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
3131
set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)$(Configuration)")
3232
endif ()
3333

34+
include(${EXTERNAL_DIR}/externals.cmake)
35+
3436
target_include_directories (${TARGET_NAME}
3537
PRIVATE
3638
.
@@ -54,6 +56,9 @@ target_compile_definitions(${TARGET_NAME}
5456
_UNICODE
5557
)
5658

57-
target_link_libraries(${TARGET_NAME} PRIVATE zEngineLib)
59+
target_link_libraries(${TARGET_NAME} PRIVATE
60+
zEngineLib
61+
imported::External_editorLibs
62+
)
5863

5964
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "zEngineEditor")

Tetragrama/Editor.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <MessageToken.h>
44
#include <Messengers/Messenger.h>
55
#include <fmt/format.h>
6+
#include <nlohmann/json.hpp>
67

78
using namespace ZEngine;
89
using namespace ZEngine::Helpers;
@@ -78,4 +79,66 @@ namespace Tetragrama
7879
{
7980
return m_has_pending_change;
8081
}
82+
83+
void EditorConfiguration::ReadConfig(std::string_view file)
84+
{
85+
std::ifstream f(file.data());
86+
nlohmann::json config = nlohmann::json::parse(f);
87+
std::string root_project_dir = std::filesystem::path(file).parent_path().string();
88+
89+
std::string working_space_path = config["workingSpace"];
90+
if (working_space_path == ".")
91+
{
92+
std::string_view lookup_key("$(workingSpace)");
93+
size_t length = lookup_key.size();
94+
95+
auto& texture_path = config["defaultImportDir"]["textureDir"];
96+
auto& sound_path = config["defaultImportDir"]["soundDir"];
97+
auto& scene_path = config["sceneDir"];
98+
auto& scene_data_path = config["sceneDataDir"];
99+
100+
if (texture_path.get<std::string>().find(lookup_key) != std::string::npos)
101+
{
102+
config["defaultImportDir"]["textureDir"] = texture_path.get<std::string>().replace(texture_path.get<std::string>().find(lookup_key), length, "");
103+
}
104+
105+
if (sound_path.get<std::string>().find(lookup_key) != std::string::npos)
106+
{
107+
config["defaultImportDir"]["soundDir"] = sound_path.get<std::string>().replace(sound_path.get<std::string>().find(lookup_key), length, "");
108+
}
109+
110+
if (scene_path.get<std::string>().find(lookup_key) != std::string::npos)
111+
{
112+
config["sceneDir"] = scene_path.get<std::string>().replace(scene_path.get<std::string>().find(lookup_key), length, "");
113+
}
114+
115+
if (scene_data_path.get<std::string>().find(lookup_key) != std::string::npos)
116+
{
117+
config["sceneDataDir"] = scene_data_path.get<std::string>().replace(scene_data_path.get<std::string>().find(lookup_key), length, "");
118+
}
119+
120+
config["workingSpace"] = root_project_dir;
121+
}
122+
123+
ProjectName = config["projectName"];
124+
WorkingSpacePath = config["workingSpace"];
125+
DefaultImportTexturePath = config["defaultImportDir"]["textureDir"];
126+
DefaultImportSoundPath = config["defaultImportDir"]["soundDir"];
127+
ScenePath = config["sceneDir"];
128+
SceneDataPath = config["sceneDataDir"];
129+
130+
/*
131+
* Retreiving the Active Scene
132+
*/
133+
for (const auto& scene : config["sceneList"])
134+
{
135+
bool is_default = scene["isDefault"].get<bool>();
136+
if (!is_default)
137+
{
138+
continue;
139+
}
140+
ActiveSceneName = scene["name"];
141+
break;
142+
}
143+
}
81144
} // namespace Tetragrama

Tetragrama/Editor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ namespace Tetragrama
5555
std::string SceneDataPath;
5656
std::string ProjectName;
5757
std::string ActiveSceneName;
58+
59+
void ReadConfig(std::string_view file);
5860
};
5961

6062
struct EditorContext : public ZEngine::Helpers::RefCounted

Tetragrama/EntryPoint.cpp

Lines changed: 11 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,26 @@
11
#include <pch.h>
2+
#include <CLI/CLI.hpp>
23
#include "Editor.h"
3-
#include "nlohmann/json.hpp"
44

55
#ifdef ZENGINE_PLATFORM
66

7-
namespace fs = std::filesystem;
8-
9-
static void ConfigureWorkingSpace(nlohmann::json& config, std::string_view ws_path)
10-
{
11-
std::string working_space_path = config["workingSpace"];
12-
if (working_space_path == ".")
13-
{
14-
std::string_view lookup_key("$(workingSpace)");
15-
size_t length = lookup_key.size();
16-
17-
auto& texture_path = config["defaultImportDir"]["textureDir"];
18-
auto& sound_path = config["defaultImportDir"]["soundDir"];
19-
auto& scene_path = config["sceneDir"];
20-
auto& scene_data_path = config["sceneDataDir"];
21-
22-
if (texture_path.get<std::string>().find(lookup_key) != std::string::npos)
23-
{
24-
config["defaultImportDir"]["textureDir"] = texture_path.get<std::string>().replace(texture_path.get<std::string>().find(lookup_key), length, "");
25-
}
26-
27-
if (sound_path.get<std::string>().find(lookup_key) != std::string::npos)
28-
{
29-
config["defaultImportDir"]["soundDir"] = sound_path.get<std::string>().replace(sound_path.get<std::string>().find(lookup_key), length, "");
30-
}
31-
32-
if (scene_path.get<std::string>().find(lookup_key) != std::string::npos)
33-
{
34-
config["sceneDir"] = scene_path.get<std::string>().replace(scene_path.get<std::string>().find(lookup_key), length, "");
35-
}
36-
37-
if (scene_data_path.get<std::string>().find(lookup_key) != std::string::npos)
38-
{
39-
config["sceneDataDir"] = scene_data_path.get<std::string>().replace(scene_data_path.get<std::string>().find(lookup_key), length, "");
40-
}
41-
42-
config["workingSpace"] = ws_path;
43-
}
44-
}
45-
467
int applicationEntryPoint(int argc, char* argv[])
478
{
48-
std::string_view project_config_json;
49-
50-
if (argc == 1)
51-
{
52-
return -2; // Missing arguments
53-
}
54-
else if (argc > 1)
55-
{
56-
std::string_view config_file_arg = "--projectConfigFile";
57-
for (int i = 1; i < argc; ++i)
58-
{
59-
if (config_file_arg == std::string_view(argv[i]))
60-
{
61-
project_config_json = argv[i + 1];
62-
}
63-
}
64-
}
9+
CLI::App app{"ZEngine Editor"};
10+
argv = app.ensure_utf8(argv);
6511

66-
try
67-
{
68-
if (project_config_json.empty())
69-
{
70-
return -2;
71-
}
12+
std::string json_config_file{""};
13+
app.add_option("--projectConfigFile", json_config_file, "The project config file");
7214

73-
std::ifstream f(project_config_json.data());
74-
nlohmann::json config = nlohmann::json::parse(f);
75-
std::string root_project_dir = std::filesystem::path(project_config_json).parent_path().string();
76-
ConfigureWorkingSpace(config, root_project_dir);
15+
CLI11_PARSE(app, argc, argv);
7716

78-
Tetragrama::EditorConfiguration editor_config = {};
79-
editor_config.ProjectName = config["projectName"];
80-
editor_config.WorkingSpacePath = config["workingSpace"];
81-
editor_config.DefaultImportTexturePath = config["defaultImportDir"]["textureDir"];
82-
editor_config.DefaultImportSoundPath = config["defaultImportDir"]["soundDir"];
83-
editor_config.ScenePath = config["sceneDir"];
84-
editor_config.SceneDataPath = config["sceneDataDir"];
17+
Tetragrama::EditorConfiguration editor_config = {};
18+
editor_config.ReadConfig(json_config_file);
8519

86-
/*
87-
* Retreiving the Active Scene
88-
*/
89-
for (const auto& scene : config["sceneList"])
90-
{
91-
bool is_default = scene["isDefault"].get<bool>();
92-
if (!is_default)
93-
{
94-
continue;
95-
}
96-
editor_config.ActiveSceneName = scene["name"];
97-
break;
98-
}
20+
auto editor = ZEngine::Helpers::CreateRef<Tetragrama::Editor>(editor_config);
21+
editor->Initialize();
22+
editor->Run();
9923

100-
auto editor = ZEngine::Helpers::CreateRef<Tetragrama::Editor>(editor_config);
101-
editor->Initialize();
102-
editor->Run();
103-
}
104-
catch (const std::exception& e)
105-
{
106-
}
10724
return 0;
10825
}
10926

__externals/CLI11

Submodule CLI11 added at f75fd22

__externals/externals.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(EXTERNAL_INCLUDE_DIRS
1818
${EXTERNAL_DIR}/SPIRV-Cross
1919
${EXTERNAL_DIR}/VulkanMemoryAllocator
2020
${EXTERNAL_DIR}/nlohmann_json/single_include
21+
${EXTERNAL_DIR}/CLI11/include
2122
)
2223

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

3334
add_library (imported::External_libs INTERFACE IMPORTED)
35+
add_library(imported::External_editorLibs INTERFACE IMPORTED)
36+
37+
38+
target_link_libraries(imported::External_editorLibs INTERFACE
39+
CLI11::CLI11
40+
)
3441

3542
target_link_libraries(imported::External_libs INTERFACE
3643
vulkan

0 commit comments

Comments
 (0)