From 37f973b09356447b8098d06559beed2be291a46c Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 14 Nov 2024 14:09:39 +0100 Subject: [PATCH] Core - Removed scripting providers Meta - Updated packages --- src/Artemis.Core/Models/Profile/Profile.cs | 97 +--------- .../IScriptEditorViewModel.cs | 23 --- .../ScriptingProviders/ScriptConfiguration.cs | 163 ----------------- .../ScriptingProviders/ScriptingProvider.cs | 80 --------- .../Scripts/GlobalScript.cs | 45 ----- .../Scripts/ProfileScript.cs | 67 ------- .../ScriptingProviders/Scripts/Script.cs | 114 ------------ src/Artemis.Core/Services/CoreRenderer.cs | 11 +- src/Artemis.Core/Services/CoreService.cs | 6 - .../Services/Interfaces/IScriptingService.cs | 46 ----- src/Artemis.Core/Services/ScriptingService.cs | 165 ------------------ .../General/ScriptConfigurationEntity.cs | 12 -- .../Entities/Profile/ProfileEntity.cs | 2 - .../ScriptEditorViewModel.cs | 54 ------ src/Artemis.UI/Artemis.UI.csproj | 3 + src/Artemis.UI/DryIoc/Factories/IVMFactory.cs | 28 --- .../Features/PluginFeatureViewModel.cs | 5 - .../Panels/MenuBar/MenuBarView.axaml | 5 - .../Panels/MenuBar/MenuBarViewModel.cs | 14 +- .../ScriptConfigurationCreateView.axaml | 36 ---- .../ScriptConfigurationCreateView.axaml.cs | 13 -- .../ScriptConfigurationCreateViewModel.cs | 40 ----- .../Dialogs/ScriptConfigurationEditView.axaml | 10 -- .../ScriptConfigurationEditView.axaml.cs | 19 -- .../ScriptConfigurationEditViewModel.cs | 35 ---- .../Scripting/ScriptConfigurationViewModel.cs | 63 ------- .../Screens/Scripting/ScriptsDialogView.axaml | 90 ---------- .../Scripting/ScriptsDialogView.axaml.cs | 34 ---- .../Scripting/ScriptsDialogViewModel.cs | 142 --------------- src/Directory.Packages.props | 54 +++--- 30 files changed, 35 insertions(+), 1441 deletions(-) delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/Scripts/GlobalScript.cs delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/Scripts/ProfileScript.cs delete mode 100644 src/Artemis.Core/Plugins/ScriptingProviders/Scripts/Script.cs delete mode 100644 src/Artemis.Core/Services/Interfaces/IScriptingService.cs delete mode 100644 src/Artemis.Core/Services/ScriptingService.cs delete mode 100644 src/Artemis.Storage/Entities/General/ScriptConfigurationEntity.cs delete mode 100644 src/Artemis.UI.Shared/Plugins/ScriptingProviders/ScriptEditorViewModel.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationCreateView.axaml delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationCreateView.axaml.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationCreateViewModel.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationEditView.axaml delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationEditView.axaml.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/Dialogs/ScriptConfigurationEditViewModel.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/ScriptConfigurationViewModel.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/ScriptsDialogView.axaml delete mode 100644 src/Artemis.UI/Screens/Scripting/ScriptsDialogView.axaml.cs delete mode 100644 src/Artemis.UI/Screens/Scripting/ScriptsDialogViewModel.cs diff --git a/src/Artemis.Core/Models/Profile/Profile.cs b/src/Artemis.Core/Models/Profile/Profile.cs index 073afa540..187d9c423 100644 --- a/src/Artemis.Core/Models/Profile/Profile.cs +++ b/src/Artemis.Core/Models/Profile/Profile.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; -using Artemis.Core.ScriptingProviders; using Artemis.Storage.Entities.Profile; using SkiaSharp; @@ -14,15 +12,10 @@ namespace Artemis.Core; public sealed class Profile : ProfileElement { private readonly object _lock = new(); - private readonly ObservableCollection _scriptConfigurations; - private readonly ObservableCollection _scripts; private bool _isFreshImport; internal Profile(ProfileConfiguration configuration, ProfileEntity profileEntity) : base(null!) { - _scripts = new ObservableCollection(); - _scriptConfigurations = new ObservableCollection(); - Opacity = 0d; ShouldDisplay = true; Configuration = configuration; @@ -31,8 +24,6 @@ public sealed class Profile : ProfileElement EntityId = profileEntity.Id; Exceptions = new List(); - Scripts = new ReadOnlyObservableCollection(_scripts); - ScriptConfigurations = new ReadOnlyObservableCollection(_scriptConfigurations); Load(); } @@ -41,17 +32,7 @@ public sealed class Profile : ProfileElement /// Gets the profile configuration of this profile /// public ProfileConfiguration Configuration { get; } - - /// - /// Gets a collection of all active scripts assigned to this profile - /// - public ReadOnlyObservableCollection Scripts { get; } - - /// - /// Gets a collection of all script configurations assigned to this profile - /// - public ReadOnlyObservableCollection ScriptConfigurations { get; } - + /// /// Gets or sets a boolean indicating whether this profile is freshly imported i.e. no changes have been made to it /// since import @@ -85,15 +66,9 @@ public sealed class Profile : ProfileElement if (Disposed) throw new ObjectDisposedException("Profile"); - foreach (ProfileScript profileScript in Scripts) - profileScript.OnProfileUpdating(deltaTime); - foreach (ProfileElement profileElement in Children) profileElement.Update(deltaTime); - foreach (ProfileScript profileScript in Scripts) - profileScript.OnProfileUpdated(deltaTime); - const double OPACITY_PER_SECOND = 1; if (ShouldDisplay && Opacity < 1) @@ -111,9 +86,6 @@ public sealed class Profile : ProfileElement if (Disposed) throw new ObjectDisposedException("Profile"); - foreach (ProfileScript profileScript in Scripts) - profileScript.OnProfileRendering(canvas, canvas.LocalClipBounds); - SKPaint? opacityPaint = null; bool applyOpacityLayer = Configuration.FadeInAndOut && Opacity < 1; @@ -133,9 +105,6 @@ public sealed class Profile : ProfileElement opacityPaint?.Dispose(); } - foreach (ProfileScript profileScript in Scripts) - profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds); - if (!Exceptions.Any()) return; @@ -174,7 +143,7 @@ public sealed class Profile : ProfileElement /// public override IEnumerable GetFeatureDependencies() { - return GetRootFolder().GetFeatureDependencies().Concat(Scripts.Select(c => c.ScriptingProvider)); + return GetRootFolder().GetFeatureDependencies(); } /// @@ -205,10 +174,7 @@ public sealed class Profile : ProfileElement { if (!disposing) return; - - while (Scripts.Count > 0) - RemoveScript(Scripts[0]); - + foreach (ProfileElement profileElement in Children) profileElement.Dispose(); ChildrenList.Clear(); @@ -238,61 +204,11 @@ public sealed class Profile : ProfileElement AddChild(new Folder(this, this, rootFolder)); } - while (_scriptConfigurations.Any()) - RemoveScriptConfiguration(_scriptConfigurations[0]); - foreach (ScriptConfiguration scriptConfiguration in ProfileEntity.ScriptConfigurations.Select(e => new ScriptConfiguration(e))) - AddScriptConfiguration(scriptConfiguration); - // Load node scripts last since they may rely on the profile structure being in place foreach (RenderProfileElement renderProfileElement in GetAllRenderElements()) renderProfileElement.LoadNodeScript(); } - /// - /// Removes a script configuration from the profile, if the configuration has an active script it is also removed. - /// - internal void RemoveScriptConfiguration(ScriptConfiguration scriptConfiguration) - { - if (!_scriptConfigurations.Contains(scriptConfiguration)) - return; - - Script? script = scriptConfiguration.Script; - if (script != null) - RemoveScript((ProfileScript) script); - - _scriptConfigurations.Remove(scriptConfiguration); - } - - /// - /// Adds a script configuration to the profile but does not instantiate it's script. - /// - internal void AddScriptConfiguration(ScriptConfiguration scriptConfiguration) - { - if (!_scriptConfigurations.Contains(scriptConfiguration)) - _scriptConfigurations.Add(scriptConfiguration); - } - - /// - /// Adds a script that has a script configuration belonging to this profile. - /// - internal void AddScript(ProfileScript script) - { - if (!_scriptConfigurations.Contains(script.ScriptConfiguration)) - throw new ArtemisCoreException("Cannot add a script to a profile whose script configuration doesn't belong to the same profile."); - - if (!_scripts.Contains(script)) - _scripts.Add(script); - } - - /// - /// Removes a script from the profile and disposes it. - /// - internal void RemoveScript(ProfileScript script) - { - _scripts.Remove(script); - script.Dispose(); - } - internal override void Save() { if (Disposed) @@ -310,12 +226,5 @@ public sealed class Profile : ProfileElement ProfileEntity.Layers.Clear(); ProfileEntity.Layers.AddRange(GetAllLayers().Select(f => f.LayerEntity)); - - ProfileEntity.ScriptConfigurations.Clear(); - foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations) - { - scriptConfiguration.Save(); - ProfileEntity.ScriptConfigurations.Add(scriptConfiguration.Entity); - } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs b/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs deleted file mode 100644 index 9e7674b35..000000000 --- a/src/Artemis.Core/Plugins/ScriptingProviders/IScriptEditorViewModel.cs +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index eb9c2c287..000000000 --- a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptConfiguration.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using Artemis.Storage.Entities.General; - -namespace Artemis.Core.ScriptingProviders; - -/// -/// Represents the configuration of a script -/// -public class ScriptConfiguration : CorePropertyChanged, IStorageModel -{ - private bool _hasChanges; - private bool _isSuspended; - private string _name; - private string? _pendingScriptContent; - private string? _scriptContent; - private string _scriptingProviderId; - - /// - /// Creates a new instance of the class - /// - public ScriptConfiguration(ScriptingProvider provider, string name, ScriptType scriptType) - { - _scriptingProviderId = provider.Id; - _name = name; - Entity = new ScriptConfigurationEntity(); - PendingScriptContent = provider.GetDefaultScriptContent(scriptType); - ScriptContent = PendingScriptContent; - } - - internal ScriptConfiguration(ScriptConfigurationEntity entity) - { - _scriptingProviderId = null!; - _name = null!; - Entity = entity; - - Load(); - } - - /// - /// Gets or sets the ID of the scripting provider - /// - public string ScriptingProviderId - { - get => _scriptingProviderId; - set => SetAndNotify(ref _scriptingProviderId, value); - } - - /// - /// Gets or sets the name of the script - /// - public string Name - { - get => _name; - set => SetAndNotify(ref _name, value); - } - - /// - /// Gets or sets the script's content - /// - public string? ScriptContent - { - get => _scriptContent; - private set - { - if (!SetAndNotify(ref _scriptContent, value)) return; - OnScriptContentChanged(); - } - } - - /// - /// Gets or sets the pending changes to the script's content - /// - public string? PendingScriptContent - { - get => _pendingScriptContent; - set - { - if (string.IsNullOrWhiteSpace(value)) - value = null; - if (!SetAndNotify(ref _pendingScriptContent, value)) return; - HasChanges = ScriptContent != PendingScriptContent; - } - } - - // 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 - /// - /// - public bool HasChanges - { - get => _hasChanges; - set => SetAndNotify(ref _hasChanges, value); - } - - /// - /// If active, gets the script - /// - public Script? Script { get; internal set; } - - internal ScriptConfigurationEntity Entity { get; } - - /// - /// Applies the to the - /// - public void ApplyPendingChanges() - { - ScriptContent = PendingScriptContent; - HasChanges = false; - } - - /// - /// Discards the - /// - public void DiscardPendingChanges() - { - PendingScriptContent = ScriptContent; - HasChanges = false; - } - - /// - /// Occurs whenever the contents of the script have changed - /// - public event EventHandler? ScriptContentChanged; - - /// - /// Invokes the event - /// - protected virtual void OnScriptContentChanged() - { - ScriptContentChanged?.Invoke(this, EventArgs.Empty); - } - - #region Implementation of IStorageModel - - /// - public void Load() - { - ScriptingProviderId = Entity.ScriptingProviderId; - ScriptContent = Entity.ScriptContent; - PendingScriptContent = Entity.ScriptContent; - Name = Entity.Name; - } - - /// - public void Save() - { - Entity.ScriptingProviderId = ScriptingProviderId; - Entity.ScriptContent = ScriptContent; - Entity.Name = Name; - } - - #endregion -} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs b/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs deleted file mode 100644 index 5148c823a..000000000 --- a/src/Artemis.Core/Plugins/ScriptingProviders/ScriptingProvider.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; - -namespace Artemis.Core.ScriptingProviders; - -/// -/// Allows you to implement and register your own scripting provider. -/// -public abstract class ScriptingProvider : ScriptingProvider - where TGlobalScript : GlobalScript - where TProfileScript : ProfileScript -{ - #region Overrides of PluginFeature - - /// - internal override void InternalDisable() - { - base.InternalDisable(); - - while (Scripts.Count > 0) - Scripts[0].Dispose(); - } - - #endregion - - #region Overrides of ScriptingProvider - - /// - internal override Type ProfileScriptType => typeof(TProfileScript); - - /// - internal override Type GlobalScriptType => typeof(TGlobalScript); - - #endregion -} - -/// -/// Allows you to implement and register your own scripting provider. -/// -/// Note: You can't implement this, implement -/// instead. -/// -/// -public abstract class ScriptingProvider : PluginFeature -{ - /// - /// The base constructor of the class - /// - protected ScriptingProvider() - { - Scripts = new ReadOnlyCollection