diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 00:23:48 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 00:23:48 -0400 |
commit | 0863f9b7e5f165f2b1db8750b20ed35bc0c3701a (patch) | |
tree | 30f7f83e6c699c03081067b01b3fd62a2846e6fc /src/StardewModdingAPI/Framework/Serialisation | |
parent | 33af789e2eb4da101cead531b77c29ecf4933549 (diff) | |
download | SMAPI-0863f9b7e5f165f2b1db8750b20ed35bc0c3701a.tar.gz SMAPI-0863f9b7e5f165f2b1db8750b20ed35bc0c3701a.tar.bz2 SMAPI-0863f9b7e5f165f2b1db8750b20ed35bc0c3701a.zip |
revamp mod compatibility fields to allow broader use of mod data records (#361)
Diffstat (limited to 'src/StardewModdingAPI/Framework/Serialisation')
-rw-r--r-- | src/StardewModdingAPI/Framework/Serialisation/SFieldConverter.cs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/StardewModdingAPI/Framework/Serialisation/SFieldConverter.cs b/src/StardewModdingAPI/Framework/Serialisation/SFieldConverter.cs index d71e138b..ffece081 100644 --- a/src/StardewModdingAPI/Framework/Serialisation/SFieldConverter.cs +++ b/src/StardewModdingAPI/Framework/Serialisation/SFieldConverter.cs @@ -27,7 +27,8 @@ namespace StardewModdingAPI.Framework.Serialisation return objectType == typeof(ISemanticVersion) || objectType == typeof(IManifestDependency[]) - || objectType == typeof(ModDataID); + || objectType == typeof(ModDataID) + || objectType == typeof(ModCompatibility[]); } /// <summary>Reads the JSON representation of the object.</summary> @@ -68,7 +69,7 @@ namespace StardewModdingAPI.Framework.Serialisation } } - // manifest dependency + // manifest dependencies if (objectType == typeof(IManifestDependency[])) { List<IManifestDependency> result = new List<IManifestDependency>(); @@ -82,13 +83,28 @@ namespace StardewModdingAPI.Framework.Serialisation return result.ToArray(); } - // mod compatibility ID + // mod data ID if (objectType == typeof(ModDataID)) { JToken token = JToken.Load(reader); return new ModDataID(token.Value<string>()); } + // mod compatibility records + if (objectType == typeof(ModCompatibility[])) + { + List<ModCompatibility> result = new List<ModCompatibility>(); + foreach (JProperty property in JObject.Load(reader).Properties()) + { + string range = property.Name; + ModStatus status = property.Value.Value<ModStatus>(nameof(ModCompatibility.Status)); + string reasonPhrase = property.Value.Value<string>(nameof(ModCompatibility.ReasonPhrase)); + + result.Add(new ModCompatibility(range, status, reasonPhrase)); + } + return result.ToArray(); + } + // unknown throw new NotSupportedException($"Unknown type '{objectType?.FullName}'."); } |