mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Core - Moved JSON calls into a helper
This commit is contained in:
1 parent
190d64b497
commit
a5e2dc81a4
12 files changed
+125
-72
No files matched your search
@@ -115,7 +115,7 @@ namespace Artemis.Core
|
||||
|
||||
try
|
||||
{
|
||||
rightSideValue = JsonConvert.DeserializeObject(Entity.RightStaticValue, leftSideType, Constants.JsonConvertSettings);
|
||||
rightSideValue = CoreJson.DeserializeObject(Entity.RightStaticValue, leftSideType);
|
||||
}
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
@@ -129,7 +129,7 @@ namespace Artemis.Core
|
||||
else
|
||||
{
|
||||
// Hope for the best...
|
||||
UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue, Constants.JsonConvertSettings));
|
||||
UpdateRightSideStatic(CoreJson.DeserializeObject(Entity.RightStaticValue));
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
@@ -349,7 +349,7 @@ namespace Artemis.Core
|
||||
RightPath?.Save();
|
||||
Entity.RightPath = RightPath?.Entity;
|
||||
|
||||
Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue, Constants.JsonConvertSettings);
|
||||
Entity.RightStaticValue = CoreJson.SerializeObject(RightStaticValue);
|
||||
|
||||
if (Operator?.Plugin != null)
|
||||
{
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -74,7 +73,7 @@ namespace Artemis.Core
|
||||
Entity.Condition = Condition.Entity;
|
||||
Condition.Save();
|
||||
|
||||
Entity.Value = JsonConvert.SerializeObject(Value, Constants.JsonConvertSettings);
|
||||
Entity.Value = CoreJson.SerializeObject(Value);
|
||||
Entity.Order = Order;
|
||||
}
|
||||
|
||||
@@ -88,7 +87,7 @@ namespace Artemis.Core
|
||||
? new DataModelConditionGroup(null, Entity.Condition)
|
||||
: new DataModelConditionGroup(null);
|
||||
|
||||
Value = (Entity.Value == null ? default : JsonConvert.DeserializeObject<TProperty>(Entity.Value, Constants.JsonConvertSettings))!;
|
||||
Value = (Entity.Value == null ? default : CoreJson.DeserializeObject<TProperty>(Entity.Value))!;
|
||||
Order = Entity.Order;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,30 +112,6 @@ namespace Artemis.Core
|
||||
ValidateParameter();
|
||||
}
|
||||
|
||||
private void ValidateParameter()
|
||||
{
|
||||
if (ModifierType == null)
|
||||
return;
|
||||
|
||||
if (ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
if (ParameterPath == null || !ParameterPath.IsValid)
|
||||
return;
|
||||
|
||||
Type parameterType = ParameterPath.GetPropertyType()!;
|
||||
if (!ModifierType.SupportsType(parameterType, ModifierTypePart.Parameter))
|
||||
UpdateParameterDynamic(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ParameterStaticValue == null)
|
||||
return;
|
||||
|
||||
if (!ModifierType.SupportsType(ParameterStaticValue.GetType(), ModifierTypePart.Parameter))
|
||||
UpdateParameterStatic(null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the parameter of the modifier and makes the modifier dynamic
|
||||
/// </summary>
|
||||
@@ -181,6 +157,30 @@ namespace Artemis.Core
|
||||
ParameterStaticValue = null;
|
||||
}
|
||||
|
||||
private void ValidateParameter()
|
||||
{
|
||||
if (ModifierType == null)
|
||||
return;
|
||||
|
||||
if (ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
if (ParameterPath == null || !ParameterPath.IsValid)
|
||||
return;
|
||||
|
||||
Type parameterType = ParameterPath.GetPropertyType()!;
|
||||
if (!ModifierType.SupportsType(parameterType, ModifierTypePart.Parameter))
|
||||
UpdateParameterDynamic(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ParameterStaticValue == null)
|
||||
return;
|
||||
|
||||
if (!ModifierType.SupportsType(ParameterStaticValue.GetType(), ModifierTypePart.Parameter))
|
||||
UpdateParameterStatic(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
DataBindingModifierTypeStore.DataBindingModifierAdded += DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||
@@ -208,9 +208,9 @@ namespace Artemis.Core
|
||||
|
||||
try
|
||||
{
|
||||
staticValue = parameterType != null
|
||||
? JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType, Constants.JsonConvertSettings)
|
||||
: JsonConvert.DeserializeObject(Entity.ParameterStaticValue, Constants.JsonConvertSettings);
|
||||
staticValue = parameterType != null
|
||||
? CoreJson.DeserializeObject(Entity.ParameterStaticValue, parameterType)
|
||||
: CoreJson.DeserializeObject(Entity.ParameterStaticValue);
|
||||
}
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
@@ -252,7 +252,7 @@ namespace Artemis.Core
|
||||
ParameterPath?.Save();
|
||||
Entity.ParameterPath = ParameterPath?.Entity;
|
||||
|
||||
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue, Constants.JsonConvertSettings);
|
||||
Entity.ParameterStaticValue = CoreJson.SerializeObject(ParameterStaticValue);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -122,9 +122,7 @@ namespace Artemis.Core
|
||||
if (Parent == null)
|
||||
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");
|
||||
|
||||
FolderEntity entityCopy = JsonConvert.DeserializeObject<FolderEntity>(
|
||||
JsonConvert.SerializeObject(FolderEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
|
||||
)!;
|
||||
FolderEntity entityCopy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity, true), true)!;
|
||||
entityCopy.Id = Guid.NewGuid();
|
||||
entityCopy.Name += " - Copy";
|
||||
|
||||
|
||||
@@ -123,9 +123,7 @@ namespace Artemis.Core
|
||||
if (Parent == null)
|
||||
throw new ArtemisCoreException("Cannot create a copy of a layer without a parent");
|
||||
|
||||
LayerEntity entityCopy = JsonConvert.DeserializeObject<LayerEntity>(
|
||||
JsonConvert.SerializeObject(LayerEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
|
||||
)!;
|
||||
LayerEntity entityCopy = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(LayerEntity, true), true)!;
|
||||
entityCopy.Id = Guid.NewGuid();
|
||||
entityCopy.Name += " - Copy";
|
||||
|
||||
|
||||
@@ -208,9 +208,8 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("LayerProperty");
|
||||
|
||||
string json = JsonConvert.SerializeObject(DefaultValue, Constants.JsonConvertTypedSettings);
|
||||
|
||||
SetCurrentValue(JsonConvert.DeserializeObject<T>(json), time);
|
||||
string json = CoreJson.SerializeObject(DefaultValue, true);
|
||||
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!, time);
|
||||
}
|
||||
|
||||
private void ReapplyUpdate()
|
||||
@@ -512,7 +511,7 @@ namespace Artemis.Core
|
||||
try
|
||||
{
|
||||
if (Entity.Value != null)
|
||||
BaseValue = JsonConvert.DeserializeObject<T>(Entity.Value, Constants.JsonConvertSettings)!;
|
||||
BaseValue = CoreJson.DeserializeObject<T>(Entity.Value)!;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@@ -528,7 +527,7 @@ namespace Artemis.Core
|
||||
_keyframes.AddRange(Entity.KeyframeEntities
|
||||
.Where(k => k.Position <= ProfileElement.Timeline.Length)
|
||||
.Select(k => new LayerPropertyKeyframe<T>(
|
||||
JsonConvert.DeserializeObject<T>(k.Value, Constants.JsonConvertSettings)!, k.Position, (Easings.Functions) k.EasingFunction, this
|
||||
CoreJson.DeserializeObject<T>(k.Value)!, k.Position, (Easings.Functions) k.EasingFunction, this
|
||||
))
|
||||
);
|
||||
}
|
||||
@@ -557,12 +556,12 @@ namespace Artemis.Core
|
||||
if (!_isInitialized)
|
||||
throw new ArtemisCoreException("Layer property is not yet initialized");
|
||||
|
||||
Entity.Value = JsonConvert.SerializeObject(BaseValue, Constants.JsonConvertSettings);
|
||||
Entity.Value = CoreJson.SerializeObject(BaseValue);
|
||||
Entity.KeyframesEnabled = KeyframesEnabled;
|
||||
Entity.KeyframeEntities.Clear();
|
||||
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
|
||||
{
|
||||
Value = JsonConvert.SerializeObject(k.Value, Constants.JsonConvertSettings),
|
||||
Value = CoreJson.SerializeObject(k.Value),
|
||||
Position = k.Position,
|
||||
EasingFunction = (int) k.EasingFunction
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user