9#include <glm/gtc/matrix_transform.hpp>
11#include "imgui_internal.h"
13#include "hellfire/assets/AssetManager.h"
14#include "hellfire/assets/importers/AssetImportManager.h"
15#include "hellfire/graphics/renderer/Renderer.h"
16#include "hellfire/scene/Scene.h"
17#include "hellfire/serializers/ProjectSerializer.h"
18#include "hellfire/utilities/ServiceLocator.h"
22 metadata_.name = name;
23 metadata_.version =
"1.0.0";
24 metadata_.engine_version =
"0.1.0";
25 metadata_.created_at = get_current_timestamp();
26 metadata_.last_opened = metadata_.created_at;
27 metadata_.default_scene =
"assets/default_scene.hfscene";
28 metadata_.renderer_settings =
"settings/renderer.json";
37 std::unique_ptr<Project>
Project::create(
const std::string &name,
const std::filesystem::path &location) {
47 auto project = std::make_unique<
Project>(metadata);
48 project->project_root_path_ = location / name;
49 project->project_file_path_ = project->project_root_path_ /
"project.hfproj";
51 project->create_directory_structure();
53 if (!project->save()) {
54 std::cerr <<
"Failed to save new project" << std::endl;
61 std::unique_ptr<Project>
Project::load_data(
const std::filesystem::path &project_file) {
62 if (!exists(project_file)) {
63 std::cerr <<
"ERROR::PROJECT::LOAD:: Project file doesnt exist at " << project_file.string() << std::endl;
68 std::ifstream file(project_file);
69 if (!file.is_open()) {
70 std::cerr <<
"ERROR::PROJECT::LOAD:: Failed to open project file" << std::endl;
76 std::cerr <<
"Failed to deserialize project metadata" << std::endl;
81 auto project = std::make_unique<
Project>(metadata);
82 project->project_file_path_ = project_file;
83 project->project_root_path_ = project_file.parent_path();
86 }
catch (
const nlohmann::json::parse_error& e) {
87 std::cerr <<
"ERROR::PROJECT::LOAD:: JSON parse error: " << e.what() << std::endl;
89 catch (
const std::exception &e) {
90 std::cout <<
"ERROR::PROJECT::LOAD:: Exception: " << e.what() << std::endl;
98 metadata_.last_opened = get_current_timestamp();
100 std::ofstream file(project_file_path_);
101 if (!file.is_open())
return false;
104 if (asset_registry_) {
105 asset_registry_->save();
109 if (scene_manager_ && scene_manager_->has_active_scene()) {
110 scene_manager_->save_current_scene();
111 metadata_.last_scene = scene_manager_->get_active_scene_asset_id();
115 return Serializer<ProjectMetadata>::serialize(file, &metadata_);
121 if (scene_manager_) {
122 scene_manager_->clear();
125 if (asset_registry_) {
126 asset_registry_->clear();
168 asset_registry_ = std::make_unique<AssetRegistry>(registry_path, project_root_path_);
169 ServiceLocator::register_service<AssetRegistry>(asset_registry_.get());
170 asset_registry_->register_directory(get_assets_path(),
true);
172 asset_manager_ = std::make_unique<AssetManager>(*asset_registry_.get());
173 ServiceLocator::register_service<AssetManager>(asset_manager_.get());
175 scene_renderer_ = std::make_unique<Renderer>();
176 scene_renderer_->init();
177 ServiceLocator::register_service<Renderer>(scene_renderer_.get());
179 AssetImportManager import_manager(*asset_registry_, *asset_manager_, project_root_path_);
181 asset_registry_->save();
183 scene_manager_ = std::make_unique<SceneManager>();
184 ServiceLocator::register_service<SceneManager>(scene_manager_.get());
187 if (metadata_.last_scene) {
188 if (
auto asset_info = asset_registry_->get_asset(metadata_.last_scene.value())) {
189 auto path = asset_registry_->get_absolute_path(asset_info->uuid);
190 auto scene = scene_manager_->load_scene(asset_info->uuid, path);
191 scene_manager_->set_active_scene(scene);
200 scene_manager_.reset();
201 asset_registry_.reset();
205 auto now = std::chrono::system_clock::now();
206 auto time_t_now = std::chrono::system_clock::to_time_t(now);
207 std::stringstream ss;
208 ss << std::put_time(std::gmtime(&time_t_now),
"%Y-%m-%dT%H:%M:%SZ");
void import_all_pending()
Import all unprocessed assets in registry.
Registry for storing assets.
std::filesystem::path get_assets_path() const
std::filesystem::path get_settings_path() const
void initialize_default_assets()
Project(const ProjectMetadata &metadata)
void create_directory_structure() const
std::filesystem::path project_root_path_
Project(const std::string &name)
void initialize_managers()
std::filesystem::path get_scenes_path() const
std::filesystem::path get_project_root() const
static std::string get_current_timestamp()