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 entt::meta_factory<editor_settings>{}
115 .type("editor_settings"_hs)
117 entt::attribute{"name", "editor_settings"},
118 entt::attribute{"category", "EDITOR"},
119 entt::attribute{"pretty_name", "Editor Settings"},
120 })
121 .data<&editor_settings::debugger>("debugger"_hs)
123 entt::attribute{"name", "debugger"},
124 entt::attribute{"pretty_name", "Debugger"},
125 entt::attribute{"tooltip", "Missing..."},
126 })
127 .data<&editor_settings::external_tools>("external_tools"_hs)
129 entt::attribute{"name", "external_tools"},
130 entt::attribute{"pretty_name", "External Tools"},
131 entt::attribute{"tooltip", "Missing..."},
132 });
133}
134
136{
137 try_save(ar, ser20::make_nvp("debugger", obj.debugger));
138 try_save(ar, ser20::make_nvp("external_tools", obj.external_tools));
139 try_save(ar, ser20::make_nvp("projects", obj.projects));
140}
143
145{
146 try_load(ar, ser20::make_nvp("debugger", obj.debugger));
147 try_load(ar, ser20::make_nvp("external_tools", obj.external_tools));
148 try_load(ar, ser20::make_nvp("projects", obj.projects));
149}
152
153void save_to_file(const std::string& absolute_path, const editor_settings& obj)
154{
155 std::ofstream stream(absolute_path);
156 if(stream.good())
157 {
158 try
159 {
160 auto ar = ser20::create_oarchive_associative(stream);
161 try_save(ar, ser20::make_nvp("settings", obj));
162 }
163 catch(const ser20::Exception& e)
164 {
165 APPLOG_WARNING("Failed to load config file {}", absolute_path);
166 }
167 }
168}
169
170void save_to_file_bin(const std::string& absolute_path, const editor_settings& obj)
171{
172 std::ofstream stream(absolute_path, std::ios::binary);
173 if(stream.good())
174 {
175 try
176 {
177 ser20::oarchive_binary_t ar(stream);
178 try_save(ar, ser20::make_nvp("settings", obj));
179 }
180 catch(const ser20::Exception& e)
181 {
182 APPLOG_WARNING("Failed to load config file {}", absolute_path);
183 }
184 }
185}
186
187auto load_from_file(const std::string& absolute_path, editor_settings& obj) -> bool
188{
189 std::ifstream stream(absolute_path);
190 if(stream.good())
191 {
192 try
193 {
194 auto ar = ser20::create_iarchive_associative(stream);
195 return try_load(ar, ser20::make_nvp("settings", obj));
196 }
197 catch(const ser20::Exception& e)
198 {
199 APPLOG_WARNING("Failed to load config file {}", absolute_path);
200 }
201 }
202
203 return false;
204}
205
206auto load_from_file_bin(const std::string& absolute_path, editor_settings& obj) -> bool
207{
208 std::ifstream stream(absolute_path, std::ios::binary);
209 if(stream.good())
210 {
211 try
212 {
213 ser20::iarchive_binary_t ar(stream);
214 return try_load(ar, ser20::make_nvp("settings", obj));
215 }
216 catch(const ser20::Exception& e)
217 {
218 APPLOG_WARNING("Failed to load config file {}", absolute_path);
219 }
220 }
221
222 return false;
223}
224} // namespace unravel
#define APPLOG_WARNING(...)
Definition logging.h:19
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:133
#define REFLECT_INLINE(cls)
Definition reflection.h:128
#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