2022-09-26 21:08:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ECS_Base/Components/SHComponent.h"
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
#include <rttr/registration>
|
|
|
|
|
2022-10-01 23:43:00 +08:00
|
|
|
#include "ECS_Base/Managers/SHComponentManager.h"
|
2022-09-27 07:03:31 +08:00
|
|
|
#include "Math/Vector/SHVec2.h"
|
|
|
|
#include "Math/Vector/SHVec3.h"
|
|
|
|
#include "Math/Vector/SHVec4.h"
|
2022-10-25 08:42:51 +08:00
|
|
|
#include "Physics/Components/SHColliderComponent.h"
|
2022-09-27 07:03:31 +08:00
|
|
|
|
2022-10-25 08:42:51 +08:00
|
|
|
namespace YAML
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
using namespace SHADE;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct convert<SHVec4>
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
static constexpr const char* x = "x";
|
|
|
|
static constexpr const char* y = "y";
|
|
|
|
static constexpr const char* z = "z";
|
|
|
|
static constexpr const char* w = "w";
|
|
|
|
|
|
|
|
static Node encode(SHVec4 const& rhs)
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
Node node;
|
|
|
|
node.SetStyle(EmitterStyle::Flow);
|
|
|
|
node[x] = rhs.x;
|
|
|
|
node[y] = rhs.y;
|
|
|
|
node[z] = rhs.z;
|
|
|
|
node[w] = rhs.w;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
static bool decode(Node const& node, SHVec4& rhs)
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[x])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.x = node[x].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[y])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.y = node[y].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[z])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.z = node[z].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[w])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.w = node[w].as<float>();
|
|
|
|
return true;
|
2022-09-26 21:08:59 +08:00
|
|
|
}
|
2022-10-25 08:42:51 +08:00
|
|
|
};
|
2022-09-26 21:08:59 +08:00
|
|
|
|
2022-10-25 08:42:51 +08:00
|
|
|
template<>
|
|
|
|
struct convert<SHVec3>
|
|
|
|
{
|
|
|
|
static constexpr const char* x = "x";
|
|
|
|
static constexpr const char* y = "y";
|
|
|
|
static constexpr const char* z = "z";
|
|
|
|
|
|
|
|
static Node encode(SHVec3 const& rhs)
|
|
|
|
{
|
|
|
|
Node node;
|
|
|
|
node.SetStyle(EmitterStyle::Flow);
|
|
|
|
node[x] = rhs.x;
|
|
|
|
node[y] = rhs.y;
|
|
|
|
node[z] = rhs.z;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
static bool decode(Node const& node, SHVec3& rhs)
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[x])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.x = node[x].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[y])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.y = node[y].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[z])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.z = node[z].as<float>();
|
|
|
|
return true;
|
2022-09-26 21:08:59 +08:00
|
|
|
}
|
2022-10-25 08:42:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct convert<SHVec2>
|
|
|
|
{
|
|
|
|
static constexpr const char* x = "x";
|
|
|
|
static constexpr const char* y = "y";
|
|
|
|
|
|
|
|
static Node encode(SHVec2 const& rhs)
|
|
|
|
{
|
|
|
|
Node node;
|
|
|
|
node.SetStyle(EmitterStyle::Flow);
|
|
|
|
node[x] = rhs.x;
|
|
|
|
node[y] = rhs.y;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
static bool decode(Node const& node, SHVec2& rhs)
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[x])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.x = node[x].as<float>();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (node[y])
|
2022-10-25 08:42:51 +08:00
|
|
|
rhs.y = node[y].as<float>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2022-10-25 15:09:45 +08:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct convert<SHCollider>
|
|
|
|
{
|
|
|
|
static constexpr const char* IsTrigger = "Is Trigger";
|
|
|
|
|
|
|
|
static constexpr const char* Type = "Type";
|
|
|
|
static constexpr const char* HalfExtents = "Half Extents";
|
|
|
|
static constexpr const char* Radius = "Radius";
|
|
|
|
|
|
|
|
static constexpr const char* Friction = "Friction";
|
|
|
|
static constexpr const char* Bounciness = "Bounciness";
|
|
|
|
static constexpr const char* Density = "Density";
|
|
|
|
static constexpr const char* PositionOffset = "Position Offset";
|
|
|
|
|
|
|
|
static Node encode(SHCollider& rhs)
|
|
|
|
{
|
|
|
|
Node node;
|
|
|
|
node[IsTrigger] = rhs.IsTrigger();
|
|
|
|
|
|
|
|
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>();
|
|
|
|
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
|
|
|
|
SHCollider::Type colliderType = rhs.GetType();
|
|
|
|
|
|
|
|
node[Type] = enumAlign.value_to_name(colliderType).data();
|
|
|
|
|
|
|
|
switch (colliderType)
|
|
|
|
{
|
|
|
|
case SHCollider::Type::BOX:
|
|
|
|
{
|
|
|
|
auto const bb = reinterpret_cast<SHBoundingBox*>(rhs.GetShape());
|
|
|
|
node[HalfExtents] = bb->GetHalfExtents();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHCollider::Type::SPHERE:
|
|
|
|
{
|
|
|
|
auto const bs = reinterpret_cast<SHBoundingSphere*>(rhs.GetShape());
|
|
|
|
node[Radius] = bs->GetRadius();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHCollider::Type::CAPSULE: break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
|
|
|
node[Friction] = rhs.GetFriction();
|
|
|
|
node[Bounciness] = rhs.GetBounciness();
|
|
|
|
node[Density] = rhs.GetDensity();
|
|
|
|
node[PositionOffset] = rhs.GetPositionOffset();
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
static bool decode(Node const& node, SHCollider& rhs)
|
|
|
|
{
|
|
|
|
if (node[IsTrigger])
|
|
|
|
rhs.SetIsTrigger(node[IsTrigger].as<bool>());
|
|
|
|
if (!node[Type])
|
|
|
|
return false;
|
|
|
|
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>();
|
|
|
|
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
|
|
|
|
bool ok;
|
|
|
|
const SHCollider::Type colliderType = enumAlign.name_to_value(node[Type].as<std::string>()).convert<SHCollider::Type>(&ok);
|
|
|
|
if (!ok)
|
|
|
|
return false;
|
|
|
|
switch (colliderType)
|
|
|
|
{
|
|
|
|
case SHCollider::Type::BOX:
|
|
|
|
{
|
|
|
|
if(auto const bb = dynamic_cast<SHBoundingBox*>(rhs.GetShape()); bb)
|
|
|
|
{
|
|
|
|
if (node[HalfExtents])
|
|
|
|
{
|
|
|
|
bb->SetHalfExtents(node[HalfExtents].as<SHVec3>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHCollider::Type::SPHERE:
|
|
|
|
{
|
|
|
|
if(auto const bs = dynamic_cast<SHBoundingSphere*>(rhs.GetShape()); bs)
|
|
|
|
{
|
|
|
|
if (node[Radius])
|
|
|
|
{
|
|
|
|
bs->SetRadius(node[Radius].as<float>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHCollider::Type::CAPSULE: break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
if (node[Friction])
|
|
|
|
rhs.SetFriction(node[Friction].as<float>());
|
|
|
|
if (node[Bounciness])
|
|
|
|
rhs.SetBounciness(rhs.GetBounciness());
|
|
|
|
if (node[Density])
|
|
|
|
rhs.SetDensity(node[Density].as<float>());
|
|
|
|
if (node[PositionOffset])
|
|
|
|
rhs.SetPositionOffset(node[PositionOffset].as<SHVec3>());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct convert<SHColliderComponent>
|
|
|
|
{
|
|
|
|
static constexpr const char* Colliders = "Colliders";
|
|
|
|
static Node encode(SHColliderComponent& rhs)
|
|
|
|
{
|
|
|
|
Node node, collidersNode;
|
|
|
|
auto const& colliders = rhs.GetColliders();
|
|
|
|
int const numColliders = static_cast<int>(colliders.size());
|
|
|
|
for (int i = 0; i < numColliders; ++i)
|
|
|
|
{
|
|
|
|
auto& collider = rhs.GetCollider(i);
|
|
|
|
Node colliderNode = convert<SHCollider>::encode(collider);
|
|
|
|
if (colliderNode.IsDefined())
|
|
|
|
collidersNode[i] = colliderNode;
|
|
|
|
}
|
|
|
|
node[Colliders] = collidersNode;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
static bool decode(Node const& node, SHColliderComponent& rhs)
|
|
|
|
{
|
|
|
|
if(node.IsNull())
|
|
|
|
return false;
|
|
|
|
if (node[Colliders])
|
|
|
|
{
|
|
|
|
int numColliders{};
|
|
|
|
for (auto const& colliderNode : node[Colliders])
|
|
|
|
{
|
|
|
|
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>();
|
|
|
|
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
|
|
|
|
bool ok;
|
|
|
|
const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert<SHCollider>::Type].as<std::string>()).convert<SHCollider::Type>(&ok);
|
|
|
|
if (!ok)
|
|
|
|
return false;
|
|
|
|
switch (colliderType)
|
|
|
|
{
|
|
|
|
case SHCollider::Type::BOX: rhs.AddBoundingBox(); break;
|
|
|
|
case SHCollider::Type::SPHERE: rhs.AddBoundingSphere(); break;
|
|
|
|
case SHCollider::Type::CAPSULE: break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
rhs.GetCollider(numColliders++) = colliderNode.as<SHCollider>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-10-25 08:42:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace SHADE
|
|
|
|
{
|
|
|
|
struct SHSerializationHelper
|
|
|
|
{
|
|
|
|
|
2022-09-26 21:08:59 +08:00
|
|
|
|
|
|
|
static YAML::Node RTTRToNode(const rttr::variant& var)
|
|
|
|
{
|
|
|
|
YAML::Node node;
|
|
|
|
auto varType = var.get_type();
|
2022-10-25 15:09:45 +08:00
|
|
|
if (varType.is_sequential_container())
|
2022-10-25 08:42:51 +08:00
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
for (auto const& elem : var.create_sequential_view())
|
2022-10-25 08:42:51 +08:00
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
node.push_back(RTTRToNode(elem));
|
2022-10-25 08:42:51 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-01 23:43:00 +08:00
|
|
|
if (varType == rttr::type::get<SHVec4>())
|
2022-09-27 07:03:31 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
node = YAML::convert<SHVec4>::encode(var.convert<SHVec4>());
|
2022-09-27 07:03:31 +08:00
|
|
|
}
|
2022-10-01 23:43:00 +08:00
|
|
|
else if (varType == rttr::type::get<SHVec3>())
|
2022-09-27 07:03:31 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
node = YAML::convert<SHVec3>::encode(var.convert<SHVec3>());
|
2022-09-27 07:03:31 +08:00
|
|
|
}
|
2022-10-01 23:43:00 +08:00
|
|
|
else if (varType == rttr::type::get<SHVec2>())
|
2022-09-27 07:03:31 +08:00
|
|
|
{
|
2022-10-25 08:42:51 +08:00
|
|
|
node = YAML::convert<SHVec2>::encode(var.convert<SHVec2>());
|
2022-09-27 07:03:31 +08:00
|
|
|
}
|
2022-10-01 23:43:00 +08:00
|
|
|
else if (varType.is_arithmetic())
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if (varType == rttr::type::get<bool>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_bool();
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<int8_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_int8(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<int16_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_int16(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<int32_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_int32(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<int64_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_int64(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<uint8_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_uint8(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<uint16_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_uint16(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<uint32_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_uint32(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<uint64_t>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_uint64(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<float>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_float(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
else if (varType == rttr::type::get<double>())
|
2022-10-01 23:43:00 +08:00
|
|
|
node = var.to_double(&ok);
|
2022-09-26 21:08:59 +08:00
|
|
|
//else if (varType == rttr::type::get<char>()) //same as uint8_t
|
|
|
|
// node = var.to_uint8();
|
|
|
|
}
|
|
|
|
else if (varType.is_enumeration())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
auto result = var.to_string(&ok);
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
node = var.to_string();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-01 23:43:00 +08:00
|
|
|
ok = false;
|
|
|
|
auto value = var.to_uint64(&ok);
|
|
|
|
if (ok)
|
|
|
|
node = value;
|
|
|
|
else
|
|
|
|
node = YAML::Null;
|
2022-09-26 21:08:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto properties = var.get_type().get_properties();
|
2022-10-25 15:09:45 +08:00
|
|
|
for (auto const& property : properties)
|
2022-09-26 21:08:59 +08:00
|
|
|
{
|
|
|
|
node[property.get_name().data()] = RTTRToNode(property.get_value(var));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-10-25 15:09:45 +08:00
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
2022-10-25 08:42:51 +08:00
|
|
|
static std::string SerializeComponentToString(ComponentType* component)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
|
|
|
static void SerializeComponentToFile(ComponentType* component, std::filesystem::path const& path)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-01 23:43:00 +08:00
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
2022-09-26 21:08:59 +08:00
|
|
|
static YAML::Node SerializeComponentToNode(ComponentType* component)
|
|
|
|
{
|
|
|
|
YAML::Node node{};
|
2022-10-01 23:43:00 +08:00
|
|
|
if (!component)
|
|
|
|
return node;
|
2022-09-26 21:08:59 +08:00
|
|
|
|
|
|
|
auto componentType = rttr::type::get<ComponentType>();
|
2022-09-26 23:51:20 +08:00
|
|
|
node = RTTRToNode(*component);
|
2022-09-26 21:08:59 +08:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
2022-10-01 23:43:00 +08:00
|
|
|
|
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
|
|
|
static void InitializeProperty(ComponentType* component, rttr::property const& prop, YAML::Node const& propertyNode)
|
|
|
|
{
|
|
|
|
auto propType = prop.get_type();
|
|
|
|
if (propType == rttr::type::get<SHVec4>())
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
SHVec4 vec = propertyNode.as<SHVec4>();
|
2022-10-01 23:43:00 +08:00
|
|
|
prop.set_value(component, vec);
|
|
|
|
}
|
|
|
|
else if (propType == rttr::type::get<SHVec3>())
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
SHVec3 vec = propertyNode.as<SHVec3>();
|
2022-10-01 23:43:00 +08:00
|
|
|
prop.set_value(component, vec);
|
|
|
|
}
|
|
|
|
else if (propType == rttr::type::get<SHVec2>())
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
SHVec2 vec = propertyNode.as<SHVec2>();
|
2022-10-01 23:43:00 +08:00
|
|
|
prop.set_value(component, vec);
|
|
|
|
}
|
|
|
|
else if (propType.is_arithmetic())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if (propType == rttr::type::get<bool>())
|
|
|
|
prop.set_value(component, propertyNode.as<bool>());
|
|
|
|
else if (propType == rttr::type::get<int8_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<int8_t>());
|
|
|
|
else if (propType == rttr::type::get<int16_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<int16_t>());
|
|
|
|
else if (propType == rttr::type::get<int32_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<int32_t>());
|
|
|
|
else if (propType == rttr::type::get<int64_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<int64_t>());
|
|
|
|
else if (propType == rttr::type::get<uint8_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<uint8_t>());
|
|
|
|
else if (propType == rttr::type::get<uint16_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<uint16_t>());
|
|
|
|
else if (propType == rttr::type::get<uint32_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<uint32_t>());
|
|
|
|
else if (propType == rttr::type::get<uint64_t>())
|
|
|
|
prop.set_value(component, propertyNode.as<uint64_t>());
|
|
|
|
else if (propType == rttr::type::get<float>())
|
|
|
|
prop.set_value(component, propertyNode.as<float>());
|
|
|
|
else if (propType == rttr::type::get<double>())
|
|
|
|
prop.set_value(component, propertyNode.as<double>());
|
|
|
|
}
|
|
|
|
else if (propType.is_enumeration())
|
|
|
|
{
|
|
|
|
auto enumAlign = prop.get_enumeration();
|
|
|
|
prop.set_value(component, enumAlign.name_to_value(propertyNode.as<std::string>()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto properties = propType.get_properties();
|
2022-10-25 15:09:45 +08:00
|
|
|
for (auto const& property : properties)
|
2022-10-01 23:43:00 +08:00
|
|
|
{
|
|
|
|
InitializeProperty(component, property, propertyNode[property.get_name().data()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
|
|
|
static void InitializeComponentFromNode(YAML::Node const& componentsNode, EntityID const& eid)
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
ComponentType* component = SHComponentManager::GetComponent_s<ComponentType>(eid);
|
2022-10-01 23:43:00 +08:00
|
|
|
if (componentsNode.IsNull() && !component)
|
|
|
|
return;
|
|
|
|
auto rttrType = rttr::type::get<ComponentType>();
|
|
|
|
auto componentNode = componentsNode[rttrType.get_name().data()];
|
|
|
|
if (componentsNode.IsNull())
|
|
|
|
return;
|
|
|
|
auto properties = rttrType.get_properties();
|
|
|
|
for (auto const& prop : properties)
|
|
|
|
{
|
2022-10-25 15:09:45 +08:00
|
|
|
|
|
|
|
if (componentNode[prop.get_name().data()].IsDefined())
|
2022-10-01 23:43:00 +08:00
|
|
|
{
|
|
|
|
InitializeProperty<ComponentType>(component, prop, componentNode[prop.get_name().data()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 15:09:45 +08:00
|
|
|
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
|
|
|
static void InitializeComponentFromNodeData(YAML::Node const& componentsNode, EntityID const& eid)
|
|
|
|
{
|
|
|
|
ComponentType* component = SHComponentManager::GetComponent_s<ComponentType>(eid);
|
|
|
|
if (componentsNode.IsNull() && !component)
|
|
|
|
return;
|
|
|
|
auto rttrType = rttr::type::get<ComponentType>();
|
|
|
|
auto componentNode = componentsNode[rttrType.get_name().data()];
|
|
|
|
if (componentsNode.IsNull())
|
|
|
|
return;
|
|
|
|
YAML::convert<ComponentType>::decode(componentNode, *component);
|
|
|
|
}
|
|
|
|
|
2022-09-26 23:51:20 +08:00
|
|
|
};
|
2022-09-27 07:03:31 +08:00
|
|
|
}
|