From 85abf7e22f7d0b2bec6bb77c835387be71a75b95 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 15 Dec 2019 21:14:28 -0600 Subject: [PATCH] Added an AlmostVersionConverter --- .../Config/Stores/CustomObjectConverter.cs | 2 +- IPA.Loader/Loader/PluginManifest.cs | 1 + IPA.Loader/Updating/BeatMods/ApiEndpoint.cs | 2 +- IPA.Loader/Utilities/AlmostVersion.cs | 28 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/IPA.Loader/Config/Stores/CustomObjectConverter.cs b/IPA.Loader/Config/Stores/CustomObjectConverter.cs index 21402ce9..5f8cc00a 100644 --- a/IPA.Loader/Config/Stores/CustomObjectConverter.cs +++ b/IPA.Loader/Config/Stores/CustomObjectConverter.cs @@ -20,7 +20,7 @@ namespace IPA.Config.Stores.Converters private static readonly GeneratedStore.GeneratedStoreCreator creator = GeneratedStore.GetCreator(typeof(T)); public T FromValue(Value value, object parent) - { // lots of casting here, but it works i promise (parent can be a non-IGeneratedStore, however it won't necessarily behave then) + { // lots of casting here, but it works i promise (probably) (parent can be a non-IGeneratedStore, however it won't necessarily behave then) var obj = creator(parent as GeneratedStore.IGeneratedStore) as U; obj.Deserialize(value); return obj; diff --git a/IPA.Loader/Loader/PluginManifest.cs b/IPA.Loader/Loader/PluginManifest.cs index ae621ea4..a545962e 100644 --- a/IPA.Loader/Loader/PluginManifest.cs +++ b/IPA.Loader/Loader/PluginManifest.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using SemVer; using System; using System.Collections.Generic; +using AlmostVersionConverter = IPA.JsonConverters.AlmostVersionConverter; using Version = SemVer.Version; namespace IPA.Loader diff --git a/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs b/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs index 18bcbd00..8062dbd8 100644 --- a/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs +++ b/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs @@ -104,7 +104,7 @@ namespace IPA.Updating.BeatMods public Version Version; [JsonProperty("gameVersion"), - JsonConverter(typeof(AlmostVersionConverter))] + JsonConverter(typeof(JsonConverters.AlmostVersionConverter))] public AlmostVersion GameVersion; [Serializable] diff --git a/IPA.Loader/Utilities/AlmostVersion.cs b/IPA.Loader/Utilities/AlmostVersion.cs index c23f0ba9..182c1371 100644 --- a/IPA.Loader/Utilities/AlmostVersion.cs +++ b/IPA.Loader/Utilities/AlmostVersion.cs @@ -1,4 +1,7 @@ -using System; +using IPA.Config.Data; +using IPA.Config.Stores; +using IPA.Config.Stores.Converters; +using System; using System.Collections.Generic; using Version = SemVer.Version; @@ -241,4 +244,27 @@ namespace IPA.Utilities /// public static implicit operator Version(AlmostVersion av) => av?.SemverValue; } + + /// + /// A for s. + /// + public sealed class AlmostVersionConverter : ValueConverter + { + /// + /// Converts a node into an . + /// + /// the node to convert + /// the owner of the new object + /// + public override AlmostVersion FromValue(Value value, object parent) + => new AlmostVersion(Converter.Default.FromValue(value, parent)); + /// + /// Converts an to a node. + /// + /// the to convert + /// the parent of + /// a node representing + public override Value ToValue(AlmostVersion obj, object parent) + => Value.From(obj.ToString()); + } }