SHADE_Y3/SHADE_Engine/src/Serialization/SHSerialization.h

62 lines
2.3 KiB
C++

#pragma once
#include "SH_API.h"
#include <string>
#include "ECS_Base/SHECSMacros.h"
#include <Assets/SHAssetMacros.h>
#include <unordered_map>
namespace YAML
{
class Emitter;
class Node;
}
namespace SHADE
{
class SHSceneNode;
constexpr const char* ComponentsNode = "Components";
constexpr const char* EntityNameNode = "Name";
constexpr const char* EIDNode = "EID";
constexpr const char* IsActiveNode = "IsActive";
constexpr const char* NumberOfChildrenNode = "NumberOfChildren";
constexpr const char* ScriptsNode = "Scripts";
constexpr const char* PrefabID = "PrefabID";
class SH_API SHSerialization
{
public:
//Original EID : New EID
using CreatedEntitiesList = std::unordered_map<EntityID, EntityID>;
static bool SerializeSceneToFile(AssetID const& sceneAssetID);
static std::string SerializeSceneToString();
static void SerializeSceneToEmitter(YAML::Emitter& out);
static std::string DeserializeSceneFromFile(AssetID const& sceneAssetID) noexcept;
static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out, bool isPrefab = false, EntityID* entityIndex = nullptr);
static std::string SerializeEntitiesToString(std::vector<EntityID> const& entities) noexcept;
static std::string SerializeEntityToString(EntityID eid) noexcept;
//static void SerializeEntityToFile(std::filesystem::path const& path);
static YAML::Node SerializeEntityToNode(SHSceneNode* sceneNode, bool isPrefab = false, EntityID* entityIndex = nullptr);
static CreatedEntitiesList DeserializeEntitiesFromString(std::string const& data, EntityID const& parentEID = MAX_EID) noexcept;
static std::vector<ComponentTypeID> GetComponentIDList(YAML::Node const& componentsNode);
static void LoadAssetsFromAssetQueue(std::unordered_map<AssetID, AssetType>& assetQueue);
static std::string ResolveSerializedEntityIndices(std::string serializedEntityData, CreatedEntitiesList const& createdEntities) noexcept;
private:
//static void ResolveSerializedEntityID(YAML::Emitter& out, YAML::iterator& it, YAML::Node const& entityNode, CreatedEntitiesList const& createdEntities);
static void InitializeEntity(YAML::Node const& entityNode, EntityID const& eid);
static constexpr std::string_view NewSceneName = "New Scene";
};
}