diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 6eea123b0..f73fb5879 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -38,8 +38,6 @@ namespace Artemis.Core Profile = Parent.Profile; Name = name; Suspended = false; - Scripts = new List(); - ScriptConfigurations = new List(); _general = new LayerGeneralProperties(); _transform = new LayerTransformProperties(); @@ -64,8 +62,6 @@ namespace Artemis.Core Profile = profile; Parent = parent; - Scripts = new List(); - ScriptConfigurations = new List(); _general = new LayerGeneralProperties(); _transform = new LayerTransformProperties(); @@ -82,16 +78,6 @@ namespace Artemis.Core /// public ReadOnlyCollection Leds => _leds.AsReadOnly(); - /// - /// Gets a collection of all active scripts assigned to this layer - /// - public List Scripts { get; } - - /// - /// Gets a collection of all script configurations assigned to this layer - /// - public List ScriptConfigurations { get; } - /// /// Defines the shape that is rendered by the . /// @@ -190,9 +176,6 @@ namespace Artemis.Core Disposed = true; - while (Scripts.Count > 1) - Scripts[0].Dispose(); - LayerBrushStore.LayerBrushAdded -= LayerBrushStoreOnLayerBrushAdded; LayerBrushStore.LayerBrushRemoved -= LayerBrushStoreOnLayerBrushRemoved; @@ -269,11 +252,6 @@ namespace Artemis.Core ExpandedPropertyGroups.AddRange(LayerEntity.ExpandedPropertyGroups); LoadRenderElement(); Adapter.Load(); - - foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations) - scriptConfiguration.Script?.Dispose(); - ScriptConfigurations.Clear(); - ScriptConfigurations.AddRange(LayerEntity.ScriptConfigurations.Select(e => new ScriptConfiguration(e))); } internal override void Save() @@ -310,14 +288,7 @@ namespace Artemis.Core // Adaption hints Adapter.Save(); - - LayerEntity.ScriptConfigurations.Clear(); - foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations) - { - scriptConfiguration.Save(); - LayerEntity.ScriptConfigurations.Add(scriptConfiguration.Entity); - } - + SaveRenderElement(); } @@ -349,10 +320,7 @@ namespace Artemis.Core { if (Disposed) throw new ObjectDisposedException("Layer"); - - foreach (LayerScript layerScript in Scripts) - layerScript.OnLayerUpdating(deltaTime); - + UpdateDisplayCondition(); UpdateTimeline(deltaTime); @@ -360,9 +328,6 @@ namespace Artemis.Core Enable(); else if (Timeline.IsFinished) Disable(); - - foreach (LayerScript layerScript in Scripts) - layerScript.OnLayerUpdated(deltaTime); } /// @@ -512,10 +477,7 @@ namespace Artemis.Core { if (LayerBrush == null) throw new ArtemisCoreException("The layer is not yet ready for rendering"); - - foreach (LayerScript layerScript in Scripts) - layerScript.OnLayerRendering(canvas, bounds, layerPaint); - + foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended)) baseLayerEffect.PreProcess(canvas, bounds, layerPaint); @@ -531,9 +493,6 @@ namespace Artemis.Core foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended)) baseLayerEffect.PostProcess(canvas, bounds, layerPaint); - - foreach (LayerScript layerScript in Scripts) - layerScript.OnLayerRendered(canvas, bounds, layerPaint); } finally diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/ILayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/ILayerProperty.cs index 76b787f1d..dcfcdeeda 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/ILayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/ILayerProperty.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Artemis.Core.ScriptingProviders; using Artemis.Storage.Entities.Profile; namespace Artemis.Core @@ -24,16 +23,6 @@ namespace Artemis.Core /// LayerPropertyGroup LayerPropertyGroup { get; } - /// - /// Gets a collection of all active scripts assigned to this layer property - /// - List Scripts { get; } - - /// - /// Gets a collection of all script configurations assigned to this layer property - /// - public List ScriptConfigurations { get; } - /// /// Gets the unique path of the property on the layer /// @@ -81,8 +70,6 @@ namespace Artemis.Core /// The timeline to apply to the property void Update(Timeline timeline); - #region Events - /// /// Occurs when the layer property is disposed /// @@ -137,7 +124,5 @@ namespace Artemis.Core /// Occurs when a data binding has been disabled /// public event EventHandler? DataBindingDisabled; - - #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs index 2877482c5..3d83ce37b 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Artemis.Core.ScriptingProviders; using Artemis.Storage.Entities.Profile; using Newtonsoft.Json; @@ -31,8 +30,6 @@ namespace Artemis.Core Path = null!; Entity = null!; PropertyDescription = null!; - Scripts = new List(); - ScriptConfigurations = new List(); CurrentValue = default!; DefaultValue = default!; @@ -60,9 +57,6 @@ namespace Artemis.Core { _disposed = true; - while (Scripts.Count > 1) - Scripts[0].Dispose(); - foreach (IDataBinding dataBinding in _dataBindings) dataBinding.Dispose(); @@ -153,12 +147,6 @@ namespace Artemis.Core /// public PropertyDescriptionAttribute PropertyDescription { get; internal set; } - /// - public List Scripts { get; } - - /// - public List ScriptConfigurations { get; } - /// public string Path { get; private set; } @@ -171,18 +159,12 @@ namespace Artemis.Core if (_disposed) throw new ObjectDisposedException("LayerProperty"); - foreach (PropertyScript propertyScript in Scripts) - propertyScript.OnPropertyUpdating(timeline.Delta.TotalSeconds); - CurrentValue = BaseValue; UpdateKeyframes(timeline); UpdateDataBindings(timeline); OnUpdated(); - - foreach (PropertyScript propertyScript in Scripts) - propertyScript.OnPropertyUpdated(timeline.Delta.TotalSeconds); } /// @@ -762,11 +744,6 @@ namespace Artemis.Core if (dataBinding != null) _dataBindings.Add(dataBinding); } - - foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations) - scriptConfiguration.Script?.Dispose(); - ScriptConfigurations.Clear(); - ScriptConfigurations.AddRange(Entity.ScriptConfigurations.Select(e => new ScriptConfiguration(e))); } /// @@ -788,13 +765,6 @@ namespace Artemis.Core Entity.DataBindingEntities.Clear(); foreach (IDataBinding dataBinding in _dataBindings) dataBinding.Save(); - - Entity.ScriptConfigurations.Clear(); - foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations) - { - scriptConfiguration.Save(); - Entity.ScriptConfigurations.Add(scriptConfiguration.Entity); - } } /// diff --git a/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs b/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs new file mode 100644 index 000000000..92ba0a646 --- /dev/null +++ b/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs @@ -0,0 +1,24 @@ +namespace Artemis.Core.ScriptingProviders +{ + /// + /// Represents a view model containing a script editor + /// + public interface IScriptEditorViewModel + { + /// + /// Gets the script type this view model was created for + /// + ScriptType ScriptType { get; } + + /// + /// Gets the script this editor is editing + /// + Script? Script { get; } + + /// + /// Called whenever the view model must display a different script + /// + /// The script to display or if no script is to be displayed + void ChangeScript(Script? script); + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs b/src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs index d27b0e145..ecc953eb5 100644 --- a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs +++ b/src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs @@ -9,6 +9,7 @@ namespace Artemis.Core.ScriptingProviders public class ScriptConfiguration : CorePropertyChanged, IStorageModel { private bool _hasChanges; + private bool _isSuspended; private string _name; private string? _pendingScriptContent; private string? _scriptContent; @@ -79,6 +80,16 @@ namespace Artemis.Core.ScriptingProviders } } + // TODO: Implement suspension + /// + /// [NYI] Gets or sets a boolean indicating whether this configuration is suspended + /// + public bool IsSuspended + { + get => _isSuspended; + set => SetAndNotify(ref _isSuspended, value); + } + /// /// Gets or sets a boolean indicating whether this configuration has pending changes to it's /// diff --git a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs b/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs index e9a06fd0d..08568f78e 100644 --- a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs +++ b/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs @@ -7,36 +7,10 @@ namespace Artemis.Core.ScriptingProviders /// /// Allows you to implement and register your own scripting provider. /// - public abstract class ScriptingProvider : ScriptingProvider + public abstract class ScriptingProvider : ScriptingProvider where TGlobalScript : GlobalScript where TProfileScript : ProfileScript - where TLayerScript : LayerScript - where TPropertyScript : PropertyScript { - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public abstract IScriptEditorViewModel CreateGlobalScriptEditor(TGlobalScript script); - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public abstract IScriptEditorViewModel CreateProfileScriptEditor(TProfileScript script); - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public abstract IScriptEditorViewModel CreateLayerScriptScriptEditor(TLayerScript script); - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public abstract IScriptEditorViewModel CreatePropertyScriptEditor(TPropertyScript script); - #region Overrides of PluginFeature /// @@ -52,69 +26,11 @@ namespace Artemis.Core.ScriptingProviders #region Overrides of ScriptingProvider - /// - internal override Type GlobalScriptType => typeof(TGlobalScript); - /// internal override Type ProfileScriptType => typeof(TProfileScript); /// - internal override Type LayerScriptType => typeof(TLayerScript); - - /// - internal override Type PropertyScriptType => typeof(TPropertyScript); - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public override IScriptEditorViewModel CreateGlobalScriptEditor(GlobalScript script) - { - if (script == null) throw new ArgumentNullException(nameof(script)); - if (script.GetType() != GlobalScriptType) - throw new ArtemisCoreException($"This scripting provider only supports global scripts of type {GlobalScriptType.Name}"); - - return CreateGlobalScriptEditor((TGlobalScript) script); - } - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public override IScriptEditorViewModel CreateProfileScriptEditor(ProfileScript script) - { - if (script == null) throw new ArgumentNullException(nameof(script)); - if (script.GetType() != ProfileScriptType) - throw new ArtemisCoreException($"This scripting provider only supports profile scripts of type {ProfileScriptType.Name}"); - - return CreateProfileScriptEditor((TProfileScript) script); - } - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public override IScriptEditorViewModel CreateLayerScriptScriptEditor(LayerScript script) - { - if (script == null) throw new ArgumentNullException(nameof(script)); - if (script.GetType() != LayerScriptType) - throw new ArtemisCoreException($"This scripting provider only supports layer scripts of type {LayerScriptType.Name}"); - - return CreateLayerScriptScriptEditor((TLayerScript) script); - } - - /// - /// Called when the UI needs a script editor for a - /// - /// The script the editor must edit - public override IScriptEditorViewModel CreatePropertyScriptEditor(PropertyScript script) - { - if (script == null) throw new ArgumentNullException(nameof(script)); - if (script.GetType() != PropertyScriptType) - throw new ArtemisCoreException($"This scripting provider only supports property scripts of type {PropertyScriptType.Name}"); - - return CreatePropertyScriptEditor((TPropertyScript) script); - } + internal override Type GlobalScriptType => typeof(TGlobalScript); #endregion } @@ -123,7 +39,7 @@ namespace Artemis.Core.ScriptingProviders /// Allows you to implement and register your own scripting provider. /// /// Note: You can't implement this, implement - /// instead. + /// instead. /// /// public abstract class ScriptingProvider : PluginFeature @@ -139,44 +55,13 @@ namespace Artemis.Core.ScriptingProviders public ReadOnlyCollection