Finality Engine
Loading...
Searching...
No Matches
Prefab.h
Go to the documentation of this file.
1
6#pragma once
7#include <Finality.h>
8#include <set>
9
10namespace FINALITY
11{
12 inline bool SavePrefab(Scene& source, entt::entity root, const std::filesystem::path& path)
13 {
14 if (!source.GetRegistry().valid(root)) return false;
15 EmptyScene copy;
16 if (!copy.InstantiateHierarchy(source, root).IsValid()) return false;
17 std::filesystem::create_directories(path.parent_path());
18 SceneSerializer(copy, path.stem().string()).Serialize(path.string());
20 return std::filesystem::is_regular_file(path);
21 }
22
23 inline Entity InstantiatePrefab(Scene& destination, const std::filesystem::path& path)
24 {
25 EmptyScene source;
26 if (!SceneSerializer(source).DeSerialize(path.string())) return {};
27 for (auto entity : source.GetRegistry().view<RelationshipComponent>())
28 if (source.GetRegistry().get<RelationshipComponent>(entity).Parent == entt::null)
29 return destination.InstantiateHierarchy(source, entity);
30 return {};
31 }
32}
Provides a scene-bound handle for component and hierarchy operations.
Definition Entity.h:34
bool IsValid() const
Checks that the scene still exists and the entity handle is valid.
Definition Entity.h:67
Owns entities and dispatches script simulation.
Definition Scene.h:36
Entity InstantiateHierarchy(const Scene &source, entt::entity handle)
const entt::registry & GetRegistry() const
Definition Scene.h:82
SceneSerializer(const Scene &scene, const std::string &name="Untitled Scene")
Entity InstantiatePrefab(Scene &destination, const std::filesystem::path &path)
Definition Prefab.h:23
bool SavePrefab(Scene &source, entt::entity root, const std::filesystem::path &path)
Definition Prefab.h:12
Intrusive hierarchy links using EnTT handles; entt::null denotes a missing link.
Definition Entity.h:84