Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Feb 28, 2024
2 parents 39c0b6c + a340f88 commit e6565a2
Show file tree
Hide file tree
Showing 63 changed files with 455 additions and 573 deletions.
2 changes: 1 addition & 1 deletion src/Artemis.Core/Artemis.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<PackageReference Include="Humanizer.Core" />
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="McMaster.NETCore.Plugins" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="RGB.NET.Core" />
<PackageReference Include="RGB.NET.Layout" />
<PackageReference Include="RGB.NET.Presets" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.Debug" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="SkiaSharp" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 6 additions & 18 deletions src/Artemis.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using Artemis.Core.JsonConverters;
using Artemis.Core.Services;
using Artemis.Core.SkiaSharp;
using Newtonsoft.Json;

namespace Artemis.Core;

Expand Down Expand Up @@ -62,7 +60,7 @@ public static class Constants
/// The full path to the Artemis user layouts folder
/// </summary>
public static readonly string LayoutsFolder = Path.Combine(DataFolder, "User Layouts");

/// <summary>
/// The full path to the Artemis user layouts folder
/// </summary>
Expand Down Expand Up @@ -94,20 +92,6 @@ public static class Constants
/// </summary>
public static readonly Plugin CorePlugin = new(CorePluginInfo, new DirectoryInfo(ApplicationFolder), null);

internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};

internal static JsonSerializerSettings JsonConvertSettings = new()
{
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 NumericJsonConverter(), new ForgivingIntConverter()}
};

/// <summary>
/// A read-only collection containing all primitive numeric types
/// </summary>
Expand Down Expand Up @@ -155,4 +139,8 @@ public static class Constants
/// Gets the startup arguments provided to the application
/// </summary>
public static ReadOnlyCollection<string> StartupArguments { get; set; } = null!;

internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};
internal static readonly JsonSerializerOptions JsonConvertSettings = new() {Converters = {new SKColorConverter(), new NumericJsonConverter()}};
}
32 changes: 0 additions & 32 deletions src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs

This file was deleted.

26 changes: 0 additions & 26 deletions src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs

This file was deleted.

36 changes: 19 additions & 17 deletions src/Artemis.Core/JsonConverters/NumericJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using System;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Artemis.Core.JsonConverters;

internal class NumericJsonConverter : JsonConverter<Numeric>
namespace Artemis.Core.JsonConverters
{
#region Overrides of JsonConverter<Numeric>

/// <inheritdoc />
public override void WriteJson(JsonWriter writer, Numeric value, JsonSerializer serializer)
internal class NumericJsonConverter : JsonConverter<Numeric>
{
float floatValue = value;
writer.WriteValue(floatValue);
}
public override void Write(Utf8JsonWriter writer, Numeric value, JsonSerializerOptions options)
{
float floatValue = value;
writer.WriteNumberValue(floatValue);
}

/// <inheritdoc />
public override Numeric ReadJson(JsonReader reader, Type objectType, Numeric existingValue, bool hasExistingValue, JsonSerializer serializer)
{
return new Numeric(reader.Value);
}
public override Numeric Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.Number)
{
throw new JsonException($"Expected a number token, but got {reader.TokenType}.");
}

#endregion
float floatValue = reader.GetSingle();
return new Numeric(floatValue);
}
}
}
29 changes: 17 additions & 12 deletions src/Artemis.Core/JsonConverters/SKColorConverter.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
using System;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using SkiaSharp;

namespace Artemis.Core.JsonConverters;

internal class SKColorConverter : JsonConverter<SKColor>
namespace Artemis.Core.JsonConverters
{
public override void WriteJson(JsonWriter writer, SKColor value, JsonSerializer serializer)
internal class SKColorConverter : JsonConverter<SKColor>
{
writer.WriteValue(value.ToString());
}
public override void Write(Utf8JsonWriter writer, SKColor value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}

public override SKColor ReadJson(JsonReader reader, Type objectType, SKColor existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.Value is string value && !string.IsNullOrWhiteSpace(value))
return SKColor.Parse(value);
public override SKColor Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException($"Expected a string token, but got {reader.TokenType}.");
}

return SKColor.Empty;
string colorString = reader.GetString() ?? string.Empty;
return SKColor.TryParse(colorString, out SKColor color) ? color : SKColor.Empty;
}
}
}
44 changes: 0 additions & 44 deletions src/Artemis.Core/JsonConverters/StreamConverter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Artemis.Core/Models/Profile/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Folder CreateCopy()
if (Parent == null)
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");

FolderEntity entityCopy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity, true), true)!;
FolderEntity entityCopy = CoreJson.Deserialize<FolderEntity>(CoreJson.Serialize(FolderEntity))!;
entityCopy.Id = Guid.NewGuid();
entityCopy.Name += " - Copy";

Expand Down
12 changes: 6 additions & 6 deletions src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.Json;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;

namespace Artemis.Core;

Expand Down Expand Up @@ -324,8 +324,8 @@ public void ApplyDefaultValue()
// Reference types make a deep clone (ab)using JSON
else
{
string json = CoreJson.SerializeObject(DefaultValue, true);
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!);
string json = CoreJson.Serialize(DefaultValue);
SetCurrentValue(CoreJson.Deserialize<T>(json)!);
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ public void AddKeyframe(LayerPropertyKeyframe<T> keyframe)

try
{
T? value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
T? value = CoreJson.Deserialize<T>(keyframeEntity.Value);
if (value == null)
return null;

Expand Down Expand Up @@ -625,7 +625,7 @@ public void Load()
try
{
if (Entity.Value != null)
BaseValue = CoreJson.DeserializeObject<T>(Entity.Value)!;
BaseValue = CoreJson.Deserialize<T>(Entity.Value)!;
}
catch (JsonException)
{
Expand Down Expand Up @@ -664,7 +664,7 @@ public void Save()
if (!_isInitialized)
throw new ArtemisCoreException("Layer property is not yet initialized");

Entity.Value = CoreJson.SerializeObject(BaseValue);
Entity.Value = CoreJson.Serialize(BaseValue);
Entity.KeyframesEnabled = KeyframesEnabled;
Entity.KeyframeEntities.Clear();
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => k.GetKeyframeEntity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public KeyframeEntity GetKeyframeEntity()
{
return new KeyframeEntity
{
Value = CoreJson.SerializeObject(Value),
Value = CoreJson.Serialize(Value),
Position = Position,
EasingFunction = (int) EasingFunction
};
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/Artemis.Core/Plugins/Modules/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text.Json.Serialization;
using Humanizer;
using Newtonsoft.Json;

namespace Artemis.Core.Modules;

Expand Down
Loading

0 comments on commit e6565a2

Please sign in to comment.