|
1 | 1 | #include <pch.h> |
| 2 | +#include <CLI/CLI.hpp> |
2 | 3 | #include "Editor.h" |
3 | | -#include "nlohmann/json.hpp" |
4 | 4 |
|
5 | 5 | #ifdef ZENGINE_PLATFORM |
6 | 6 |
|
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 | | - |
46 | 7 | int applicationEntryPoint(int argc, char* argv[]) |
47 | 8 | { |
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); |
65 | 11 |
|
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"); |
72 | 14 |
|
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); |
77 | 16 |
|
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); |
85 | 19 |
|
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(); |
99 | 23 |
|
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 | | - } |
107 | 24 | return 0; |
108 | 25 | } |
109 | 26 |
|
|
0 commit comments