From cfed342f9c7571f303e0143d47373b91b3ac2b78 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 20 Oct 2022 09:54:51 +0800 Subject: [PATCH] Modified script serialization to use a sequence of scripts instead of a map --- SHADE_Managed/src/Scripts/ScriptStore.cxx | 2 +- .../src/Serialisation/ReflectionUtilities.cxx | 15 ++++++++++----- .../src/Serialisation/ReflectionUtilities.hxx | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 3f366c36..b9423795 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -497,7 +497,7 @@ namespace SHADE return true; // Serialise each script - //yamlNode->SetStyle(YAML::EmitterStyle::Block); + yamlNode->SetStyle(YAML::EmitterStyle::Block); System::Collections::Generic::List^ scriptList = scripts[entity]; for each (Script^ script in scriptList) { diff --git a/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx b/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx index dc03a95c..8e5b1d38 100644 --- a/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx @@ -38,6 +38,11 @@ if (iter != jsonValue.MemberEnd()) \ vec.MEMBER = iter->value.GetDouble(); \ } \ +/*-------------------------------------------------------------------------------------*/ +/* File-Level Constants */ +/*-------------------------------------------------------------------------------------*/ +static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type"; + /*-------------------------------------------------------------------------------------*/ /* Function Definitions */ /*-------------------------------------------------------------------------------------*/ @@ -61,12 +66,14 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Serialisation Functions */ /*---------------------------------------------------------------------------------*/ - void ReflectionUtilities::Serialise(System::Object^ object, YAML::Node& yamlNode) + void ReflectionUtilities::Serialise(System::Object^ object, YAML::Node& scriptListNode) { using namespace System::Reflection; // Create YAML object YAML::Node scriptNode; + scriptNode.SetStyle(YAML::EmitterStyle::Block); + scriptNode[SCRIPT_TYPE_YAMLTAG] = Convert::ToNative(object->GetType()->FullName); // Get all fields System::Collections::Generic::IEnumerable^ fields = GetInstanceFields(object); @@ -80,7 +87,7 @@ namespace SHADE writeFieldIntoYaml(field, object, scriptNode); } - yamlNode[Convert::ToNative(object->GetType()->FullName)] = scriptNode; + scriptListNode.push_back(scriptNode); } void ReflectionUtilities::Deserialise(Object^ object, YAML::Node& yamlNode) { @@ -120,8 +127,6 @@ namespace SHADE { // Field YAML Node YAML::Node fieldNode; - fieldNode.SetStyle(YAML::EmitterStyle::Block); - fieldNode["Name"] = Convert::ToNative(fieldInfo->Name); // Retrieve string for the YAML if (fieldInsertYaml (fieldInfo, object, fieldNode) || @@ -172,7 +177,7 @@ namespace SHADE } // Store the field into YAML - yamlNode.push_back(fieldNode); + yamlNode[Convert::ToNative(fieldInfo->Name)] = fieldNode; } void ReflectionUtilities::writeYamlIntoField(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) diff --git a/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx b/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx index 0709f667..4742c7ff 100644 --- a/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx +++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx @@ -64,6 +64,8 @@ namespace SHADE /// The object to copy deserialised data into. static void Deserialise(System::Object^ object, YAML::Node& yamlNode); + + private: /*-----------------------------------------------------------------------------*/ /* Serialization Helper Functions */ /*-----------------------------------------------------------------------------*/