summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-08 00:12:47 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-08 00:12:47 -0400
commit03e679d66cc7439b0218c95cbead925786e37e86 (patch)
tree9002440ea14dfdd1363e3a0587c9d807695ca7a4
parent8df5d79c9e01c2d665192ba5accfcd45a47e2dda (diff)
downloadSMAPI-03e679d66cc7439b0218c95cbead925786e37e86.tar.gz
SMAPI-03e679d66cc7439b0218c95cbead925786e37e86.tar.bz2
SMAPI-03e679d66cc7439b0218c95cbead925786e37e86.zip
serialise all enums to string in JSON by default
-rw-r--r--docs/release-notes.md3
-rw-r--r--src/SMAPI/Program.cs3
-rw-r--r--src/StardewModdingAPI.Toolkit/Serialisation/Converters/StringEnumConverter.cs22
-rw-r--r--src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs7
4 files changed, 8 insertions, 27 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 691bf48e..d14b7459 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -3,9 +3,10 @@
* For players:
* Fixed custom festival maps always using spring tilesheets.
* Fixed `player_add` command not recognising return scepter.
- * Fixed `player_add` showing fish twice.
+ * Fixed `player_add` command showing fish twice.
* For modders:
+ * All enums in `config.json` are now serialised to string by default, since that's more user-friendly. Previously only certain predefined enums were serialised that way. Note that `config.json` files which already have integer enums will still be parsed fine.
* Fixed false compatibility error when constructing multidimensional arrays.
* Fixed `.ToSButton()` methods not being public.
* Updated compatibility list.
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 6012b15a..999aa23c 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -193,9 +193,6 @@ namespace StardewModdingAPI
// init JSON parser
JsonConverter[] converters = {
- new StringEnumConverter<Buttons>(),
- new StringEnumConverter<Keys>(),
- new StringEnumConverter<SButton>(),
new ColorConverter(),
new PointConverter(),
new RectangleConverter()
diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/StringEnumConverter.cs b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/StringEnumConverter.cs
deleted file mode 100644
index 13e6e3a1..00000000
--- a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/StringEnumConverter.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using Newtonsoft.Json.Converters;
-
-namespace StardewModdingAPI.Toolkit.Serialisation.Converters
-{
- /// <summary>A variant of <see cref="StringEnumConverter"/> which only converts a specified enum.</summary>
- /// <typeparam name="T">The enum type.</typeparam>
- internal class StringEnumConverter<T> : StringEnumConverter
- {
- /*********
- ** Public methods
- *********/
- /// <summary>Get whether this instance can convert the specified object type.</summary>
- /// <param name="type">The object type.</param>
- public override bool CanConvert(Type type)
- {
- return
- base.CanConvert(type)
- && (Nullable.GetUnderlyingType(type) ?? type) == typeof(T);
- }
- }
-}
diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
index 00f334ad..3cabbab3 100644
--- a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
+++ b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
using StardewModdingAPI.Toolkit.Serialisation.Converters;
namespace StardewModdingAPI.Toolkit.Serialisation
@@ -17,7 +18,11 @@ namespace StardewModdingAPI.Toolkit.Serialisation
{
Formatting = Formatting.Indented,
ObjectCreationHandling = ObjectCreationHandling.Replace, // avoid issue where default ICollection<T> values are duplicated each time the config is loaded
- Converters = new List<JsonConverter> { new SemanticVersionConverter() }
+ Converters = new List<JsonConverter>
+ {
+ new SemanticVersionConverter(),
+ new StringEnumConverter()
+ }
};