diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/ItemCoverter.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/ItemCoverter.cs index 7f820222..97694aa7 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/ItemCoverter.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/ItemCoverter.cs @@ -11,12 +11,9 @@ using StardewValley; namespace Revitalize.Framework.Utilities.Serialization.Converters { - /// - /// TODO: - /// Add support for all vanilla SDV objects in deserialization. - /// public class ItemCoverter:Newtonsoft.Json.JsonConverter { + public static Dictionary AllTypes = new Dictionary(); JsonSerializerSettings settings; public ItemCoverter() @@ -77,6 +74,12 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters string t = jo["Type"].Value(); + //See if the type has already been cached and if so return it for deserialization. + if (AllTypes.ContainsKey(t)) + { + + return JsonConvert.DeserializeObject(jo["Item"].ToString(), AllTypes[t], this.settings); + } Assembly asm = typeof(StardewValley.Object).Assembly; Type type = null; @@ -88,6 +91,25 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters asm = typeof(Revitalize.ModCore).Assembly; type = asm.GetType(t); } + + if (type == null) + { + foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + asm = assembly; + type = asm.GetType(t); + if (t != null) break; + } + } + + if (type == null) + { + throw new Exception("Unsupported type found when Deserializing Unsure what to do so we can;t deserialize this thing!: " + t); + } + + //Cache the newly found type. + AllTypes.Add(t, type); + return JsonConvert.DeserializeObject(jo["Item"].ToString(),type, this.settings); /* if (t== typeof(StardewValley.Tools.Axe).FullName.ToString()) diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs index 026334a9..7742cdcb 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs @@ -11,6 +11,8 @@ namespace Revitalize.Framework.Utilities { /// /// Handles serialization of all objects in existence. + /// + /// TODO: Make JConvert that has same settings to implement a toJSon string obj /// public class Serializer {