Unravel Engine C++ Reference
Loading...
Searching...
No Matches
settings.cpp
Go to the documentation of this file.
1#include "settings.hpp"
2
3#include <fstream>
6
7#include "logging/logging.h"
10
11namespace unravel
12{
13
15{
16 std::vector<std::string> recent_projects;
17 recent_projects.reserve(obj.recent_projects.size());
18 for(const auto& prj : obj.recent_projects)
19 {
20 recent_projects.emplace_back(prj.generic_string());
21 }
22 try_save(ar, ser20::make_nvp("recent_projects", recent_projects));
23}
24
26{
27 std::vector<std::string> recent_projects;
28
29 try_load(ar, ser20::make_nvp("recent_projects", recent_projects));
30
31 obj.recent_projects.reserve(recent_projects.size());
32 for(const auto& prj : recent_projects)
33 {
34 obj.recent_projects.emplace_back(fs::path(prj));
35 }
36}
37
39{
40 entt::meta_factory<editor_settings::external_tools_settings>{}
41 .type("external_tools_settings"_hs)
43 entt::attribute{"name", "external_tools_settings"},
44 entt::attribute{"category", "EDITOR"},
45 entt::attribute{"pretty_name", "External Tools"},
46 })
47 .data<&editor_settings::external_tools_settings::vscode_executable>("vscode_executable"_hs)
49 entt::attribute{"name", "vscode_executable"},
50 entt::attribute{"pretty_name", "Visual Studio Code"},
51 entt::attribute{"tooltip", "Full path to executable."},
52 entt::attribute{"type", "file"},
53 });
54}
55
57{
58 try_save(ar, ser20::make_nvp("vscode_executable", obj.vscode_executable.generic_string()));
59}
60
62{
63 std::string vscode_executable;
64 if(try_load(ar, ser20::make_nvp("vscode_executable", vscode_executable)))
65 {
66 obj.vscode_executable = vscode_executable;
67 }
68}
69
71{
72 entt::meta_factory<editor_settings::debugger_settings>{}
73 .type("debugger_settings"_hs)
75 entt::attribute{"name", "debugger_settings"},
76 entt::attribute{"category", "EDITOR"},
77 entt::attribute{"pretty_name", "Debugger"},
78 })
79 .data<&editor_settings::debugger_settings::ip>("ip"_hs)
81 entt::attribute{"name", "ip"},
82 entt::attribute{"pretty_name", "Ip Address"},
83 entt::attribute{"tooltip", "Ip address to await connections. Default(127.0.0.1)"},
84 })
85 .data<&editor_settings::debugger_settings::port>("port"_hs)
87 entt::attribute{"name", "port"},
88 entt::attribute{"pretty_name", "Port"},
89 entt::attribute{"tooltip", "Port to await connections. Default (55555)"},
90 })
91 .data<&editor_settings::debugger_settings::loglevel>("loglevel"_hs)
93 entt::attribute{"name", "loglevel"},
94 entt::attribute{"pretty_name", "Log Level"},
95 });
96}
97
99{
100 try_save(ar, ser20::make_nvp("ip", obj.ip));
101 try_save(ar, ser20::make_nvp("port", obj.port));
102 try_save(ar, ser20::make_nvp("loglevel", obj.loglevel));
103}
104
106{
107 try_load(ar, ser20::make_nvp("ip", obj.ip));
108 try_load(ar, ser20::make_nvp("port", obj.port));
109 try_load(ar, ser20::make_nvp("loglevel", obj.loglevel));
110}
111
113{
114 auto always_readonly = entt::property_predicate<bool>(
115 [](const entt::meta_any&)
116 {
117 return true;
118 });
119
120 entt::meta_factory<editor_settings::scripting_settings>{}
121 .type("scripting_settings"_hs)
123 entt::attribute{"name", "scripting_settings"},
124 entt::attribute{"category", "EDITOR"},
125 entt::attribute{"pretty_name", "Scripting"},
126 })
127 .data<&editor_settings::scripting_settings::reload_app_domain>("reload_app_domain"_hs)
129 entt::attribute{"name", "reload_app_domain"},
130 entt::attribute{"pretty_name", "Reload App Domain"},
131 entt::attribute{"tooltip", "Always reloads the app domain on play-mode changes and script recompile."},
132 entt::attribute{"readonly_predicate", always_readonly},
133 })
134 .data<&editor_settings::scripting_settings::reload_engine_domain>("reload_engine_domain"_hs)
136 entt::attribute{"name", "reload_engine_domain"},
137 entt::attribute{"pretty_name", "Reload Engine Domain"},
138 entt::attribute{"tooltip",
139 "Also reload the engine domain on play-mode changes and script recompile. "
140 "Useful when iterating on engine C# scripts."},
141 });
142}
143
145{
146 try_save(ar, ser20::make_nvp("reload_app_domain", obj.reload_app_domain));
147 try_save(ar, ser20::make_nvp("reload_engine_domain", obj.reload_engine_domain));
148}
149
151{
152 try_load(ar, ser20::make_nvp("reload_app_domain", obj.reload_app_domain));
153 try_load(ar, ser20::make_nvp("reload_engine_domain", obj.reload_engine_domain));
154 obj.reload_app_domain = true;
155}
156
158{
159 entt::meta_factory<editor_settings>{}
160 .type("editor_settings"_hs)
162 entt::attribute{"name", "editor_settings"},
163 entt::attribute{"category", "EDITOR"},
164 entt::attribute{"pretty_name", "Editor Settings"},
165 })
166 .data<&editor_settings::debugger>("debugger"_hs)
168 entt::attribute{"name", "debugger"},
169 entt::attribute{"pretty_name", "Debugger"},
170 entt::attribute{"tooltip", "Missing..."},
171 })
172 .data<&editor_settings::external_tools>("external_tools"_hs)
174 entt::attribute{"name", "external_tools"},
175 entt::attribute{"pretty_name", "External Tools"},
176 entt::attribute{"tooltip", "Missing..."},
177 })
178 .data<&editor_settings::scripting>("scripting"_hs)
180 entt::attribute{"name", "scripting"},
181 entt::attribute{"pretty_name", "Scripting"},
182 entt::attribute{"tooltip", "Script domain reload behaviour."},
183 });
184}
185
187{
188 try_save(ar, ser20::make_nvp("debugger", obj.debugger));
189 try_save(ar, ser20::make_nvp("external_tools", obj.external_tools));
190 try_save(ar, ser20::make_nvp("scripting", obj.scripting));
191 try_save(ar, ser20::make_nvp("projects", obj.projects));
192}
195
197{
198 try_load(ar, ser20::make_nvp("debugger", obj.debugger));
199 try_load(ar, ser20::make_nvp("external_tools", obj.external_tools));
200 try_load(ar, ser20::make_nvp("scripting", obj.scripting));
201 try_load(ar, ser20::make_nvp("projects", obj.projects));
202}
205
206void save_to_file(const std::string& absolute_path, const editor_settings& obj)
207{
208 std::ofstream stream(absolute_path);
209 if(stream.good())
210 {
211 try
212 {
213 auto ar = ser20::create_oarchive_associative(stream);
214 try_save(ar, ser20::make_nvp("settings", obj));
215 }
216 catch(const std::exception& e)
217 {
218 APPLOG_WARNING("Failed to load config file {}", absolute_path);
219 }
220 }
221}
222
223void save_to_file_bin(const std::string& absolute_path, const editor_settings& obj)
224{
225 std::ofstream stream(absolute_path, std::ios::binary);
226 if(stream.good())
227 {
228 try
229 {
230 ser20::oarchive_binary_t ar(stream);
231 try_save(ar, ser20::make_nvp("settings", obj));
232 }
233 catch(const std::exception& e)
234 {
235 APPLOG_WARNING("Failed to load config file {}", absolute_path);
236 }
237 }
238}
239
240auto load_from_file(const std::string& absolute_path, editor_settings& obj) -> bool
241{
242 std::ifstream stream(absolute_path);
243 if(stream.good())
244 {
245 try
246 {
247 auto ar = ser20::create_iarchive_associative(stream);
248 return try_load(ar, ser20::make_nvp("settings", obj));
249 }
250 catch(const std::exception& e)
251 {
252 APPLOG_WARNING("Failed to load config file {}", absolute_path);
253 }
254 }
255
256 return false;
257}
258
259auto load_from_file_bin(const std::string& absolute_path, editor_settings& obj) -> bool
260{
261 std::ifstream stream(absolute_path, std::ios::binary);
262 if(stream.good())
263 {
264 try
265 {
266 ser20::iarchive_binary_t ar(stream);
267 return try_load(ar, ser20::make_nvp("settings", obj));
268 }
269 catch(const std::exception& e)
270 {
271 APPLOG_WARNING("Failed to load config file {}", absolute_path);
272 }
273 }
274
275 return false;
276}
277} // namespace unravel
#define APPLOG_WARNING(...)
Definition logging.h:19
auto property_predicate(property_predicate_t< T > predicate) -> property_predicate_t< T >
Definition reflection.h:89
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto create_oarchive_associative(std::ostream &stream)
BinaryInputArchive iarchive_binary_t
auto create_iarchive_associative(std::istream &stream)
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT(cls)
Definition reflection.h:149
#define REFLECT_INLINE(cls)
Definition reflection.h:144
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
#define LOAD_INLINE(cls)
#define SAVE_INLINE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool