SHADE_Y3/SHADE_Engine/src/Serialization/SHSerialization.h

61 lines
2.2 KiB
C
Raw Normal View History

2022-09-26 21:08:59 +08:00
#pragma once
#include "SH_API.h"
#include <string>
#include "ECS_Base/SHECSMacros.h"
2022-11-04 14:44:18 +08:00
#include <Assets/SHAssetMacros.h>
#include <unordered_map>
2022-09-27 21:06:25 +08:00
2022-09-26 21:08:59 +08:00
namespace YAML
{
class Emitter;
class Node;
}
namespace SHADE
{
class SHSceneNode;
2022-09-27 21:06:25 +08:00
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";
2023-02-24 20:34:49 +08:00
constexpr const char* PrefabID = "PrefabID";
2022-09-27 21:06:25 +08:00
class SH_API SHSerialization
2022-09-26 21:08:59 +08:00
{
public:
//Original EID : New EID
using CreatedEntitiesList = std::unordered_map<EntityID, EntityID>;
2022-11-04 14:44:18 +08:00
static bool SerializeSceneToFile(AssetID const& sceneAssetID);
2022-09-26 21:08:59 +08:00
static std::string SerializeSceneToString();
static void SerializeSceneToEmitter(YAML::Emitter& out);
2022-10-19 17:23:25 +08:00
2022-11-04 14:44:18 +08:00
static std::string DeserializeSceneFromFile(AssetID const& sceneAssetID) noexcept;
2022-09-27 21:06:25 +08:00
2023-02-24 20:34:49 +08:00
static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out, bool isPrefab = false, EntityID* entityIndex = nullptr);
2022-10-19 17:23:25 +08:00
2023-02-24 20:34:49 +08:00
static std::string SerializeEntitiesToString(std::vector<EntityID> const& entities, bool isPrefab = false) noexcept;
//static void SerializeEntityToFile(std::filesystem::path const& path);
2023-02-24 20:34:49 +08:00
static YAML::Node SerializeEntityToNode(SHSceneNode* sceneNode, bool isPrefab = false, EntityID* entityIndex = nullptr);
2022-09-27 21:06:25 +08:00
static CreatedEntitiesList DeserializeEntitiesFromString(std::string const& data, EntityID const& parentEID = MAX_EID) noexcept;
2022-10-19 17:23:25 +08:00
2022-09-27 21:06:25 +08:00
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;
2022-09-27 21:06:25 +08:00
private:
//static void ResolveSerializedEntityID(YAML::Emitter& out, YAML::iterator& it, YAML::Node const& entityNode, CreatedEntitiesList const& createdEntities);
2022-10-01 23:43:00 +08:00
static void InitializeEntity(YAML::Node const& entityNode, EntityID const& eid);
2022-11-04 14:44:18 +08:00
static constexpr std::string_view NewSceneName = "New Scene";
2022-09-26 23:51:20 +08:00
};
2022-09-26 21:08:59 +08:00
}