Plugins - Moved test data model to a seperate plugin

Core - Moved built-in types to a separate folder and namespace
This commit is contained in:
Robert committed 2020-09-16 13:08:14 +02:00
1 parent 9373d15715
commit 35b3b1d1f6
59 files changed
+350 -131

No files matched your search

@@ -1,4 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cconditions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconditions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconverters/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cproperties/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cplugins/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cprofiles/@EntryIndexedValue">True</s:Boolean>
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class EqualsConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class GreaterThanConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class GreaterThanOrEqualConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class LessThanConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class LessThanOrEqualConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class NotEqualConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringContainsConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringEndsWithConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringEqualsConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringNotContainsConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringNotEqualConditionOperator : ConditionOperator
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringNullConditionOperator : ConditionOperator
{
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class StringStartsWithConditionOperator : ConditionOperator
{
@@ -1,7 +1,6 @@
using System;
using SkiaSharp;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class FloatDataBindingConverter : FloatDataBindingConverter<float>
@@ -1,6 +1,6 @@
using System;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class GeneralDataBindingConverter<T> : DataBindingConverter<T, object> where T : ILayerProperty
@@ -1,6 +1,6 @@
using System;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class IntDataBindingConverter : IntDataBindingConverter<int>
@@ -1,10 +1,16 @@
using SkiaSharp;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class SKColorDataBindingConverter : DataBindingConverter<SKColor, SKColor>
{
public SKColorDataBindingConverter()
{
SupportsInterpolate = true;
SupportsSum = true;
}
/// <inheritdoc />
public override SKColor Sum(SKColor a, SKColor b)
{
@@ -14,7 +20,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override SKColor Interpolate(SKColor a, SKColor b, double progress)
{
return a.Interpolate(b, (float)progress);
return a.Interpolate(b, (float) progress);
}
}
}
}
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class DivideModifierType : DataBindingModifierType
{
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class FloorModifierType : DataBindingModifierType
{
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class MultiplicationModifierType : DataBindingModifierType
{
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
internal class PercentageOfModifierType : DataBindingModifierType
{
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using SkiaSharp;
namespace Artemis.Core.DefaultTypes
{
internal class SKColorSumModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
public override string Description => "Combine with";
public override string Icon => "FormatColorFill";
public override object Apply(object currentValue, object parameterValue)
{
return ((SKColor) currentValue).Sum((SKColor) parameterValue);
}
}
}
@@ -1,4 +1,4 @@
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class ColorGradientLayerProperty : LayerProperty<ColorGradient>
@@ -1,6 +1,6 @@
using System;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class EnumLayerProperty<T> : LayerProperty<T> where T : Enum
@@ -1,4 +1,4 @@
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class FloatLayerProperty : LayerProperty<float>
@@ -1,6 +1,6 @@
using System;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class IntLayerProperty : LayerProperty<int>
@@ -1,4 +1,4 @@
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <summary>
/// A special layer property used to configure the selected layer brush
@@ -1,6 +1,6 @@
using SkiaSharp;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class SKColorLayerProperty : LayerProperty<SKColor>
@@ -1,6 +1,6 @@
using SkiaSharp;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class SKPointLayerProperty : LayerProperty<SKPoint>
@@ -1,6 +1,6 @@
using SkiaSharp;
namespace Artemis.Core
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
public class SKSizeLayerProperty : LayerProperty<SKSize>
@@ -1,70 +0,0 @@
using System;
using SkiaSharp;
namespace Artemis.Core
{
// This is internal because it's mainly a proof-of-concept
internal class SKColorArgbDataBindingConverter : DataBindingConverter<SKColor, byte>
{
private readonly Channel _channel;
public SKColorArgbDataBindingConverter(Channel channel)
{
_channel = channel;
SupportsSum = true;
SupportsInterpolate = true;
}
public override byte Sum(byte a, byte b)
{
return ClampToByte(a + b);
}
public override byte Interpolate(byte a, byte b, double progress)
{
var diff = b - a;
return ClampToByte(a + diff * progress);
}
public override void ApplyValue(byte value)
{
switch (_channel)
{
case Channel.Alpha:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithAlpha(value);
break;
case Channel.Red:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithRed(value);
break;
case Channel.Green:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithGreen(value);
break;
case Channel.Blue:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithBlue(value);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public override byte ConvertFromObject(object source)
{
var saveValue = Convert.ToDouble(source);
return ClampToByte(saveValue);
}
private static byte ClampToByte(double value)
{
return (byte) Math.Clamp(value, 0, 255);
}
public enum Channel
{
Alpha,
Red,
Green,
Blue
}
}
}
@@ -1,4 +1,5 @@
using SkiaSharp;
using Artemis.Core.DefaultTypes;
using SkiaSharp;
namespace Artemis.Core
{
@@ -1,4 +1,5 @@
using SkiaSharp;
using Artemis.Core.DefaultTypes;
using SkiaSharp;
namespace Artemis.Core
{
+10 -10
View File
@@ -165,16 +165,6 @@ namespace Artemis.Core.Modules
/// </param>
public abstract void ModuleDeactivated(bool isOverride);
internal virtual void InternalUpdate(double deltaTime)
{
Update(deltaTime);
}
internal virtual void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo)
{
Render(deltaTime, surface, canvas, canvasInfo);
}
/// <summary>
/// Evaluates the activation requirements following the <see cref="ActivationRequirementMode" /> and returns the result
/// </summary>
@@ -190,6 +180,16 @@ namespace Artemis.Core.Modules
return false;
}
internal virtual void InternalUpdate(double deltaTime)
{
Update(deltaTime);
}
internal virtual void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo)
{
Render(deltaTime, surface, canvas, canvasInfo);
}
internal virtual void Activate(bool isOverride)
{
+14
View File
@@ -39,6 +39,20 @@ namespace Artemis.Core
/// </summary>
public abstract void DisablePlugin();
/// <summary>
/// Registers a timed update that whenever the plugin is enabled calls the provided <paramref name="action" /> at the provided
/// <paramref name="interval" />
/// </summary>
/// <param name="interval">The interval at which the update should occur</param>
/// <param name="action">The action to call every time the interval has passed. The delta time parameter represents the time passed since the last update in seconds</param>
/// <returns>The resulting plugin update registration</returns>
public PluginUpdateRegistration AddTimedUpdate(TimeSpan interval, Action<double> action)
{
if (action == null)
throw new ArgumentNullException(nameof(action));
return new PluginUpdateRegistration(PluginInfo, interval, action);
}
internal void SetEnabled(bool enable, bool isAutoEnable = false)
{
if (enable && !Enabled)
@@ -0,0 +1,102 @@
using System;
using System.Timers;
namespace Artemis.Core
{
/// <summary>
/// Represents a registration for a timed plugin update
/// </summary>
public class PluginUpdateRegistration
{
private DateTime _lastEvent;
private Timer _timer;
internal PluginUpdateRegistration(PluginInfo pluginInfo, TimeSpan interval, Action<double> action)
{
PluginInfo = pluginInfo;
Interval = interval;
Action = action;
PluginInfo.Instance.PluginEnabled += InstanceOnPluginEnabled;
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
if (PluginInfo.Instance.Enabled)
Start();
}
/// <summary>
/// Gets the plugin info of the plugin this registration is associated with
/// </summary>
public PluginInfo PluginInfo { get; }
/// <summary>
/// Gets the interval at which the update should occur
/// </summary>
public TimeSpan Interval { get; }
/// <summary>
/// Gets the action that gets called each time the update event fires
/// </summary>
public Action<double> Action { get; }
/// <summary>
/// Starts calling the <see cref="Action" /> at the configured <see cref="Interval" />
/// <para>Note: Called automatically when the plugin enables</para>
/// </summary>
public void Start()
{
lock (this)
{
if (!PluginInfo.Instance.Enabled)
throw new ArtemisPluginException("Cannot start a timed update for a disabled plugin");
if (_timer != null)
return;
_lastEvent = DateTime.Now;
_timer = new Timer(Interval.TotalMilliseconds);
_timer.Elapsed += TimerOnElapsed;
_timer.Start();
}
}
/// <summary>
/// Stops calling the <see cref="Action" /> at the configured <see cref="Interval" />
/// <para>Note: Called automatically when the plugin disables</para>
/// </summary>
public void Stop()
{
lock (this)
{
if (_timer == null)
return;
_timer.Elapsed -= TimerOnElapsed;
_timer.Stop();
_timer.Dispose();
_timer = null;
}
}
private void TimerOnElapsed(object sender, ElapsedEventArgs e)
{
if (!PluginInfo.Instance.Enabled)
return;
var interval = DateTime.Now - _lastEvent;
_lastEvent = DateTime.Now;
Action(interval.TotalSeconds);
}
private void InstanceOnPluginEnabled(object? sender, EventArgs e)
{
Start();
}
private void InstanceOnPluginDisabled(object? sender, EventArgs e)
{
Stop();
}
}
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DefaultTypes;
namespace Artemis.Core.Services
{
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DefaultTypes;
namespace Artemis.Core.Services
{
@@ -45,6 +46,7 @@ namespace Artemis.Core.Services
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType());
RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SKColorSumModifierType());
}
}
}
@@ -53,7 +53,7 @@ namespace Artemis.Core
if (type == null)
return new List<DataBindingModifierTypeRegistration>(Registrations);
var candidates = Registrations.Where(r => r.DataBindingModifierType.CompatibleTypes.Any(t => t.IsCastableFrom(type))).ToList();
var candidates = Registrations.Where(r => r.DataBindingModifierType.CompatibleTypes.Any(t => t == type)).ToList();
// If there are multiple operators with the same description, use the closest match
foreach (var displayDataBindingModifiers in candidates.GroupBy(r => r.DataBindingModifierType.Description).Where(g => g.Count() > 1).ToList())