1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Datamodel - Added basic infrastructure

This commit is contained in:
SpoinkyNL 2020-04-26 17:30:43 +02:00
parent dad7591af5
commit 349e0a2c41
23 changed files with 206 additions and 43 deletions

View File

@ -56,4 +56,7 @@
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Groups.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Attributes\" />
</ItemGroup>
</Project>

View File

@ -6,7 +6,7 @@ using Artemis.Core.Annotations;
using SkiaSharp;
using Stylet;
namespace Artemis.Core.Models.Profile
namespace Artemis.Core.Models.Profile.Colors
{
public class ColorGradient : INotifyPropertyChanged
{
@ -88,28 +88,4 @@ namespace Artemis.Core.Models.Profile
#endregion
}
public class ColorGradientStop : INotifyPropertyChanged
{
public ColorGradientStop(SKColor color, float position)
{
Color = color;
Position = position;
}
public SKColor Color { get; set; }
public float Position { get; set; }
#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}

View File

@ -0,0 +1,31 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Artemis.Core.Annotations;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.Colors
{
public class ColorGradientStop : INotifyPropertyChanged
{
public ColorGradientStop(SKColor color, float position)
{
Color = color;
Position = position;
}
public SKColor Color { get; set; }
public float Position { get; set; }
#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
using System;
using System.Linq.Expressions;
using Artemis.Core.Plugins.Abstract.DataModels;
namespace Artemis.Core.Models.Profile.Conditions
{
public class LayerCondition
{
public Expression<Func<DataModel, bool>> ExpressionTree { get; set; }
}
}

View File

@ -0,0 +1,43 @@
using System;
namespace Artemis.Core.Plugins.Abstract.DataModels.Attributes
{
[AttributeUsage(System.AttributeTargets.Property)]
public class DataModelPropertyAttribute : Attribute
{
/// <summary>
/// Gets or sets the user-friendly name for this property, shown in the UI.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the user-friendly description for this property, shown in the UI.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Gets or sets the an optional input prefix to show before input elements in the UI.
/// </summary>
public string InputPrefix { get; set; }
/// <summary>
/// Gets or sets an optional input affix to show behind input elements in the UI.
/// </summary>
public string InputAffix { get; set; }
/// <summary>
/// Gets or sets an optional maximum input value, only enforced in the UI.
/// </summary>
public object MaxInputValue { get; set; }
/// <summary>
/// Gets or sets the input drag step size, used in the UI.
/// </summary>
public float InputStepSize { get; set; }
/// <summary>
/// Gets or sets an optional minimum input value, only enforced in the UI.
/// </summary>
public object MinInputValue { get; set; }
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Core.Plugins.Exceptions;
using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract.DataModels
{
public abstract class DataModel
{
private static readonly List<Type> SupportedTypes = new List<Type>
{
typeof(bool),
typeof(byte),
typeof(decimal),
typeof(double),
typeof(float),
typeof(int),
typeof(long),
typeof(string),
typeof(SKColor),
typeof(SKPoint)
};
protected DataModel(Module module)
{
Module = module;
Validate();
}
public Module Module { get; }
/// <summary>
/// Recursively validates the current datamodel, ensuring all properties annotated with
/// <see cref="DataModelPropertyAttribute" /> are of supported types.
/// </summary>
/// <returns></returns>
public bool Validate()
{
return ValidateType(GetType());
}
private bool ValidateType(Type type)
{
foreach (var propertyInfo in type.GetProperties())
{
var dataModelPropertyAttribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
if (dataModelPropertyAttribute == null)
continue;
// If the a nested datamodel, ensure the properties on there are valid
if (propertyInfo.PropertyType == typeof(DataModel))
ValidateType(propertyInfo.PropertyType);
else if (!SupportedTypes.Contains(propertyInfo.PropertyType))
{
// Show a useful error for plugin devs
throw new ArtemisPluginException(Module.PluginInfo,
$"Plugin datamodel contains property of unsupported type {propertyInfo.PropertyType.Name}. \r\n\r\n" +
$"Property name: {propertyInfo.Name}\r\n" +
$"Property declared on: {propertyInfo.DeclaringType?.Name ?? "-"} \r\n\r\n" +
$"Supported properties:\r\n{string.Join("\r\n", SupportedTypes.Select(t => $" - {t.Name}"))}");
}
}
return true;
}
}
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using SkiaSharp;
@ -27,6 +28,11 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary>
public string DisplayIcon { get; set; }
/// <summary>
/// The optional datamodel driving this module
/// </summary>
public DataModel DataModel { get; set; }
/// <summary>
/// Whether or not this module expands upon the main data model. If set to true any data in main data model can be
/// accessed by profiles in this module

View File

@ -1,12 +0,0 @@
namespace Artemis.Core.Plugins.Abstract
{
public abstract class ModuleDataModel
{
protected ModuleDataModel(Module module)
{
Module = module;
}
public Module Module { get; }
}
}

View File

@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Shared.Annotations;
using Artemis.UI.Shared.Services.Interfaces;

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Windows.Data;
using System.Windows.Media;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using SkiaSharp;
using Stylet;

View File

@ -1,4 +1,5 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Shared.Screens.GradientEditor;
namespace Artemis.UI.Shared.Ninject.Factories

View File

@ -6,6 +6,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Shared.Utilities;
using Stylet;

View File

@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Shared.Services.Dialog;
using Artemis.UI.Shared.Utilities;
using Stylet;

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Shared.Screens.GradientEditor;
using Artemis.UI.Shared.Services.Interfaces;

View File

@ -1,4 +1,5 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
namespace Artemis.UI.Shared.Services.Interfaces
{

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Artemis.Core.Models.Profile.Conditions;
using Artemis.Core.Ninject;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Ninject;
@ -33,6 +34,8 @@ namespace Artemis.UI
protected override void Launch()
{
var test = new LayerCondition();
StartupArguments = Args.ToList();
var logger = Kernel.Get<ILogger>();

View File

@ -1,5 +1,6 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract;
using Artemis.UI.Screens.Module;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
using Artemis.Core.Utilities;
using Artemis.UI.Services.Interfaces;
using Stylet;

View File

@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp;

View File

@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces;

View File

@ -1,15 +1,35 @@
using Artemis.Core.Attributes;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using SkiaSharp;
namespace Artemis.Plugins.Modules.General
{
public class GeneralDataModel : ModuleDataModel
public class GeneralDataModel : DataModel
{
public GeneralDataModel(Module module) : base(module)
{
}
[DataModelProperty(DisplayName = "Unique boolean")]
public bool PropertyUniqueToThisDm { get; set; }
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
public string TestString { get; set; }
[DataModelProperty(Name = "A test boolean", Description = "This is a test boolean that's not of any use outside testing!")]
public bool TestBoolean { get; set; }
[DataModelProperty(Name = "Player info", Description = "[TEST] Contains information about the player")]
public PlayerInfo PlayerInfo { get; set; }
}
public class PlayerInfo
{
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
public string TestString { get; set; }
[DataModelProperty(Name = "A test boolean", Description = "This is a test boolean that's not of any use outside testing!")]
public bool TestBoolean { get; set; }
[DataModelProperty()]
public SKRect SkRect { get; set; }
}
}

View File

@ -17,10 +17,11 @@ namespace Artemis.Plugins.Modules.General
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsMainDataModel = true;
DataModel = new GeneralDataModel(this);
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
}
public override void EnablePlugin()
{
}