Unravel Engine C++ Reference
Loading...
Searching...
No Matches
project_editor_settings.cpp
Go to the documentation of this file.
2
3#include <fstream>
7
8#include <logging/logging.h>
9
10namespace unravel
11{
12
14{
15 entt::meta_factory<project_editor_settings::scene_setup>{}
16 .type("scene_setup"_hs)
18 entt::attribute{"name", "scene_setup"},
19 entt::attribute{"pretty_name", "Scene Setup"},
20 })
21 .data<&project_editor_settings::scene_setup::opened_scene>("opened_scene"_hs)
23 entt::attribute{"name", "opened_scene"},
24 entt::attribute{"pretty_name", "Opened Scene"},
25 entt::attribute{"tooltip", "The scene that was last opened in the editor."},
26 });
27}
28
30{
31 try_save(ar, ser20::make_nvp("opened_scene", obj.opened_scene));
32}
33
35{
36 try_load(ar, ser20::make_nvp("opened_scene", obj.opened_scene));
37}
38
40{
41 entt::meta_factory<project_editor_settings>{}
42 .type("project_editor_settings"_hs)
44 entt::attribute{"name", "project_editor_settings"},
45 entt::attribute{"category", "EDITOR"},
46 entt::attribute{"pretty_name", "Project Editor Settings"},
47 })
48 .data<&project_editor_settings::scene>("scene"_hs)
50 entt::attribute{"name", "scene"},
51 entt::attribute{"pretty_name", "Scene"},
52 });
53}
54
56{
57 try_save(ar, ser20::make_nvp("scene", obj.scene));
58}
61
63{
64 try_load(ar, ser20::make_nvp("scene", obj.scene));
65}
68
69void save_to_file(const std::string& absolute_path, const project_editor_settings& obj)
70{
71 std::ofstream stream(absolute_path);
72 if(stream.good())
73 {
74 try
75 {
76 auto ar = ser20::create_oarchive_associative(stream);
77 try_save(ar, ser20::make_nvp("settings", obj));
78 }
79 catch(const std::exception& e)
80 {
81 APPLOG_WARNING("Failed to save project editor settings {}", absolute_path);
82 }
83 }
84}
85
86auto load_from_file(const std::string& absolute_path, project_editor_settings& obj) -> bool
87{
88 std::ifstream stream(absolute_path);
89 if(stream.good())
90 {
91 try
92 {
93 auto ar = ser20::create_iarchive_associative(stream);
94 return try_load(ar, ser20::make_nvp("settings", obj));
95 }
96 catch(const std::exception& e)
97 {
98 APPLOG_WARNING("Failed to load project editor settings {}", absolute_path);
99 }
100 }
101
102 return false;
103}
104
105} // 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 load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const 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