diff --git a/src/Artemis.Core/Models/Profile/Colors/ColorGradient.cs b/src/Artemis.Core/Models/Profile/Colors/ColorGradient.cs index bc66fb1ee..4e0274d5b 100644 --- a/src/Artemis.Core/Models/Profile/Colors/ColorGradient.cs +++ b/src/Artemis.Core/Models/Profile/Colors/ColorGradient.cs @@ -10,13 +10,25 @@ namespace Artemis.Core.Models.Profile.Colors { public class ColorGradient : INotifyPropertyChanged { + private float _rotation; + public ColorGradient() { Stops = new BindableCollection(); } public BindableCollection Stops { get; } - public float Rotation { get; set; } + + public float Rotation + { + get => _rotation; + set + { + if (value.Equals(_rotation)) return; + _rotation = value; + OnPropertyChanged(); + } + } public SKColor[] GetColorsArray() { diff --git a/src/Artemis.Core/Models/Profile/Colors/ColorGradientStop.cs b/src/Artemis.Core/Models/Profile/Colors/ColorGradientStop.cs index 7a860da42..abc89947a 100644 --- a/src/Artemis.Core/Models/Profile/Colors/ColorGradientStop.cs +++ b/src/Artemis.Core/Models/Profile/Colors/ColorGradientStop.cs @@ -7,14 +7,36 @@ namespace Artemis.Core.Models.Profile.Colors { public class ColorGradientStop : INotifyPropertyChanged { + private SKColor _color; + private float _position; + public ColorGradientStop(SKColor color, float position) { Color = color; Position = position; } - public SKColor Color { get; set; } - public float Position { get; set; } + public SKColor Color + { + 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 diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs index 82ae2aa34..d5eab15fd 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs @@ -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. /// /// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will - /// initialize - /// these for you. + /// initialize these for you. /// /// /// The type of property encapsulated in this layer property diff --git a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs index e88f62315..76e45c766 100644 --- a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs +++ b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs @@ -44,7 +44,7 @@ namespace Artemis.Core.Models.Profile public LayerPropertyGroup Parent { get; internal set; } /// - /// Gets whether this property group's properties are all initialized + /// Gets whether this property groups properties are all initialized /// public bool PropertiesInitialized { get; private set; } diff --git a/src/Artemis.Core/Plugins/Abstract/BaseDataModelExpansion.cs b/src/Artemis.Core/Plugins/Abstract/BaseDataModelExpansion.cs new file mode 100644 index 000000000..396e0d84a --- /dev/null +++ b/src/Artemis.Core/Plugins/Abstract/BaseDataModelExpansion.cs @@ -0,0 +1,40 @@ +using Artemis.Core.Plugins.Abstract.DataModels; +using Artemis.Core.Plugins.Abstract.DataModels.Attributes; + +namespace Artemis.Core.Plugins.Abstract +{ + /// + /// Allows you to expand the application-wide datamodel + /// + public abstract class BaseDataModelExpansion : BaseDataModelExpansion where T : DataModel + { + /// + /// The data model driving this module + /// + public T DataModel + { + get => (T) InternalDataModel; + internal set => InternalDataModel = value; + } + } + + /// + /// For internal use only, to implement your own layer property type, extend + /// instead. + /// + public abstract class BaseDataModelExpansion : Plugin + { + internal DataModel InternalDataModel { get; set; } + public abstract void Update(double deltaTime); + + /// + /// Override to provide your own data model description. By default this returns a description matching your plugin + /// name and description + /// + /// + public virtual DataModelPropertyAttribute GetDataModelDescription() + { + return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description}; + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs b/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs deleted file mode 100644 index d53253c8f..000000000 --- a/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Artemis.Core.Plugins.Abstract -{ - /// - /// - /// Allows you to expand the application-wide datamodel - /// - public abstract class DataModelExpansion : Plugin - { - public abstract void Update(double deltaTime); - } -} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs b/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs index 372e4191b..107f423f9 100644 --- a/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs +++ b/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Artemis.Core.Exceptions; using Artemis.Core.Plugins.Abstract.DataModels.Attributes; using Artemis.Core.Plugins.Exceptions; +using Artemis.Core.Plugins.Models; using SkiaSharp; namespace Artemis.Core.Plugins.Abstract.DataModels @@ -23,39 +25,63 @@ namespace Artemis.Core.Plugins.Abstract.DataModels typeof(SKPoint) }; - protected DataModel(Module module) - { - Module = module; - Validate(); - } - - public Module Module { get; } + /// + /// Gets the plugin info this data model belongs to + /// + public PluginInfo PluginInfo { get; internal set; } /// - /// Recursively validates the current datamodel, ensuring all properties annotated with - /// are of supported types. + /// Gets whether this data model is initialized /// - /// - public bool Validate() + public bool Initialized { get; private set; } + + /// + /// Gets the describing this data model + /// + public DataModelPropertyAttribute DataModelDescription { get; internal set; } + + /// + /// If found on this type, returns the for the provided property name + /// + /// The name of the property on to look for + 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)); if (dataModelPropertyAttribute == null) 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)) - 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)) { // 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" + $"Property name: {propertyInfo.Name}\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; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/Module.cs b/src/Artemis.Core/Plugins/Abstract/Module.cs index 559fc491b..5ebce30f6 100644 --- a/src/Artemis.Core/Plugins/Abstract/Module.cs +++ b/src/Artemis.Core/Plugins/Abstract/Module.cs @@ -1,17 +1,65 @@ using System.Collections.Generic; using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Abstract.DataModels; +using Artemis.Core.Plugins.Abstract.DataModels.Attributes; using Artemis.Core.Plugins.Abstract.ViewModels; using SkiaSharp; namespace Artemis.Core.Plugins.Abstract { - /// + /// + /// Allows you to add support for new games/applications while utilizing your own data model + /// + public abstract class Module : Module where T : DataModel + { + /// + /// The data model driving this module + /// + public T DataModel + { + get => (T) InternalDataModel; + internal set => InternalDataModel = value; + } + + /// + /// Gets or sets whether this module must also expand the main data model + /// + /// Note: If expanding the main data model is all you want your plugin to do, create a + /// plugin instead. + /// + /// + public bool ExpandsDataModel + { + get => InternalExpandsMainDataModel; + set => InternalExpandsMainDataModel = value; + } + + /// + /// Override to provide your own data model description. By default this returns a description matching your plugin + /// name and description + /// + /// + public virtual DataModelPropertyAttribute GetDataModelDescription() + { + return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description}; + } + + internal override DataModelPropertyAttribute InternalGetDataModelDescription() + { + return GetDataModelDescription(); + } + } + + /// /// Allows you to add support for new games/applications /// public abstract class Module : Plugin { + internal DataModel InternalDataModel { get; set; } + + internal bool InternalExpandsMainDataModel { get; set; } + /// /// The modules display name that's shown in the menu /// @@ -23,17 +71,6 @@ namespace Artemis.Core.Plugins.Abstract /// public string DisplayIcon { get; set; } - /// - /// The optional datamodel driving this module - /// - public DataModel DataModel { get; set; } - - /// - /// 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 - /// - public bool ExpandsMainDataModel { get; protected set; } - /// /// Called each frame when the module must update /// @@ -54,5 +91,10 @@ namespace Artemis.Core.Plugins.Abstract /// /// public abstract IEnumerable GetViewModels(); + + internal virtual DataModelPropertyAttribute InternalGetDataModelDescription() + { + return null; + } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/Plugin.cs b/src/Artemis.Core/Plugins/Abstract/Plugin.cs index 1a27b7dd6..a0f01b1d7 100644 --- a/src/Artemis.Core/Plugins/Abstract/Plugin.cs +++ b/src/Artemis.Core/Plugins/Abstract/Plugin.cs @@ -4,7 +4,6 @@ using Artemis.Core.Plugins.Models; namespace Artemis.Core.Plugins.Abstract { - /// /// /// This is the base plugin type, use the other interfaces such as Module to create plugins /// diff --git a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs index 1d34f53d0..8120e1bd6 100644 --- a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs +++ b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs @@ -2,10 +2,58 @@ using Artemis.Core.Exceptions; using Artemis.Core.Models.Profile; using Artemis.Core.Models.Surface; +using Artemis.Core.Plugins.Abstract.DataModels; +using Artemis.Core.Plugins.Abstract.DataModels.Attributes; using SkiaSharp; namespace Artemis.Core.Plugins.Abstract { + /// + /// Allows you to add support for new games/applications while utilizing Artemis' profile engine and your own data model + /// + public abstract class ProfileModule : ProfileModule where T : DataModel + { + /// + /// The data model driving this module + /// + public T DataModel + { + get => (T)InternalDataModel; + internal set => InternalDataModel = value; + } + + /// + /// Gets or sets whether this module must also expand the main data model + /// + /// Note: If expanding the main data model is all you want your plugin to do, create a + /// plugin instead. + /// + /// + public bool ExpandsDataModel + { + get => InternalExpandsMainDataModel; + set => InternalExpandsMainDataModel = value; + } + + /// + /// Override to provide your own data model description. By default this returns a description matching your plugin + /// name and description + /// + /// + public virtual DataModelPropertyAttribute GetDataModelDescription() + { + return new DataModelPropertyAttribute { Name = PluginInfo.Name, Description = PluginInfo.Description }; + } + + internal override DataModelPropertyAttribute InternalGetDataModelDescription() + { + return GetDataModelDescription(); + } + } + + /// + /// Allows you to add support for new games/applications while utilizing Artemis' profile engine + /// public abstract class ProfileModule : Module { public Profile ActiveProfile { get; private set; } diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index 4fb246a6a..c47593056 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -6,6 +6,7 @@ using Artemis.Core.Events; using Artemis.Core.Exceptions; using Artemis.Core.JsonConverters; using Artemis.Core.Ninject; +using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Storage.Interfaces; @@ -24,13 +25,14 @@ namespace Artemis.Core.Services /// public class CoreService : ICoreService { + private readonly Stopwatch _frameStopWatch; private readonly ILogger _logger; private readonly PluginSetting _loggingLevel; private readonly IPluginService _pluginService; private readonly IProfileService _profileService; private readonly IRgbService _rgbService; private readonly ISurfaceService _surfaceService; - private readonly Stopwatch _frameStopWatch; + private List _dataModelExpansions; private List _modules; // 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; _loggingLevel.SettingChanged += (sender, args) => ApplyLoggingLevel(); - _modules = _pluginService.GetPluginsOfType(); - _pluginService.PluginEnabled += (sender, args) => _modules = _pluginService.GetPluginsOfType(); - _pluginService.PluginDisabled += (sender, args) => _modules = _pluginService.GetPluginsOfType(); + _pluginService.PluginEnabled += (sender, args) => UpdatePluginCache(); + _pluginService.PluginDisabled += (sender, args) => UpdatePluginCache(); + UpdatePluginCache(); _frameStopWatch = new Stopwatch(); @@ -58,7 +60,7 @@ namespace Artemis.Core.Services } public TimeSpan FrameTime { get; private set; } - public bool ModuleUpdatingDisabled { get; set; } + public bool PluginUpdatingDisabled { get; set; } public bool ModuleRenderingDisabled { get; set; } public void Dispose() @@ -75,7 +77,7 @@ namespace Artemis.Core.Services throw new ArtemisCoreException("Cannot initialize the core as it is already initialized."); var versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute(); - _logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion); + _logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion); ApplyLoggingLevel(); // Initialize the services @@ -103,6 +105,12 @@ namespace Artemis.Core.Services FrameRendered?.Invoke(this, e); } + private void UpdatePluginCache() + { + _modules = _pluginService.GetPluginsOfType(); + _dataModelExpansions = _pluginService.GetPluginsOfType(); + } + private void ConfigureJsonConvert() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings @@ -125,8 +133,15 @@ namespace Artemis.Core.Services try { _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) { // Update all active modules diff --git a/src/Artemis.Core/Services/DataModelService.cs b/src/Artemis.Core/Services/DataModelService.cs new file mode 100644 index 000000000..7719b8005 --- /dev/null +++ b/src/Artemis.Core/Services/DataModelService.cs @@ -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 +{ + /// + /// Provides access to the main data model + /// + public class DataModelService : IDataModelService + { + private readonly IPluginService _pluginService; + private readonly List _dataModelExpansions; + + internal DataModelService(IPluginService pluginService) + { + _pluginService = pluginService; + _dataModelExpansions = new List(); + + _pluginService.PluginEnabled += PluginServiceOnPluginEnabled; + _pluginService.PluginDisabled += PluginServiceOnPluginDisabled; + } + + public ReadOnlyCollection DataModelExpansions + { + get + { + lock (_dataModelExpansions) + { + return new List(_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); + } + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Interfaces/ICoreService.cs b/src/Artemis.Core/Services/Interfaces/ICoreService.cs index 838cca93b..3cf78c7cd 100644 --- a/src/Artemis.Core/Services/Interfaces/ICoreService.cs +++ b/src/Artemis.Core/Services/Interfaces/ICoreService.cs @@ -18,7 +18,7 @@ namespace Artemis.Core.Services.Interfaces /// /// Gets or sets whether modules are updated each frame by calling their Update method /// - bool ModuleUpdatingDisabled { get; set; } + bool PluginUpdatingDisabled { get; set; } /// /// Gets or sets whether modules are rendered each frame by calling their Render method diff --git a/src/Artemis.Core/Services/Interfaces/IMainDataModelService.cs b/src/Artemis.Core/Services/Interfaces/IDataModelService.cs similarity index 53% rename from src/Artemis.Core/Services/Interfaces/IMainDataModelService.cs rename to src/Artemis.Core/Services/Interfaces/IDataModelService.cs index c620a6d01..91052248f 100644 --- a/src/Artemis.Core/Services/Interfaces/IMainDataModelService.cs +++ b/src/Artemis.Core/Services/Interfaces/IDataModelService.cs @@ -1,27 +1,21 @@ using Artemis.Core.Models; -using Artemis.Core.Plugins.Abstract; +using Artemis.Core.Plugins.Abstract.DataModels; namespace Artemis.Core.Services.Interfaces { - public interface IMainDataModelService : IArtemisService + public interface IDataModelService : IArtemisService { - /// - /// Called each frame when the main data model must update - /// - /// Time since the last update - void Update(double deltaTime); - /// /// Add an expansion to the datamodel to be available for use after the next update /// - /// - void AddExpansion(DataModelExpansion dataModelExpansion); + /// + void AddExpansion(DataModel baseDataModelExpansion); /// /// Remove a previously added expansion so that it is no longer available and updated /// - /// - void RemoveExpansion(DataModelExpansion dataModelExpansion); + /// + void RemoveExpansion(DataModel baseDataModelExpansion); /// /// Generates a data model description for the main datamodel including all it's expansions diff --git a/src/Artemis.Core/Services/MainDataModelService.cs b/src/Artemis.Core/Services/MainDataModelService.cs deleted file mode 100644 index 52ca5e9f5..000000000 --- a/src/Artemis.Core/Services/MainDataModelService.cs +++ /dev/null @@ -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 -{ - /// - /// Provides access to the main data model - /// - public class MainDataModelService : IMainDataModelService - { - private readonly List _dataModelExpansions; - - internal MainDataModelService() - { - _dataModelExpansions = new List(); - } - - public ReadOnlyCollection 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; - } - } -} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 72ee9b69a..f52502575 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -4,9 +4,9 @@ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} false Artemis.UI.Shared - HP Inc. + Artemis.UI.Shared Artemis.UI.Shared - Copyright © HP Inc. 2019 + Copyright © Robert Beekman - 2020 MinimumRecommendedRules.ruleset 7.3 bin\$(Platform)\$(Configuration)\ @@ -27,6 +27,7 @@ true git true + 2.0.0 diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs index 6b71c8dbb..632a5fe8a 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs @@ -15,6 +15,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor { private readonly List _originalStops; private ColorStopViewModel _selectedColorStopViewModel; + private double _previewWidth; public GradientEditorViewModel(ColorGradient colorGradient) { @@ -41,7 +42,12 @@ namespace Artemis.UI.Shared.Screens.GradientEditor public bool HasSelectedColorStopViewModel => SelectedColorStopViewModel != null; 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) { diff --git a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs index f48a10218..ccfcdbe91 100644 --- a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs +++ b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs @@ -201,12 +201,12 @@ namespace Artemis.UI.Shared.Services public void StopRegularRender() { - _coreService.ModuleUpdatingDisabled = true; + _coreService.PluginUpdatingDisabled = true; } public void ResumeRegularRender() { - _coreService.ModuleUpdatingDisabled = false; + _coreService.PluginUpdatingDisabled = false; } protected virtual void OnSelectedProfileChanged(ProfileElementEventArgs e) diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs index bc9b899f3..ffde0654a 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs @@ -80,7 +80,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor { var result = await DialogService.ShowDialog(); if (result is string name) - CreateProfile(name); + { + var newProfile = CreateProfile(name); + SelectedProfile = newProfile; + } } public async Task DeleteActiveProfile() diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs index dd9a4fd8f..aa41b0322 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs @@ -66,7 +66,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins switch (Plugin) { - case DataModelExpansion _: + case BaseDataModelExpansion _: return PackIconKind.TableAdd; case DeviceProvider _: return PackIconKind.Devices; diff --git a/src/Artemis.sln b/src/Artemis.sln index 094416019..74a69ec93 100644 --- a/src/Artemis.sln +++ b/src/Artemis.sln @@ -71,7 +71,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artemis.Plugins.LayerBrushe EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LayerEffects", "LayerEffects", "{2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC}" 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -275,6 +277,7 @@ Global {301C3AAA-9F79-46A5-9B9D-86F076C5BDD1} = {A311DC47-42A2-4DD4-B921-50FBF7A33F41} {2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC} = {E830A02B-A7E5-4A6B-943F-76B0A542630C} {62214042-667E-4B29-B64E-1A68CE6FE209} = {2C1477DC-7A5C-4B65-85DB-1F16A18FB2EC} + {4E85F6B5-83FB-4830-8787-555103F26ECD} = {E830A02B-A7E5-4A6B-943F-76B0A542630C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C203080A-4473-4CC2-844B-F552EA43D66A} diff --git a/src/Plugins/Artemis.Plugins.Modules.General/GeneralDataModel.cs b/src/Plugins/Artemis.Plugins.Modules.General/GeneralDataModel.cs index 1ce42c686..e7d18cef1 100644 --- a/src/Plugins/Artemis.Plugins.Modules.General/GeneralDataModel.cs +++ b/src/Plugins/Artemis.Plugins.Modules.General/GeneralDataModel.cs @@ -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; namespace Artemis.Plugins.Modules.General { 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!")] public string TestString { get; set; } @@ -23,10 +17,6 @@ namespace Artemis.Plugins.Modules.General 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!")] public string TestString { get; set; } diff --git a/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs index 6e9e032c5..72209225e 100644 --- a/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using Artemis.Core.Plugins.Abstract; +using Artemis.Core.Plugins.Abstract.DataModels; using Artemis.Core.Plugins.Abstract.ViewModels; using Artemis.Core.Plugins.Models; using Artemis.Plugins.Modules.General.ViewModels; namespace Artemis.Plugins.Modules.General { - public class GeneralModule : ProfileModule + public class GeneralModule : ProfileModule { private readonly PluginSettings _settings; @@ -25,8 +26,8 @@ namespace Artemis.Plugins.Modules.General { DisplayName = "General"; DisplayIcon = "AllInclusive"; - ExpandsMainDataModel = true; - DataModel = new GeneralDataModel(this); + ExpandsDataModel = true; + var testSetting = _settings.GetSetting("TestSetting", DateTime.Now); }