Merge pull request #210 from SHADE-DP/SP3-8-serialization

Added serialization of component isActive
This commit is contained in:
XiaoQiDigipen 2022-11-15 18:15:23 +08:00 committed by GitHub
commit 4b70fbf0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -179,7 +179,9 @@ namespace SHADE
{ {
if (ComponentType* component = SHComponentManager::GetComponent_s<ComponentType>(eid)) if (ComponentType* component = SHComponentManager::GetComponent_s<ComponentType>(eid))
{ {
componentsNode[rttr::type::get<ComponentType>().get_name().data()] = YAML::convert<ComponentType>::encode(*component); auto componentNode = YAML::convert<ComponentType>::encode(*component);
componentNode[IsActive.data()] = component->isActive;
componentsNode[rttr::type::get<ComponentType>().get_name().data()] = componentNode;
} }
} }

View File

@ -14,6 +14,8 @@
namespace SHADE namespace SHADE
{ {
static constexpr std::string_view IsActive = "IsActive";
using AssetQueue = std::unordered_map<AssetID, AssetType>; using AssetQueue = std::unordered_map<AssetID, AssetType>;
struct SHSerializationHelper struct SHSerializationHelper
{ {
@ -118,9 +120,9 @@ namespace SHADE
YAML::Node node{}; YAML::Node node{};
if (!component) if (!component)
return node; return node;
auto componentType = rttr::type::get<ComponentType>(); auto componentType = rttr::type::get<ComponentType>();
node = RTTRToNode(*component); node = RTTRToNode(*component);
node[IsActive.data()] = component->isActive;
return node; return node;
} }
@ -198,6 +200,9 @@ namespace SHADE
auto componentNode = componentsNode[rttrType.get_name().data()]; auto componentNode = componentsNode[rttrType.get_name().data()];
if (!componentNode.IsDefined()) if (!componentNode.IsDefined())
return; return;
if(componentNode[IsActive.data()].IsDefined())
component->isActive = componentNode[IsActive.data()].as<bool>();
auto properties = rttrType.get_properties(); auto properties = rttrType.get_properties();
for (auto const& prop : properties) for (auto const& prop : properties)
{ {
@ -227,8 +232,10 @@ namespace SHADE
auto component = SHComponentManager::GetComponent_s<ComponentType>(eid); auto component = SHComponentManager::GetComponent_s<ComponentType>(eid);
if (componentsNode.IsNull() && !component) if (componentsNode.IsNull() && !component)
return; return;
auto componentNode = GetComponentNode<ComponentType>(componentsNode, eid);
YAML::convert<ComponentType>::decode(GetComponentNode<ComponentType>(componentsNode, eid), *component); if (componentNode[IsActive.data()].IsDefined())
component->isActive = componentNode[IsActive.data()].as<bool>();
YAML::convert<ComponentType>::decode(componentNode, *component);
} }
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true> template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>