You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

  1. using IPA.Logging;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace IPA.JsonConverters
  10. {
  11. internal class FeaturesFieldConverter : JsonConverter<Dictionary<string, JObject>>
  12. {
  13. public override Dictionary<string, JObject> ReadJson(JsonReader reader, Type objectType, Dictionary<string, JObject> existingValue, bool hasExistingValue, JsonSerializer serializer)
  14. {
  15. if (reader.TokenType == JsonToken.StartArray)
  16. {
  17. _ = serializer.Deserialize<string[]>(reader);
  18. Logger.features.Warn("Encountered old features used. They no longer do anything, please move to the new format.");
  19. return existingValue;
  20. }
  21. return serializer.Deserialize<Dictionary<string, JObject>>(reader);
  22. }
  23. public override void WriteJson(JsonWriter writer, Dictionary<string, JObject> value, JsonSerializer serializer)
  24. {
  25. serializer.Serialize(writer, value);
  26. }
  27. }
  28. }