6#include "hellfire/ecs/ComponentRegistry.h"
7#include "hellfire/scene/Scene.h"
8#include "hellfire/serializers/Serializer.h"
16 if (scene ==
nullptr)
return false;
18 nlohmann::ordered_json j;
21 j[
"entities"] = nlohmann::ordered_json::array();
23 for (
const EntityID root_id : scene->get_root_entities()) {
24 serialize_entity_recursive(*scene, root_id, j[
"entities"]);
39 for (
const auto& entity_json : j.at(
"entities")) {
40 create_entity_recursive(*scene, entity_json, INVALID_ENTITY, id_remap);
43 if (j.contains(
"default_camera")) {
44 EntityID old_id = j.at(
"default_camera");
45 if (id_remap.contains(old_id)) {
61 nlohmann::ordered_json entity_json;
62 entity_json[
"id"] = id;
65 entity_json[
"children"] = nlohmann::json::array();
67 for (EntityID child_id : scene.get_children(id)) {
68 serialize_entity_recursive(scene, child_id, entity_json[
"children"]);
71 out.push_back(entity_json);
75 EntityID old_id = entity_json.at(
"id");
77 id_remap[old_id] = new_id;
84 if (entity_json.contains(
"components")) {
88 if (entity_json.contains(
"children")) {
89 for (
const auto& child_json : entity_json.at(
"children")) {
90 create_entity_recursive(scene, child_json, new_id, id_remap);
static constexpr hellfire::EntityID INVALID_ENTITY
std::shared_ptr< Mesh > get_mesh(AssetID id)
std::shared_ptr< Material > get_material(AssetID id)
static ComponentRegistry & instance()
const std::string & get_name() const
void resolve(Scene &scene)
void resolve_entity(Entity &entity)
SceneAssetResolver(AssetManager &assets)
void destroy_scene(Scene *scene)
CameraComponent * get_active_camera() const
void save_current_scene()
bool save_scene(Scene *scene)
Scene * create_scene(const std::string &name="GameScene")
Scene * load_scene(const std::filesystem::path &filename)
std::optional< AssetID > get_scene_asset_id(Scene *scene) const
void set_active_camera(EntityID camera) const
std::optional< AssetID > get_active_scene_asset_id() const
SceneActivatedCallback scene_activated_callback_
Scene * get_active_scene() const
bool save_scene_as(const std::string &filename, Scene *scene)
std::vector< Scene * > scenes_
std::vector< Scene * > get_scenes()
std::unordered_map< Scene *, AssetID > scene_asset_ids_
EntityID find_entity_by_name(const std::string &name)
std::vector< EntityID > get_camera_entities() const
Scene * load_scene(AssetID asset_id, const std::filesystem::path &filename)
void update(float delta_time)
Manages a collection of entities and their hierarchical relationships.
Entity * find_entity_by_name(const std::string &name)
Finds an entity by its name.
Scene(std::string name="Unnamed")
Constructs a new Scene with an optional name.
const Entity * get_entity(EntityID id) const
Retrieves an entity by its ID (const version)
void set_playing(bool active)
const std::string & get_name() const
virtual void update(float delta_time)
Updates all entities in the scene.
void set_default_camera(EntityID camera_id)
Sets the default camera for the scene.
CameraComponent * get_default_camera() const
void set_parent(EntityID child_id, EntityID parent_id)
Sets the parent of an entity.
void set_source_filename(const std::filesystem::path &filename)
const std::filesystem::path & get_source_filename() const
Entity * get_entity(EntityID id)
Retrieves an entity by its ID.
EntityID get_default_camera_entity_id() const
void set_name(const std::string &name)
EntityID create_entity(const std::string &name="GameObject")
Creates a new entity in the scene.
void register_all_components()
constexpr AssetID INVALID_ASSET_ID
static void create_entity_recursive(Scene &scene, const nlohmann::json &entity_json, EntityID parent_id, Remap &id_remap)
static bool serialize(std::ostream &output, const Scene *scene)
static bool deserialize(std::istream &input, Scene *scene)
static void serialize_entity_recursive(const Scene &scene, EntityID id, nlohmann::ordered_json &out)