Loading...
Searching...
No Matches
ProjectSerializer.h
Go to the documentation of this file.
1//
2// Created by denzel on 06/12/2025.
3//
4
5#pragma once
6#include "hellfire/serializers/Serializer.h"
7#include "hellfire/core/Project.h"
8
9namespace hellfire {
10 template<>
12 static bool serialize(std::ostream &output, const ProjectMetadata *obj) {
13 if (!obj) return false;
14
15 nlohmann::json j = {
16 {"name", obj->name},
17 {"version", obj->version},
18 {"engine_version", obj->engine_version},
19 {"created", obj->created_at},
20 {"last_opened", obj->last_opened},
21 {
22 "settings", {
23 {"default_scene", obj->default_scene.string()},
24 {"renderer_settings", obj->renderer_settings.string()}
25 }
26 }
27 };
28
29 if (obj->last_scene.has_value()) {
30 j["last_scene"] = obj->last_scene.value();
31 }
32
33 output << j.dump(2);
34 return output.good();
35 }
36
37 static bool deserialize(std::istream &input, ProjectMetadata *obj) {
38 try {
39 if (!obj) return false;
40
41 nlohmann::json j;
42 input >> j;
43
44 obj->name = j.at("name").get<std::string>();
45 obj->version = j.value("version", "1.0.0");
46 obj->engine_version = j.value("engine_version", "");
47 obj->created_at = j.value("created", "");
48 obj->last_opened = j.value("last_opened", "");
49
50 if (j.contains("last_scene")) {
51 obj->last_scene = j["last_scene"].get<AssetID>();
52 }
53
54 if (j.contains("settings")) {
55 const auto& settings = j["settings"];
56 obj->default_scene = settings.value("default_scene", "");
57 obj->renderer_settings = settings.value("renderer_settings", "");
58 }
59
60 return true;
61 } catch (const std::exception& e) {
62 std::cerr << "ProjectMetadata deserialize error: " << e.what() << std::endl;
63 return false;
64 }
65 }
66 };
67}
void import_all_pending()
Import all unprocessed assets in registry.
Registry for storing assets.
const std::string & get_name() const
Definition Project.h:50
std::unique_ptr< AssetManager > asset_manager_
Definition Project.h:62
const ProjectMetadata & get_metadata() const
Definition Project.h:47
ProjectMetadata & get_metadata()
Definition Project.h:48
std::filesystem::path get_assets_path() const
Definition Project.cpp:136
std::filesystem::path get_settings_path() const
Definition Project.cpp:144
AssetRegistry * get_asset_registry() const
Definition Project.h:54
void cleanup_managers()
Definition Project.cpp:196
std::unique_ptr< SceneManager > scene_manager_
Definition Project.h:60
std::vector< std::filesystem::path > recent_scenes_
Definition Project.h:65
void initialize_default_assets()
Definition Project.cpp:157
static std::unique_ptr< Project > create(const std::string &name, const std::filesystem::path &location)
Definition Project.cpp:37
const std::string & get_version() const
Definition Project.h:51
static std::unique_ptr< Project > load_data(const std::filesystem::path &project_file)
Definition Project.cpp:61
std::unique_ptr< Renderer > scene_renderer_
Definition Project.h:63
std::unique_ptr< AssetRegistry > asset_registry_
Definition Project.h:61
Project(const ProjectMetadata &metadata)
Definition Project.cpp:31
SceneManager * get_scene_manager() const
Definition Project.h:53
ProjectMetadata metadata_
Definition Project.h:56
void create_directory_structure() const
Definition Project.cpp:148
std::filesystem::path project_root_path_
Definition Project.h:57
std::filesystem::path project_file_path_
Definition Project.h:58
Project(const std::string &name)
Definition Project.cpp:21
void initialize_managers()
Definition Project.cpp:161
std::filesystem::path get_scenes_path() const
Definition Project.cpp:140
std::filesystem::path get_project_root() const
Definition Project.cpp:132
static std::string get_current_timestamp()
Definition Project.cpp:204
std::filesystem::path renderer_settings
Definition Project.h:23
std::optional< AssetID > last_scene
Definition Project.h:21
std::string created_at
Definition Project.h:19
std::string last_opened
Definition Project.h:20
std::string engine_version
Definition Project.h:18
std::filesystem::path default_scene
Definition Project.h:22
static bool serialize(std::ostream &output, const ProjectMetadata *obj)
static bool deserialize(std::istream &input, ProjectMetadata *obj)