#pragma once #include "ECS_Base/Components/SHComponent.h" #include #include namespace SHADE { struct SHSerializationHelper { template , bool> = true> static std::string SerializeComponentToString(ComponentType* component) { return std::string(); } template , bool> = true> static void SerializeComponentToFile(ComponentType* component, std::filesystem::path const& path) { } static YAML::Node RTTRToNode(const rttr::variant& var) { YAML::Node node; auto varType = var.get_type(); if(varType.is_arithmetic()) { bool ok = false; if (varType == rttr::type::get()) node = var.to_bool(); else if (varType == rttr::type::get()) node = var.to_int8(&ok); else if (varType == rttr::type::get()) node = var.to_int16(&ok); else if (varType == rttr::type::get()) node = var.to_int32(&ok); else if (varType == rttr::type::get()) node = var.to_int64(&ok); else if (varType == rttr::type::get()) node = var.to_uint8(&ok); else if (varType == rttr::type::get()) node = var.to_uint16(&ok); else if (varType == rttr::type::get()) node = var.to_uint32(&ok); else if (varType == rttr::type::get()) node = var.to_uint64(&ok); else if (varType == rttr::type::get()) node = var.to_float(&ok); else if (varType == rttr::type::get()) node = var.to_double(&ok); //else if (varType == rttr::type::get()) //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 { ok = false; auto value = var.to_uint64(&ok); if (ok) node = value; else node = YAML::Null; } } else { auto properties = var.get_type().get_properties(); for(auto property : properties) { node[property.get_name().data()] = RTTRToNode(property.get_value(var)); } } return node; } template , bool> = true> static YAML::Node SerializeComponentToNode(ComponentType* component) { YAML::Node node{}; if(!component) return node; auto componentType = rttr::type::get(); node = RTTRToNode(*component); return node; } }; }