mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Fix numeric serialization
This commit is contained in:
parent
50b4c71142
commit
245c418b9b
@ -62,13 +62,13 @@ namespace Artemis.Core
|
||||
|
||||
internal static JsonSerializerSettings JsonConvertSettings = new()
|
||||
{
|
||||
Converters = new List<JsonConverter> {new SKColorConverter(), new ForgivingIntConverter()}
|
||||
Converters = new List<JsonConverter> {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
|
||||
};
|
||||
|
||||
internal static JsonSerializerSettings JsonConvertTypedSettings = new()
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
Converters = new List<JsonConverter> {new SKColorConverter(), new ForgivingIntConverter()}
|
||||
Converters = new List<JsonConverter> {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
25
src/Artemis.Core/JsonConverters/NumericJsonConverter.cs
Normal file
25
src/Artemis.Core/JsonConverters/NumericJsonConverter.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.JsonConverters
|
||||
{
|
||||
internal class NumericJsonConverter : JsonConverter<Numeric>
|
||||
{
|
||||
#region Overrides of JsonConverter<Numeric>
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void WriteJson(JsonWriter writer, Numeric value, JsonSerializer serializer)
|
||||
{
|
||||
float floatValue = value;
|
||||
writer.WriteValue(floatValue);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Numeric ReadJson(JsonReader reader, Type objectType, Numeric existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
return new Numeric(reader.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
@ -90,7 +89,7 @@ namespace Artemis.UI.Shared.Controls
|
||||
public DataModelPicker()
|
||||
{
|
||||
SelectPropertyCommand = new DelegateCommand(ExecuteSelectPropertyCommand);
|
||||
Unloaded += (_, _) => DataModelViewModel?.Dispose();
|
||||
Unloaded += OnUnloaded;
|
||||
InitializeComponent();
|
||||
GetDataModel();
|
||||
UpdateValueDisplay();
|
||||
@ -206,11 +205,6 @@ namespace Artemis.UI.Shared.Controls
|
||||
DataModelPathSelected?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void GetDataModel()
|
||||
{
|
||||
ChangeDataModel(_dataModelUIService.GetPluginDataModelVisualization(Modules?.ToList() ?? new List<Module>(), true));
|
||||
@ -332,6 +326,18 @@ namespace Artemis.UI.Shared.Controls
|
||||
Dispatcher.Invoke(UpdateValueDisplay, DispatcherPriority.DataBind);
|
||||
}
|
||||
|
||||
private void OnUnloaded(object o, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
if (DataModelPath != null)
|
||||
{
|
||||
DataModelPath.PathInvalidated -= PathValidationChanged;
|
||||
DataModelPath.PathValidated -= PathValidationChanged;
|
||||
}
|
||||
|
||||
DataModelViewModel?.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user