mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Core - Removed scripting providers
Meta - Updated packages
This commit is contained in:
1 parent
7691af95b9
commit
37f973b093
30 files changed
+35
-1441
No files matched your search
@@ -1,23 +0,0 @@
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing a script editor
|
||||
/// </summary>
|
||||
public interface IScriptEditorViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the script type this view model was created for
|
||||
/// </summary>
|
||||
ScriptType ScriptType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the script this editor is editing
|
||||
/// </summary>
|
||||
Script? Script { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the view model must display a different script
|
||||
/// </summary>
|
||||
/// <param name="script">The script to display or <see langword="null" /> if no script is to be displayed</param>
|
||||
void ChangeScript(Script? script);
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.General;
|
||||
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration of a script
|
||||
/// </summary>
|
||||
public class ScriptConfiguration : CorePropertyChanged, IStorageModel
|
||||
{
|
||||
private bool _hasChanges;
|
||||
private bool _isSuspended;
|
||||
private string _name;
|
||||
private string? _pendingScriptContent;
|
||||
private string? _scriptContent;
|
||||
private string _scriptingProviderId;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ScriptConfiguration" /> class
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the scripting provider
|
||||
/// </summary>
|
||||
public string ScriptingProviderId
|
||||
{
|
||||
get => _scriptingProviderId;
|
||||
set => SetAndNotify(ref _scriptingProviderId, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the script
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetAndNotify(ref _name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the script's content
|
||||
/// </summary>
|
||||
public string? ScriptContent
|
||||
{
|
||||
get => _scriptContent;
|
||||
private set
|
||||
{
|
||||
if (!SetAndNotify(ref _scriptContent, value)) return;
|
||||
OnScriptContentChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the pending changes to the script's content
|
||||
/// </summary>
|
||||
public string? PendingScriptContent
|
||||
{
|
||||
get => _pendingScriptContent;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
value = null;
|
||||
if (!SetAndNotify(ref _pendingScriptContent, value)) return;
|
||||
HasChanges = ScriptContent != PendingScriptContent;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implement suspension
|
||||
/// <summary>
|
||||
/// [NYI] Gets or sets a boolean indicating whether this configuration is suspended
|
||||
/// </summary>
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => _isSuspended;
|
||||
set => SetAndNotify(ref _isSuspended, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this configuration has pending changes to it's
|
||||
/// <see cref="ScriptContent" />
|
||||
/// </summary>
|
||||
public bool HasChanges
|
||||
{
|
||||
get => _hasChanges;
|
||||
set => SetAndNotify(ref _hasChanges, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If active, gets the script
|
||||
/// </summary>
|
||||
public Script? Script { get; internal set; }
|
||||
|
||||
internal ScriptConfigurationEntity Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Applies the <see cref="PendingScriptContent" /> to the <see cref="ScriptContent" />
|
||||
/// </summary>
|
||||
public void ApplyPendingChanges()
|
||||
{
|
||||
ScriptContent = PendingScriptContent;
|
||||
HasChanges = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discards the <see cref="PendingScriptContent" />
|
||||
/// </summary>
|
||||
public void DiscardPendingChanges()
|
||||
{
|
||||
PendingScriptContent = ScriptContent;
|
||||
HasChanges = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever the contents of the script have changed
|
||||
/// </summary>
|
||||
public event EventHandler? ScriptContentChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="ScriptContentChanged" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnScriptContentChanged()
|
||||
{
|
||||
ScriptContentChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
ScriptingProviderId = Entity.ScriptingProviderId;
|
||||
ScriptContent = Entity.ScriptContent;
|
||||
PendingScriptContent = Entity.ScriptContent;
|
||||
Name = Entity.Name;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
Entity.ScriptingProviderId = ScriptingProviderId;
|
||||
Entity.ScriptContent = ScriptContent;
|
||||
Entity.Name = Name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to implement and register your own scripting provider.
|
||||
/// </summary>
|
||||
public abstract class ScriptingProvider<TGlobalScript, TProfileScript> : ScriptingProvider
|
||||
where TGlobalScript : GlobalScript
|
||||
where TProfileScript : ProfileScript
|
||||
{
|
||||
#region Overrides of PluginFeature
|
||||
|
||||
/// <inheritdoc />
|
||||
internal override void InternalDisable()
|
||||
{
|
||||
base.InternalDisable();
|
||||
|
||||
while (Scripts.Count > 0)
|
||||
Scripts[0].Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of ScriptingProvider
|
||||
|
||||
/// <inheritdoc />
|
||||
internal override Type ProfileScriptType => typeof(TProfileScript);
|
||||
|
||||
/// <inheritdoc />
|
||||
internal override Type GlobalScriptType => typeof(TGlobalScript);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to implement and register your own scripting provider.
|
||||
/// <para>
|
||||
/// Note: You can't implement this, implement
|
||||
/// <see cref="ScriptingProvider{TGlobalScript, TProfileScript}" /> instead.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public abstract class ScriptingProvider : PluginFeature
|
||||
{
|
||||
/// <summary>
|
||||
/// The base constructor of the <see cref="ScriptingProvider" /> class
|
||||
/// </summary>
|
||||
protected ScriptingProvider()
|
||||
{
|
||||
Scripts = new ReadOnlyCollection<Script>(InternalScripts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the scripting language this provider provides
|
||||
/// </summary>
|
||||
public abstract string LanguageName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all active scripts belonging to this scripting provider
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<Script> Scripts { get; }
|
||||
|
||||
internal abstract Type GlobalScriptType { get; }
|
||||
internal abstract Type ProfileScriptType { get; }
|
||||
internal List<Script> InternalScripts { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the UI needs a script editor for the specified <paramref name="scriptType" />
|
||||
/// </summary>
|
||||
/// <param name="scriptType">The type of script the editor will host</param>
|
||||
public abstract IScriptEditorViewModel CreateScriptEditor(ScriptType scriptType);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a script for a certain type needs default content.
|
||||
/// </summary>
|
||||
/// <param name="scriptType">The type of script the default content is for.</param>
|
||||
public abstract string GetDefaultScriptContent(ScriptType scriptType);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a script running globally
|
||||
/// </summary>
|
||||
public abstract class GlobalScript : Script
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected GlobalScript(ScriptConfiguration configuration) : base(configuration)
|
||||
{
|
||||
}
|
||||
|
||||
internal ScriptingService? ScriptingService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the Artemis Core is about to update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public virtual void OnCoreUpdating(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the Artemis Core has been updated
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public virtual void OnCoreUpdated(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
#region Overrides of Script
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ScriptType ScriptType => ScriptType.Global;
|
||||
|
||||
/// <inheritdoc />
|
||||
internal override void InternalCleanup()
|
||||
{
|
||||
ScriptingService?.RemoveScript(ScriptConfiguration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a script bound to a specific <see cref="Profile" /> processed by a <see cref="ScriptingProvider" />.
|
||||
/// </summary>
|
||||
public abstract class ProfileScript : Script
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected ProfileScript(Profile profile, ScriptConfiguration configuration) : base(configuration)
|
||||
{
|
||||
Profile = profile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile this script is bound to
|
||||
/// </summary>
|
||||
public Profile Profile { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the profile is about to update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public virtual void OnProfileUpdating(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the profile has been updated
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public virtual void OnProfileUpdated(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the profile is about to render
|
||||
/// </summary>
|
||||
/// <param name="canvas">The profile canvas</param>
|
||||
/// <param name="bounds">The area to be filled, covers the entire canvas</param>
|
||||
public virtual void OnProfileRendering(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the profile has been rendered
|
||||
/// </summary>
|
||||
/// <param name="canvas">The profile canvas</param>
|
||||
/// <param name="bounds">The area to be filled, covers the entire canvas</param>
|
||||
public virtual void OnProfileRendered(SKCanvas canvas, SKRect bounds)
|
||||
{
|
||||
}
|
||||
|
||||
#region Overrides of Script
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ScriptType ScriptType => ScriptType.Profile;
|
||||
|
||||
/// <inheritdoc />
|
||||
internal override void InternalCleanup()
|
||||
{
|
||||
Profile.RemoveScript(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Artemis.Core.ScriptingProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a script processed by a <see cref="ScriptingProviders.ScriptingProvider" />.
|
||||
/// </summary>
|
||||
public abstract class Script : CorePropertyChanged, IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
private ScriptingProvider _scriptingProvider = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The base constructor of any script
|
||||
/// </summary>
|
||||
/// <param name="configuration">The script configuration this script belongs to</param>
|
||||
protected Script(ScriptConfiguration configuration)
|
||||
{
|
||||
if (configuration.Script != null)
|
||||
throw new ArtemisCoreException("The provided script configuration already has an active script");
|
||||
|
||||
ScriptConfiguration = configuration;
|
||||
ScriptConfiguration.PropertyChanged += ScriptConfigurationOnPropertyChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scripting provider this script belongs to
|
||||
/// </summary>
|
||||
public ScriptingProvider ScriptingProvider
|
||||
{
|
||||
get => _scriptingProvider;
|
||||
internal set => SetAndNotify(ref _scriptingProvider, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the script configuration this script belongs to
|
||||
/// </summary>
|
||||
public ScriptConfiguration ScriptConfiguration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the script type of this script
|
||||
/// </summary>
|
||||
public abstract ScriptType ScriptType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the contents of the script have changed
|
||||
/// </summary>
|
||||
public event EventHandler? ScriptContentChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="ScriptContentChanged" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnScriptContentChanged()
|
||||
{
|
||||
ScriptContentChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal abstract void InternalCleanup();
|
||||
|
||||
private void ScriptConfigurationOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(ScriptConfiguration.ScriptContent))
|
||||
OnScriptContentChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_disposed = true;
|
||||
ScriptConfiguration.PropertyChanged -= ScriptConfigurationOnPropertyChanged;
|
||||
ScriptConfiguration.Script = null;
|
||||
ScriptingProvider.InternalScripts.Remove(this);
|
||||
|
||||
// Can't trust those pesky plugin devs!
|
||||
InternalCleanup();
|
||||
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a type of script
|
||||
/// </summary>
|
||||
public enum ScriptType
|
||||
{
|
||||
/// <summary>
|
||||
/// A global script that's always active
|
||||
/// </summary>
|
||||
Global,
|
||||
|
||||
/// <summary>
|
||||
/// A script tied to a <see cref="Profile" />
|
||||
/// </summary>
|
||||
Profile
|
||||
}
|
||||
Reference in new issue
Block a user