diff options
Diffstat (limited to 'src/SMAPI/Framework/Serialisation')
-rw-r--r-- | src/SMAPI/Framework/Serialisation/CrossplatformConverters/ColorConverter.cs | 8 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/CrossplatformConverters/PointConverter.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/CrossplatformConverters/RectangleConverter.cs | 10 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/JsonHelper.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestContentPackForConverter.cs (renamed from src/SMAPI/Framework/Serialisation/SmapiConverters/ModCompatibilityArrayConverter.cs) | 19 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestDependencyArrayConverter.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/SmapiConverters/ModDataIdConverter.cs | 19 | ||||
-rw-r--r-- | src/SMAPI/Framework/Serialisation/SmapiConverters/SemanticVersionConverter.cs | 8 |
8 files changed, 25 insertions, 52 deletions
diff --git a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/ColorConverter.cs b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/ColorConverter.cs index f4a2a26e..f1b2f04f 100644 --- a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/ColorConverter.cs +++ b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/ColorConverter.cs @@ -20,10 +20,10 @@ namespace StardewModdingAPI.Framework.Serialisation.CrossplatformConverters /// <param name="path">The path to the current JSON node.</param> protected override Color ReadObject(JObject obj, string path) { - int r = obj.Value<int>(nameof(Color.R)); - int g = obj.Value<int>(nameof(Color.G)); - int b = obj.Value<int>(nameof(Color.B)); - int a = obj.Value<int>(nameof(Color.A)); + int r = obj.ValueIgnoreCase<int>(nameof(Color.R)); + int g = obj.ValueIgnoreCase<int>(nameof(Color.G)); + int b = obj.ValueIgnoreCase<int>(nameof(Color.B)); + int a = obj.ValueIgnoreCase<int>(nameof(Color.A)); return new Color(r, g, b, a); } diff --git a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/PointConverter.cs b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/PointConverter.cs index 84c70989..434b7ea5 100644 --- a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/PointConverter.cs +++ b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/PointConverter.cs @@ -20,8 +20,8 @@ namespace StardewModdingAPI.Framework.Serialisation.CrossplatformConverters /// <param name="path">The path to the current JSON node.</param> protected override Point ReadObject(JObject obj, string path) { - int x = obj.Value<int>(nameof(Point.X)); - int y = obj.Value<int>(nameof(Point.Y)); + int x = obj.ValueIgnoreCase<int>(nameof(Point.X)); + int y = obj.ValueIgnoreCase<int>(nameof(Point.Y)); return new Point(x, y); } diff --git a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/RectangleConverter.cs b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/RectangleConverter.cs index b89551e3..62bc8637 100644 --- a/src/SMAPI/Framework/Serialisation/CrossplatformConverters/RectangleConverter.cs +++ b/src/SMAPI/Framework/Serialisation/CrossplatformConverters/RectangleConverter.cs @@ -21,10 +21,10 @@ namespace StardewModdingAPI.Framework.Serialisation.CrossplatformConverters /// <param name="path">The path to the current JSON node.</param> protected override Rectangle ReadObject(JObject obj, string path) { - int x = obj.Value<int>(nameof(Rectangle.X)); - int y = obj.Value<int>(nameof(Rectangle.Y)); - int width = obj.Value<int>(nameof(Rectangle.Width)); - int height = obj.Value<int>(nameof(Rectangle.Height)); + int x = obj.ValueIgnoreCase<int>(nameof(Rectangle.X)); + int y = obj.ValueIgnoreCase<int>(nameof(Rectangle.Y)); + int width = obj.ValueIgnoreCase<int>(nameof(Rectangle.Width)); + int height = obj.ValueIgnoreCase<int>(nameof(Rectangle.Height)); return new Rectangle(x, y, width, height); } @@ -36,7 +36,7 @@ namespace StardewModdingAPI.Framework.Serialisation.CrossplatformConverters if (string.IsNullOrWhiteSpace(str)) return Rectangle.Empty; - var match = Regex.Match(str, @"^\{X:(?<x>\d+) Y:(?<y>\d+) Width:(?<width>\d+) Height:(?<height>\d+)\}$"); + var match = Regex.Match(str, @"^\{X:(?<x>\d+) Y:(?<y>\d+) Width:(?<width>\d+) Height:(?<height>\d+)\}$", RegexOptions.IgnoreCase); if (!match.Success) throw new SParseException($"Can't parse {typeof(Rectangle).Name} from invalid value '{str}' (path: {path})."); diff --git a/src/SMAPI/Framework/Serialisation/JsonHelper.cs b/src/SMAPI/Framework/Serialisation/JsonHelper.cs index 2e2a666e..6cba343e 100644 --- a/src/SMAPI/Framework/Serialisation/JsonHelper.cs +++ b/src/SMAPI/Framework/Serialisation/JsonHelper.cs @@ -21,6 +21,9 @@ namespace StardewModdingAPI.Framework.Serialisation ObjectCreationHandling = ObjectCreationHandling.Replace, // avoid issue where default ICollection<T> values are duplicated each time the config is loaded Converters = new List<JsonConverter> { + // SMAPI types + new SemanticVersionConverter(), + // enums new StringEnumConverter<Buttons>(), new StringEnumConverter<Keys>(), diff --git a/src/SMAPI/Framework/Serialisation/SmapiConverters/ModCompatibilityArrayConverter.cs b/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestContentPackForConverter.cs index 3232dde4..af7558f6 100644 --- a/src/SMAPI/Framework/Serialisation/SmapiConverters/ModCompatibilityArrayConverter.cs +++ b/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestContentPackForConverter.cs @@ -1,13 +1,11 @@ using System; -using System.Collections.Generic; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using StardewModdingAPI.Framework.Models; namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters { - /// <summary>Handles deserialisation of <see cref="ModCompatibility"/> arrays.</summary> - internal class ModCompatibilityArrayConverter : JsonConverter + /// <summary>Handles deserialisation of <see cref="IManifestContentPackFor"/> arrays.</summary> + internal class ManifestContentPackForConverter : JsonConverter { /********* ** Accessors @@ -23,7 +21,7 @@ namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters /// <param name="objectType">The object type.</param> public override bool CanConvert(Type objectType) { - return objectType == typeof(ModCompatibility[]); + return objectType == typeof(IManifestContentPackFor[]); } @@ -37,16 +35,7 @@ namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters /// <param name="serializer">The calling serializer.</param> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - List<ModCompatibility> result = new List<ModCompatibility>(); - foreach (JProperty property in JObject.Load(reader).Properties()) - { - string range = property.Name; - ModStatus status = (ModStatus)Enum.Parse(typeof(ModStatus), property.Value.Value<string>(nameof(ModCompatibility.Status))); - string reasonPhrase = property.Value.Value<string>(nameof(ModCompatibility.ReasonPhrase)); - - result.Add(new ModCompatibility(range, status, reasonPhrase)); - } - return result.ToArray(); + return serializer.Deserialize<ManifestContentPackFor>(reader); } /// <summary>Writes the JSON representation of the object.</summary> diff --git a/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestDependencyArrayConverter.cs b/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestDependencyArrayConverter.cs index 6352e367..4150d5fb 100644 --- a/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestDependencyArrayConverter.cs +++ b/src/SMAPI/Framework/Serialisation/SmapiConverters/ManifestDependencyArrayConverter.cs @@ -40,9 +40,9 @@ namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters List<IManifestDependency> result = new List<IManifestDependency>(); foreach (JObject obj in JArray.Load(reader).Children<JObject>()) { - string uniqueID = obj.Value<string>(nameof(IManifestDependency.UniqueID)); - string minVersion = obj.Value<string>(nameof(IManifestDependency.MinimumVersion)); - bool required = obj.Value<bool?>(nameof(IManifestDependency.IsRequired)) ?? true; + string uniqueID = obj.ValueIgnoreCase<string>(nameof(IManifestDependency.UniqueID)); + string minVersion = obj.ValueIgnoreCase<string>(nameof(IManifestDependency.MinimumVersion)); + bool required = obj.ValueIgnoreCase<bool?>(nameof(IManifestDependency.IsRequired)) ?? true; result.Add(new ManifestDependency(uniqueID, minVersion, required)); } return result.ToArray(); diff --git a/src/SMAPI/Framework/Serialisation/SmapiConverters/ModDataIdConverter.cs b/src/SMAPI/Framework/Serialisation/SmapiConverters/ModDataIdConverter.cs deleted file mode 100644 index 8a10db47..00000000 --- a/src/SMAPI/Framework/Serialisation/SmapiConverters/ModDataIdConverter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using StardewModdingAPI.Framework.Models; - -namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters -{ - /// <summary>Handles deserialisation of <see cref="ModDataID"/>.</summary> - internal class ModDataIdConverter : SimpleReadOnlyConverter<ModDataID> - { - /********* - ** Protected methods - *********/ - /// <summary>Read a JSON string.</summary> - /// <param name="str">The JSON string value.</param> - /// <param name="path">The path to the current JSON node.</param> - protected override ModDataID ReadString(string str, string path) - { - return new ModDataID(str); - } - } -} diff --git a/src/SMAPI/Framework/Serialisation/SmapiConverters/SemanticVersionConverter.cs b/src/SMAPI/Framework/Serialisation/SmapiConverters/SemanticVersionConverter.cs index 50181809..7ee7e29b 100644 --- a/src/SMAPI/Framework/Serialisation/SmapiConverters/SemanticVersionConverter.cs +++ b/src/SMAPI/Framework/Serialisation/SmapiConverters/SemanticVersionConverter.cs @@ -14,10 +14,10 @@ namespace StardewModdingAPI.Framework.Serialisation.SmapiConverters /// <param name="path">The path to the current JSON node.</param> protected override ISemanticVersion ReadObject(JObject obj, string path) { - int major = obj.Value<int>(nameof(ISemanticVersion.MajorVersion)); - int minor = obj.Value<int>(nameof(ISemanticVersion.MinorVersion)); - int patch = obj.Value<int>(nameof(ISemanticVersion.PatchVersion)); - string build = obj.Value<string>(nameof(ISemanticVersion.Build)); + int major = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.MajorVersion)); + int minor = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.MinorVersion)); + int patch = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.PatchVersion)); + string build = obj.ValueIgnoreCase<string>(nameof(ISemanticVersion.Build)); return new LegacyManifestVersion(major, minor, patch, build); } |