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

Datamodel - WIP stuff, need this on a diff. PC

This commit is contained in:
SpoinkyNL 2020-06-23 22:49:27 +02:00
parent 920aea6695
commit 2b7a507725
23 changed files with 392 additions and 161 deletions

View File

@ -10,13 +10,25 @@ namespace Artemis.Core.Models.Profile.Colors
{ {
public class ColorGradient : INotifyPropertyChanged public class ColorGradient : INotifyPropertyChanged
{ {
private float _rotation;
public ColorGradient() public ColorGradient()
{ {
Stops = new BindableCollection<ColorGradientStop>(); Stops = new BindableCollection<ColorGradientStop>();
} }
public BindableCollection<ColorGradientStop> Stops { get; } public BindableCollection<ColorGradientStop> Stops { get; }
public float Rotation { get; set; }
public float Rotation
{
get => _rotation;
set
{
if (value.Equals(_rotation)) return;
_rotation = value;
OnPropertyChanged();
}
}
public SKColor[] GetColorsArray() public SKColor[] GetColorsArray()
{ {

View File

@ -7,14 +7,36 @@ namespace Artemis.Core.Models.Profile.Colors
{ {
public class ColorGradientStop : INotifyPropertyChanged public class ColorGradientStop : INotifyPropertyChanged
{ {
private SKColor _color;
private float _position;
public ColorGradientStop(SKColor color, float position) public ColorGradientStop(SKColor color, float position)
{ {
Color = color; Color = color;
Position = position; Position = position;
} }
public SKColor Color { get; set; } public SKColor Color
public float Position { get; set; } {
get => _color;
set
{
if (value.Equals(_color)) return;
_color = value;
OnPropertyChanged();
}
}
public float Position
{
get => _position;
set
{
if (value.Equals(_position)) return;
_position = value;
OnPropertyChanged();
}
}
#region PropertyChanged #region PropertyChanged

View File

@ -13,8 +13,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI. /// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI.
/// <para> /// <para>
/// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will /// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will
/// initialize /// initialize these for you.
/// these for you.
/// </para> /// </para>
/// </summary> /// </summary>
/// <typeparam name="T">The type of property encapsulated in this layer property</typeparam> /// <typeparam name="T">The type of property encapsulated in this layer property</typeparam>

View File

@ -44,7 +44,7 @@ namespace Artemis.Core.Models.Profile
public LayerPropertyGroup Parent { get; internal set; } public LayerPropertyGroup Parent { get; internal set; }
/// <summary> /// <summary>
/// Gets whether this property group's properties are all initialized /// Gets whether this property groups properties are all initialized
/// </summary> /// </summary>
public bool PropertiesInitialized { get; private set; } public bool PropertiesInitialized { get; private set; }

View File

@ -0,0 +1,40 @@
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
namespace Artemis.Core.Plugins.Abstract
{
/// <summary>
/// Allows you to expand the application-wide datamodel
/// </summary>
public abstract class BaseDataModelExpansion<T> : BaseDataModelExpansion where T : DataModel
{
/// <summary>
/// The data model driving this module
/// </summary>
public T DataModel
{
get => (T) InternalDataModel;
internal set => InternalDataModel = value;
}
}
/// <summary>
/// For internal use only, to implement your own layer property type, extend <see cref="BaseDataModelExpansion{T}" />
/// instead.
/// </summary>
public abstract class BaseDataModelExpansion : Plugin
{
internal DataModel InternalDataModel { get; set; }
public abstract void Update(double deltaTime);
/// <summary>
/// Override to provide your own data model description. By default this returns a description matching your plugin
/// name and description
/// </summary>
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description};
}
}
}

View File

@ -1,11 +0,0 @@
namespace Artemis.Core.Plugins.Abstract
{
/// <inheritdoc />
/// <summary>
/// Allows you to expand the application-wide datamodel
/// </summary>
public abstract class DataModelExpansion : Plugin
{
public abstract void Update(double deltaTime);
}
}

View File

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes; using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract.DataModels namespace Artemis.Core.Plugins.Abstract.DataModels
@ -23,39 +25,63 @@ namespace Artemis.Core.Plugins.Abstract.DataModels
typeof(SKPoint) typeof(SKPoint)
}; };
protected DataModel(Module module) /// <summary>
{ /// Gets the plugin info this data model belongs to
Module = module; /// </summary>
Validate(); public PluginInfo PluginInfo { get; internal set; }
}
public Module Module { get; }
/// <summary> /// <summary>
/// Recursively validates the current datamodel, ensuring all properties annotated with /// Gets whether this data model is initialized
/// <see cref="DataModelPropertyAttribute" /> are of supported types.
/// </summary> /// </summary>
/// <returns></returns> public bool Initialized { get; private set; }
public bool Validate()
/// <summary>
/// Gets the <see cref="DataModelPropertyAttribute" /> describing this data model
/// </summary>
public DataModelPropertyAttribute DataModelDescription { get; internal set; }
/// <summary>
/// If found on this type, returns the <see cref="DataModelPropertyAttribute" /> for the provided property name
/// </summary>
/// <param name="propertyName">The name of the property on to look for</param>
public DataModelPropertyAttribute GetPropertyAttribute(string propertyName)
{ {
return ValidateType(GetType()); var propertyInfo = GetType().GetProperty(propertyName);
if (propertyInfo == null)
return null;
return (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
} }
private bool ValidateType(Type type) internal void Initialize()
{ {
foreach (var propertyInfo in type.GetProperties()) // Doubt this will happen but let's make sure
if (Initialized)
throw new ArtemisCoreException("Data model already initialized, wut");
foreach (var propertyInfo in GetType().GetProperties())
{ {
var dataModelPropertyAttribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute)); var dataModelPropertyAttribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
if (dataModelPropertyAttribute == null) if (dataModelPropertyAttribute == null)
continue; continue;
// If the a nested datamodel, ensure the properties on there are valid // If the a nested datamodel create an instance and initialize it
if (typeof(DataModel).IsAssignableFrom(propertyInfo.PropertyType)) if (typeof(DataModel).IsAssignableFrom(propertyInfo.PropertyType))
ValidateType(propertyInfo.PropertyType); {
var instance = (DataModel) Activator.CreateInstance(propertyInfo.PropertyType, true);
if (instance == null)
throw new ArtemisCoreException($"Failed to create instance of child datamodel at {propertyInfo.Name}");
instance.PluginInfo = PluginInfo;
instance.DataModelDescription = dataModelPropertyAttribute;
instance.Initialize();
propertyInfo.SetValue(this, instance);
}
else if (!SupportedTypes.Contains(propertyInfo.PropertyType)) else if (!SupportedTypes.Contains(propertyInfo.PropertyType))
{ {
// Show a useful error for plugin devs // Show a useful error for plugin devs
throw new ArtemisPluginException(Module.PluginInfo, throw new ArtemisPluginException(PluginInfo,
$"Plugin datamodel contains property of unsupported type {propertyInfo.PropertyType.Name}. \r\n\r\n" + $"Plugin datamodel contains property of unsupported type {propertyInfo.PropertyType.Name}. \r\n\r\n" +
$"Property name: {propertyInfo.Name}\r\n" + $"Property name: {propertyInfo.Name}\r\n" +
$"Property declared on: {propertyInfo.DeclaringType?.Name ?? "-"} \r\n\r\n" + $"Property declared on: {propertyInfo.DeclaringType?.Name ?? "-"} \r\n\r\n" +
@ -63,7 +89,7 @@ namespace Artemis.Core.Plugins.Abstract.DataModels
} }
} }
return true; Initialized = true;
} }
} }
} }

View File

@ -1,17 +1,65 @@
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract.DataModels; using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Core.Plugins.Abstract.ViewModels; using Artemis.Core.Plugins.Abstract.ViewModels;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
/// <inheritdoc /> /// <summary>
/// Allows you to add support for new games/applications while utilizing your own data model
/// </summary>
public abstract class Module<T> : Module where T : DataModel
{
/// <summary>
/// The data model driving this module
/// </summary>
public T DataModel
{
get => (T) InternalDataModel;
internal set => InternalDataModel = value;
}
/// <summary>
/// Gets or sets whether this module must also expand the main data model
/// <para>
/// Note: If expanding the main data model is all you want your plugin to do, create a
/// <see cref="BaseDataModelExpansion" /> plugin instead.
/// </para>
/// </summary>
public bool ExpandsDataModel
{
get => InternalExpandsMainDataModel;
set => InternalExpandsMainDataModel = value;
}
/// <summary>
/// Override to provide your own data model description. By default this returns a description matching your plugin
/// name and description
/// </summary>
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description};
}
internal override DataModelPropertyAttribute InternalGetDataModelDescription()
{
return GetDataModelDescription();
}
}
/// <summary> /// <summary>
/// Allows you to add support for new games/applications /// Allows you to add support for new games/applications
/// </summary> /// </summary>
public abstract class Module : Plugin public abstract class Module : Plugin
{ {
internal DataModel InternalDataModel { get; set; }
internal bool InternalExpandsMainDataModel { get; set; }
/// <summary> /// <summary>
/// The modules display name that's shown in the menu /// The modules display name that's shown in the menu
/// </summary> /// </summary>
@ -23,17 +71,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public string DisplayIcon { get; set; } 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
/// </summary>
public bool ExpandsMainDataModel { get; protected set; }
/// <summary> /// <summary>
/// Called each frame when the module must update /// Called each frame when the module must update
/// </summary> /// </summary>
@ -54,5 +91,10 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public abstract IEnumerable<ModuleViewModel> GetViewModels(); public abstract IEnumerable<ModuleViewModel> GetViewModels();
internal virtual DataModelPropertyAttribute InternalGetDataModelDescription()
{
return null;
}
} }
} }

View File

@ -4,7 +4,6 @@ using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// This is the base plugin type, use the other interfaces such as Module to create plugins /// This is the base plugin type, use the other interfaces such as Module to create plugins
/// </summary> /// </summary>

View File

@ -2,10 +2,58 @@
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
/// <summary>
/// Allows you to add support for new games/applications while utilizing Artemis' profile engine and your own data model
/// </summary>
public abstract class ProfileModule<T> : ProfileModule where T : DataModel
{
/// <summary>
/// The data model driving this module
/// </summary>
public T DataModel
{
get => (T)InternalDataModel;
internal set => InternalDataModel = value;
}
/// <summary>
/// Gets or sets whether this module must also expand the main data model
/// <para>
/// Note: If expanding the main data model is all you want your plugin to do, create a
/// <see cref="BaseDataModelExpansion" /> plugin instead.
/// </para>
/// </summary>
public bool ExpandsDataModel
{
get => InternalExpandsMainDataModel;
set => InternalExpandsMainDataModel = value;
}
/// <summary>
/// Override to provide your own data model description. By default this returns a description matching your plugin
/// name and description
/// </summary>
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute { Name = PluginInfo.Name, Description = PluginInfo.Description };
}
internal override DataModelPropertyAttribute InternalGetDataModelDescription()
{
return GetDataModelDescription();
}
}
/// <summary>
/// Allows you to add support for new games/applications while utilizing Artemis' profile engine
/// </summary>
public abstract class ProfileModule : Module public abstract class ProfileModule : Module
{ {
public Profile ActiveProfile { get; private set; } public Profile ActiveProfile { get; private set; }

View File

@ -6,6 +6,7 @@ using Artemis.Core.Events;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.JsonConverters; using Artemis.Core.JsonConverters;
using Artemis.Core.Ninject; using Artemis.Core.Ninject;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
@ -24,13 +25,14 @@ namespace Artemis.Core.Services
/// </summary> /// </summary>
public class CoreService : ICoreService public class CoreService : ICoreService
{ {
private readonly Stopwatch _frameStopWatch;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly PluginSetting<LogEventLevel> _loggingLevel; private readonly PluginSetting<LogEventLevel> _loggingLevel;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly IProfileService _profileService; private readonly IProfileService _profileService;
private readonly IRgbService _rgbService; private readonly IRgbService _rgbService;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
private readonly Stopwatch _frameStopWatch; private List<BaseDataModelExpansion> _dataModelExpansions;
private List<Module> _modules; private List<Module> _modules;
// ReSharper disable once UnusedParameter.Local - Storage migration service is injected early to ensure it runs before anything else // ReSharper disable once UnusedParameter.Local - Storage migration service is injected early to ensure it runs before anything else
@ -48,9 +50,9 @@ namespace Artemis.Core.Services
_rgbService.Surface.Updated += SurfaceOnUpdated; _rgbService.Surface.Updated += SurfaceOnUpdated;
_loggingLevel.SettingChanged += (sender, args) => ApplyLoggingLevel(); _loggingLevel.SettingChanged += (sender, args) => ApplyLoggingLevel();
_modules = _pluginService.GetPluginsOfType<Module>(); _pluginService.PluginEnabled += (sender, args) => UpdatePluginCache();
_pluginService.PluginEnabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>(); _pluginService.PluginDisabled += (sender, args) => UpdatePluginCache();
_pluginService.PluginDisabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>(); UpdatePluginCache();
_frameStopWatch = new Stopwatch(); _frameStopWatch = new Stopwatch();
@ -58,7 +60,7 @@ namespace Artemis.Core.Services
} }
public TimeSpan FrameTime { get; private set; } public TimeSpan FrameTime { get; private set; }
public bool ModuleUpdatingDisabled { get; set; } public bool PluginUpdatingDisabled { get; set; }
public bool ModuleRenderingDisabled { get; set; } public bool ModuleRenderingDisabled { get; set; }
public void Dispose() public void Dispose()
@ -103,6 +105,12 @@ namespace Artemis.Core.Services
FrameRendered?.Invoke(this, e); FrameRendered?.Invoke(this, e);
} }
private void UpdatePluginCache()
{
_modules = _pluginService.GetPluginsOfType<Module>();
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>();
}
private void ConfigureJsonConvert() private void ConfigureJsonConvert()
{ {
JsonConvert.DefaultSettings = () => new JsonSerializerSettings JsonConvert.DefaultSettings = () => new JsonSerializerSettings
@ -125,8 +133,15 @@ namespace Artemis.Core.Services
try try
{ {
_frameStopWatch.Restart(); _frameStopWatch.Restart();
if (!ModuleUpdatingDisabled && _modules != null) if (!PluginUpdatingDisabled)
{ {
lock (_dataModelExpansions)
{
// Update all active modules
foreach (var dataModelExpansion in _dataModelExpansions)
dataModelExpansion.Update(args.DeltaTime);
}
lock (_modules) lock (_modules)
{ {
// Update all active modules // Update all active modules

View File

@ -0,0 +1,112 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Models;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Services
{
/// <summary>
/// Provides access to the main data model
/// </summary>
public class DataModelService : IDataModelService
{
private readonly IPluginService _pluginService;
private readonly List<DataModel> _dataModelExpansions;
internal DataModelService(IPluginService pluginService)
{
_pluginService = pluginService;
_dataModelExpansions = new List<DataModel>();
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
}
public ReadOnlyCollection<DataModel> DataModelExpansions
{
get
{
lock (_dataModelExpansions)
{
return new List<DataModel>(_dataModelExpansions).AsReadOnly();
}
}
}
public void AddExpansion(DataModel dataModelExpansion)
{
lock (_dataModelExpansions)
{
_dataModelExpansions.Add(dataModelExpansion);
// TODO SpoinkyNL 3-3-2018: Initialize the expansion and fire an event
}
}
public void RemoveExpansion(DataModel dataModelExpansion)
{
lock (_dataModelExpansions)
{
if (!_dataModelExpansions.Contains(dataModelExpansion))
throw new ArtemisCoreException("Cannot remove a data model expansion that wasn't previously added.");
// TODO SpoinkyNL 3-3-2018: Dispose the expansion and fire an event
_dataModelExpansions.Remove(dataModelExpansion);
}
}
public DataModelDescription GetMainDataModelDescription()
{
var dataModelDescription = new DataModelDescription();
return dataModelDescription;
}
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
{
if (!module.InternalDataModel.Initialized)
{
module.InternalDataModel.DataModelDescription = module.InternalGetDataModelDescription();
if (module.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
module.InternalDataModel.Initialize();
}
_dataModelExpansions.Add(module.InternalDataModel);
}
else if (e.PluginInfo.Instance is BaseDataModelExpansion dataModelExpansion)
{
if (!dataModelExpansion.InternalDataModel.Initialized)
{
dataModelExpansion.InternalDataModel.DataModelDescription = dataModelExpansion.GetDataModelDescription();
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
dataModelExpansion.InternalDataModel.Initialize();
}
_dataModelExpansions.Add(dataModelExpansion.InternalDataModel);
}
}
private void PluginServiceOnPluginDisabled(object sender, PluginEventArgs e)
{
// Remove all data models related to the plugin
lock (_dataModelExpansions)
{
var toRemove = _dataModelExpansions.Where(d => d.PluginInfo == e.PluginInfo).ToList();
foreach (var dataModel in toRemove)
_dataModelExpansions.Remove(dataModel);
}
}
}
}

View File

@ -18,7 +18,7 @@ namespace Artemis.Core.Services.Interfaces
/// <summary> /// <summary>
/// Gets or sets whether modules are updated each frame by calling their Update method /// Gets or sets whether modules are updated each frame by calling their Update method
/// </summary> /// </summary>
bool ModuleUpdatingDisabled { get; set; } bool PluginUpdatingDisabled { get; set; }
/// <summary> /// <summary>
/// Gets or sets whether modules are rendered each frame by calling their Render method /// Gets or sets whether modules are rendered each frame by calling their Render method

View File

@ -1,27 +1,21 @@
using Artemis.Core.Models; using Artemis.Core.Models;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract.DataModels;
namespace Artemis.Core.Services.Interfaces namespace Artemis.Core.Services.Interfaces
{ {
public interface IMainDataModelService : IArtemisService public interface IDataModelService : IArtemisService
{ {
/// <summary>
/// Called each frame when the main data model must update
/// </summary>
/// <param name="deltaTime">Time since the last update</param>
void Update(double deltaTime);
/// <summary> /// <summary>
/// Add an expansion to the datamodel to be available for use after the next update /// Add an expansion to the datamodel to be available for use after the next update
/// </summary> /// </summary>
/// <param name="dataModelExpansion"></param> /// <param name="baseDataModelExpansion"></param>
void AddExpansion(DataModelExpansion dataModelExpansion); void AddExpansion(DataModel baseDataModelExpansion);
/// <summary> /// <summary>
/// Remove a previously added expansion so that it is no longer available and updated /// Remove a previously added expansion so that it is no longer available and updated
/// </summary> /// </summary>
/// <param name="dataModelExpansion"></param> /// <param name="baseDataModelExpansion"></param>
void RemoveExpansion(DataModelExpansion dataModelExpansion); void RemoveExpansion(DataModel baseDataModelExpansion);
/// <summary> /// <summary>
/// Generates a data model description for the main datamodel including all it's expansions /// Generates a data model description for the main datamodel including all it's expansions

View File

@ -1,71 +0,0 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Exceptions;
using Artemis.Core.Models;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Services
{
/// <summary>
/// Provides access to the main data model
/// </summary>
public class MainDataModelService : IMainDataModelService
{
private readonly List<DataModelExpansion> _dataModelExpansions;
internal MainDataModelService()
{
_dataModelExpansions = new List<DataModelExpansion>();
}
public ReadOnlyCollection<DataModelExpansion> DataModelExpansions
{
get
{
lock (_dataModelExpansions)
{
return _dataModelExpansions.AsReadOnly();
}
}
}
public void Update(double deltaTime)
{
lock (_dataModelExpansions)
{
// Update all expansions
foreach (var expansion in _dataModelExpansions)
expansion.Update(deltaTime);
}
}
public void AddExpansion(DataModelExpansion dataModelExpansion)
{
lock (_dataModelExpansions)
{
_dataModelExpansions.Add(dataModelExpansion);
// TODO SpoinkyNL 3-3-2018: Initialize the expansion and fire an event
}
}
public void RemoveExpansion(DataModelExpansion dataModelExpansion)
{
lock (_dataModelExpansions)
{
if (!_dataModelExpansions.Contains(dataModelExpansion))
throw new ArtemisCoreException("Cannot remove a data model expansion that wasn't previously added.");
// TODO SpoinkyNL 3-3-2018: Dispose the expansion and fire an event
_dataModelExpansions.Remove(dataModelExpansion);
}
}
public DataModelDescription GetMainDataModelDescription()
{
var dataModelDescription = new DataModelDescription();
return dataModelDescription;
}
}
}

View File

@ -4,9 +4,9 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp> <ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp>
<AssemblyTitle>Artemis.UI.Shared</AssemblyTitle> <AssemblyTitle>Artemis.UI.Shared</AssemblyTitle>
<Company>HP Inc.</Company> <Company>Artemis.UI.Shared</Company>
<Product>Artemis.UI.Shared</Product> <Product>Artemis.UI.Shared</Product>
<Copyright>Copyright © HP Inc. 2019</Copyright> <Copyright>Copyright © Robert Beekman - 2020</Copyright>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.3</LangVersion> <LangVersion>7.3</LangVersion>
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath> <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
@ -27,6 +27,7 @@
<NrtRemoveTagV>true</NrtRemoveTagV> <NrtRemoveTagV>true</NrtRemoveTagV>
<NrtRequiredVcs>git</NrtRequiredVcs> <NrtRequiredVcs>git</NrtRequiredVcs>
<NrtShowRevision>true</NrtShowRevision> <NrtShowRevision>true</NrtShowRevision>
<Version>2.0.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.0.1" /> <PackageReference Include="AvalonEdit" Version="6.0.1" />

View File

@ -15,6 +15,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
{ {
private readonly List<ColorGradientStop> _originalStops; private readonly List<ColorGradientStop> _originalStops;
private ColorStopViewModel _selectedColorStopViewModel; private ColorStopViewModel _selectedColorStopViewModel;
private double _previewWidth;
public GradientEditorViewModel(ColorGradient colorGradient) public GradientEditorViewModel(ColorGradient colorGradient)
{ {
@ -41,7 +42,12 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
public bool HasSelectedColorStopViewModel => SelectedColorStopViewModel != null; public bool HasSelectedColorStopViewModel => SelectedColorStopViewModel != null;
public ColorGradient ColorGradient { get; } public ColorGradient ColorGradient { get; }
public double PreviewWidth { get; set; }
public double PreviewWidth
{
get => _previewWidth;
set => SetAndNotify(ref _previewWidth, value);
}
public void AddColorStop(object sender, MouseEventArgs e) public void AddColorStop(object sender, MouseEventArgs e)
{ {

View File

@ -201,12 +201,12 @@ namespace Artemis.UI.Shared.Services
public void StopRegularRender() public void StopRegularRender()
{ {
_coreService.ModuleUpdatingDisabled = true; _coreService.PluginUpdatingDisabled = true;
} }
public void ResumeRegularRender() public void ResumeRegularRender()
{ {
_coreService.ModuleUpdatingDisabled = false; _coreService.PluginUpdatingDisabled = false;
} }
protected virtual void OnSelectedProfileChanged(ProfileElementEventArgs e) protected virtual void OnSelectedProfileChanged(ProfileElementEventArgs e)

View File

@ -80,7 +80,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
{ {
var result = await DialogService.ShowDialog<ProfileCreateViewModel>(); var result = await DialogService.ShowDialog<ProfileCreateViewModel>();
if (result is string name) if (result is string name)
CreateProfile(name); {
var newProfile = CreateProfile(name);
SelectedProfile = newProfile;
}
} }
public async Task DeleteActiveProfile() public async Task DeleteActiveProfile()

View File

@ -66,7 +66,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
switch (Plugin) switch (Plugin)
{ {
case DataModelExpansion _: case BaseDataModelExpansion _:
return PackIconKind.TableAdd; return PackIconKind.TableAdd;
case DeviceProvider _: case DeviceProvider _:
return PackIconKind.Devices; return PackIconKind.Devices;

View File

@ -71,7 +71,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artemis.Plugins.LayerBrushe
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LayerEffects", "LayerEffects", "{2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LayerEffects", "LayerEffects", "{2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Plugins.LayerEffects.Filter", "Plugins\Artemis.Plugins.LayerEffects.Filter\Artemis.Plugins.LayerEffects.Filter.csproj", "{62214042-667E-4B29-B64E-1A68CE6FE209}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artemis.Plugins.LayerEffects.Filter", "Plugins\Artemis.Plugins.LayerEffects.Filter\Artemis.Plugins.LayerEffects.Filter.csproj", "{62214042-667E-4B29-B64E-1A68CE6FE209}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataModelExpansions", "DataModelExpansions", "{4E85F6B5-83FB-4830-8787-555103F26ECD}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -275,6 +277,7 @@ Global
{301C3AAA-9F79-46A5-9B9D-86F076C5BDD1} = {A311DC47-42A2-4DD4-B921-50FBF7A33F41} {301C3AAA-9F79-46A5-9B9D-86F076C5BDD1} = {A311DC47-42A2-4DD4-B921-50FBF7A33F41}
{2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC} = {E830A02B-A7E5-4A6B-943F-76B0A542630C} {2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC} = {E830A02B-A7E5-4A6B-943F-76B0A542630C}
{62214042-667E-4B29-B64E-1A68CE6FE209} = {2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC} {62214042-667E-4B29-B64E-1A68CE6FE209} = {2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC}
{4E85F6B5-83FB-4830-8787-555103F26ECD} = {E830A02B-A7E5-4A6B-943F-76B0A542630C}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C203080A-4473-4CC2-844B-F552EA43D66A} SolutionGuid = {C203080A-4473-4CC2-844B-F552EA43D66A}

View File

@ -1,16 +1,10 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes; using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
namespace Artemis.Plugins.Modules.General namespace Artemis.Plugins.Modules.General
{ {
public class GeneralDataModel : DataModel public class GeneralDataModel : DataModel
{ {
public GeneralDataModel(Module module) : base(module)
{
PlayerInfo = new PlayerInfo(module);
}
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")] [DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
public string TestString { get; set; } public string TestString { get; set; }
@ -23,10 +17,6 @@ namespace Artemis.Plugins.Modules.General
public class PlayerInfo : DataModel public class PlayerInfo : DataModel
{ {
public PlayerInfo(Module module) : base(module)
{
}
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")] [DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
public string TestString { get; set; } public string TestString { get; set; }

View File

@ -1,13 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.ViewModels; using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Plugins.Modules.General.ViewModels; using Artemis.Plugins.Modules.General.ViewModels;
namespace Artemis.Plugins.Modules.General namespace Artemis.Plugins.Modules.General
{ {
public class GeneralModule : ProfileModule public class GeneralModule : ProfileModule<GeneralDataModel>
{ {
private readonly PluginSettings _settings; private readonly PluginSettings _settings;
@ -25,8 +26,8 @@ namespace Artemis.Plugins.Modules.General
{ {
DisplayName = "General"; DisplayName = "General";
DisplayIcon = "AllInclusive"; DisplayIcon = "AllInclusive";
ExpandsMainDataModel = true; ExpandsDataModel = true;
DataModel = new GeneralDataModel(this);
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now); var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
} }