mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development'
This commit is contained in:
commit
0b29f6c92c
@ -38,8 +38,6 @@ namespace Artemis.Core
|
|||||||
Profile = Parent.Profile;
|
Profile = Parent.Profile;
|
||||||
Name = name;
|
Name = name;
|
||||||
Suspended = false;
|
Suspended = false;
|
||||||
Scripts = new List<LayerScript>();
|
|
||||||
ScriptConfigurations = new List<ScriptConfiguration>();
|
|
||||||
|
|
||||||
_general = new LayerGeneralProperties();
|
_general = new LayerGeneralProperties();
|
||||||
_transform = new LayerTransformProperties();
|
_transform = new LayerTransformProperties();
|
||||||
@ -64,8 +62,6 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Profile = profile;
|
Profile = profile;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
Scripts = new List<LayerScript>();
|
|
||||||
ScriptConfigurations = new List<ScriptConfiguration>();
|
|
||||||
|
|
||||||
_general = new LayerGeneralProperties();
|
_general = new LayerGeneralProperties();
|
||||||
_transform = new LayerTransformProperties();
|
_transform = new LayerTransformProperties();
|
||||||
@ -82,16 +78,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
|
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a collection of all active scripts assigned to this layer
|
|
||||||
/// </summary>
|
|
||||||
public List<LayerScript> Scripts { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a collection of all script configurations assigned to this layer
|
|
||||||
/// </summary>
|
|
||||||
public List<ScriptConfiguration> ScriptConfigurations { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the shape that is rendered by the <see cref="LayerBrush" />.
|
/// Defines the shape that is rendered by the <see cref="LayerBrush" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -190,9 +176,6 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Disposed = true;
|
Disposed = true;
|
||||||
|
|
||||||
while (Scripts.Count > 1)
|
|
||||||
Scripts[0].Dispose();
|
|
||||||
|
|
||||||
LayerBrushStore.LayerBrushAdded -= LayerBrushStoreOnLayerBrushAdded;
|
LayerBrushStore.LayerBrushAdded -= LayerBrushStoreOnLayerBrushAdded;
|
||||||
LayerBrushStore.LayerBrushRemoved -= LayerBrushStoreOnLayerBrushRemoved;
|
LayerBrushStore.LayerBrushRemoved -= LayerBrushStoreOnLayerBrushRemoved;
|
||||||
|
|
||||||
@ -269,11 +252,6 @@ namespace Artemis.Core
|
|||||||
ExpandedPropertyGroups.AddRange(LayerEntity.ExpandedPropertyGroups);
|
ExpandedPropertyGroups.AddRange(LayerEntity.ExpandedPropertyGroups);
|
||||||
LoadRenderElement();
|
LoadRenderElement();
|
||||||
Adapter.Load();
|
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()
|
internal override void Save()
|
||||||
@ -311,13 +289,6 @@ namespace Artemis.Core
|
|||||||
// Adaption hints
|
// Adaption hints
|
||||||
Adapter.Save();
|
Adapter.Save();
|
||||||
|
|
||||||
LayerEntity.ScriptConfigurations.Clear();
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations)
|
|
||||||
{
|
|
||||||
scriptConfiguration.Save();
|
|
||||||
LayerEntity.ScriptConfigurations.Add(scriptConfiguration.Entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveRenderElement();
|
SaveRenderElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,9 +321,6 @@ namespace Artemis.Core
|
|||||||
if (Disposed)
|
if (Disposed)
|
||||||
throw new ObjectDisposedException("Layer");
|
throw new ObjectDisposedException("Layer");
|
||||||
|
|
||||||
foreach (LayerScript layerScript in Scripts)
|
|
||||||
layerScript.OnLayerUpdating(deltaTime);
|
|
||||||
|
|
||||||
UpdateDisplayCondition();
|
UpdateDisplayCondition();
|
||||||
UpdateTimeline(deltaTime);
|
UpdateTimeline(deltaTime);
|
||||||
|
|
||||||
@ -360,9 +328,6 @@ namespace Artemis.Core
|
|||||||
Enable();
|
Enable();
|
||||||
else if (Timeline.IsFinished)
|
else if (Timeline.IsFinished)
|
||||||
Disable();
|
Disable();
|
||||||
|
|
||||||
foreach (LayerScript layerScript in Scripts)
|
|
||||||
layerScript.OnLayerUpdated(deltaTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -513,9 +478,6 @@ namespace Artemis.Core
|
|||||||
if (LayerBrush == null)
|
if (LayerBrush == null)
|
||||||
throw new ArtemisCoreException("The layer is not yet ready for rendering");
|
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))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
baseLayerEffect.PreProcess(canvas, bounds, layerPaint);
|
baseLayerEffect.PreProcess(canvas, bounds, layerPaint);
|
||||||
|
|
||||||
@ -531,9 +493,6 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
baseLayerEffect.PostProcess(canvas, bounds, layerPaint);
|
baseLayerEffect.PostProcess(canvas, bounds, layerPaint);
|
||||||
|
|
||||||
foreach (LayerScript layerScript in Scripts)
|
|
||||||
layerScript.OnLayerRendered(canvas, bounds, layerPaint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
finally
|
finally
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Artemis.Core.ScriptingProviders;
|
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -24,16 +23,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
LayerPropertyGroup LayerPropertyGroup { get; }
|
LayerPropertyGroup LayerPropertyGroup { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a collection of all active scripts assigned to this layer property
|
|
||||||
/// </summary>
|
|
||||||
List<PropertyScript> Scripts { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a collection of all script configurations assigned to this layer property
|
|
||||||
/// </summary>
|
|
||||||
public List<ScriptConfiguration> ScriptConfigurations { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the unique path of the property on the layer
|
/// Gets the unique path of the property on the layer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -81,8 +70,6 @@ namespace Artemis.Core
|
|||||||
/// <param name="timeline">The timeline to apply to the property</param>
|
/// <param name="timeline">The timeline to apply to the property</param>
|
||||||
void Update(Timeline timeline);
|
void Update(Timeline timeline);
|
||||||
|
|
||||||
#region Events
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the layer property is disposed
|
/// Occurs when the layer property is disposed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -137,7 +124,5 @@ namespace Artemis.Core
|
|||||||
/// Occurs when a data binding has been disabled
|
/// Occurs when a data binding has been disabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<LayerPropertyEventArgs>? DataBindingDisabled;
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingDisabled;
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.ScriptingProviders;
|
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -31,8 +30,6 @@ namespace Artemis.Core
|
|||||||
Path = null!;
|
Path = null!;
|
||||||
Entity = null!;
|
Entity = null!;
|
||||||
PropertyDescription = null!;
|
PropertyDescription = null!;
|
||||||
Scripts = new List<PropertyScript>();
|
|
||||||
ScriptConfigurations = new List<ScriptConfiguration>();
|
|
||||||
|
|
||||||
CurrentValue = default!;
|
CurrentValue = default!;
|
||||||
DefaultValue = default!;
|
DefaultValue = default!;
|
||||||
@ -60,9 +57,6 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
|
||||||
while (Scripts.Count > 1)
|
|
||||||
Scripts[0].Dispose();
|
|
||||||
|
|
||||||
foreach (IDataBinding dataBinding in _dataBindings)
|
foreach (IDataBinding dataBinding in _dataBindings)
|
||||||
dataBinding.Dispose();
|
dataBinding.Dispose();
|
||||||
|
|
||||||
@ -153,12 +147,6 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public PropertyDescriptionAttribute PropertyDescription { get; internal set; }
|
public PropertyDescriptionAttribute PropertyDescription { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public List<PropertyScript> Scripts { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public List<ScriptConfiguration> ScriptConfigurations { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Path { get; private set; }
|
public string Path { get; private set; }
|
||||||
|
|
||||||
@ -171,18 +159,12 @@ namespace Artemis.Core
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException("LayerProperty");
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
foreach (PropertyScript propertyScript in Scripts)
|
|
||||||
propertyScript.OnPropertyUpdating(timeline.Delta.TotalSeconds);
|
|
||||||
|
|
||||||
CurrentValue = BaseValue;
|
CurrentValue = BaseValue;
|
||||||
|
|
||||||
UpdateKeyframes(timeline);
|
UpdateKeyframes(timeline);
|
||||||
UpdateDataBindings(timeline);
|
UpdateDataBindings(timeline);
|
||||||
|
|
||||||
OnUpdated();
|
OnUpdated();
|
||||||
|
|
||||||
foreach (PropertyScript propertyScript in Scripts)
|
|
||||||
propertyScript.OnPropertyUpdated(timeline.Delta.TotalSeconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -762,11 +744,6 @@ namespace Artemis.Core
|
|||||||
if (dataBinding != null)
|
if (dataBinding != null)
|
||||||
_dataBindings.Add(dataBinding);
|
_dataBindings.Add(dataBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations)
|
|
||||||
scriptConfiguration.Script?.Dispose();
|
|
||||||
ScriptConfigurations.Clear();
|
|
||||||
ScriptConfigurations.AddRange(Entity.ScriptConfigurations.Select(e => new ScriptConfiguration(e)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -788,13 +765,6 @@ namespace Artemis.Core
|
|||||||
Entity.DataBindingEntities.Clear();
|
Entity.DataBindingEntities.Clear();
|
||||||
foreach (IDataBinding dataBinding in _dataBindings)
|
foreach (IDataBinding dataBinding in _dataBindings)
|
||||||
dataBinding.Save();
|
dataBinding.Save();
|
||||||
|
|
||||||
Entity.ScriptConfigurations.Clear();
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in ScriptConfigurations)
|
|
||||||
{
|
|
||||||
scriptConfiguration.Save();
|
|
||||||
Entity.ScriptConfigurations.Add(scriptConfiguration.Entity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
public class ScriptConfiguration : CorePropertyChanged, IStorageModel
|
public class ScriptConfiguration : CorePropertyChanged, IStorageModel
|
||||||
{
|
{
|
||||||
private bool _hasChanges;
|
private bool _hasChanges;
|
||||||
|
private bool _isSuspended;
|
||||||
private string _name;
|
private string _name;
|
||||||
private string? _pendingScriptContent;
|
private string? _pendingScriptContent;
|
||||||
private string? _scriptContent;
|
private string? _scriptContent;
|
||||||
@ -79,6 +80,16 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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>
|
/// <summary>
|
||||||
/// Gets or sets a boolean indicating whether this configuration has pending changes to it's
|
/// Gets or sets a boolean indicating whether this configuration has pending changes to it's
|
||||||
/// <see cref="ScriptContent" />
|
/// <see cref="ScriptContent" />
|
||||||
|
|||||||
@ -7,36 +7,10 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows you to implement and register your own scripting provider.
|
/// Allows you to implement and register your own scripting provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ScriptingProvider<TGlobalScript, TProfileScript, TLayerScript, TPropertyScript> : ScriptingProvider
|
public abstract class ScriptingProvider<TGlobalScript, TProfileScript> : ScriptingProvider
|
||||||
where TGlobalScript : GlobalScript
|
where TGlobalScript : GlobalScript
|
||||||
where TProfileScript : ProfileScript
|
where TProfileScript : ProfileScript
|
||||||
where TLayerScript : LayerScript
|
|
||||||
where TPropertyScript : PropertyScript
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="GlobalScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreateGlobalScriptEditor(TGlobalScript script);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="ProfileScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreateProfileScriptEditor(TProfileScript script);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="LayerScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreateLayerScriptScriptEditor(TLayerScript script);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="PropertyScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreatePropertyScriptEditor(TPropertyScript script);
|
|
||||||
|
|
||||||
#region Overrides of PluginFeature
|
#region Overrides of PluginFeature
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -52,69 +26,11 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
|
|
||||||
#region Overrides of ScriptingProvider
|
#region Overrides of ScriptingProvider
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
internal override Type GlobalScriptType => typeof(TGlobalScript);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override Type ProfileScriptType => typeof(TProfileScript);
|
internal override Type ProfileScriptType => typeof(TProfileScript);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override Type LayerScriptType => typeof(TLayerScript);
|
internal override Type GlobalScriptType => typeof(TGlobalScript);
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
internal override Type PropertyScriptType => typeof(TPropertyScript);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="GlobalScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="ProfileScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="LayerScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="PropertyScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -123,7 +39,7 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
/// Allows you to implement and register your own scripting provider.
|
/// Allows you to implement and register your own scripting provider.
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Note: You can't implement this, implement
|
/// Note: You can't implement this, implement
|
||||||
/// <see cref="ScriptingProvider{TProfileScript,TLayerScript,TPropertyScript,TGlobalScript}" /> instead.
|
/// <see cref="ScriptingProvider{TGlobalScript, TProfileScript}" /> instead.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ScriptingProvider : PluginFeature
|
public abstract class ScriptingProvider : PluginFeature
|
||||||
@ -139,44 +55,13 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
public ReadOnlyCollection<Script> Scripts => InternalScripts.AsReadOnly();
|
public ReadOnlyCollection<Script> Scripts => InternalScripts.AsReadOnly();
|
||||||
|
|
||||||
internal abstract Type GlobalScriptType { get; }
|
internal abstract Type GlobalScriptType { get; }
|
||||||
internal abstract Type PropertyScriptType { get; }
|
|
||||||
internal abstract Type LayerScriptType { get; }
|
|
||||||
internal abstract Type ProfileScriptType { get; }
|
internal abstract Type ProfileScriptType { get; }
|
||||||
internal List<Script> InternalScripts { get; } = new();
|
internal List<Script> InternalScripts { get; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the UI needs a script editor for a <see cref="GlobalScript" />
|
/// Called when the UI needs a script editor for the specified <paramref name="scriptType" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="script">The script the editor must edit</param>
|
/// <param name="scriptType">The type of script the editor will host</param>
|
||||||
public abstract IScriptEditorViewModel CreateGlobalScriptEditor(GlobalScript script);
|
public abstract IScriptEditorViewModel CreateScriptEditor(ScriptType scriptType);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="ProfileScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreateProfileScriptEditor(ProfileScript script);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="LayerScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreateLayerScriptScriptEditor(LayerScript script);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the UI needs a script editor for a <see cref="PropertyScript" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="script">The script the editor must edit</param>
|
|
||||||
public abstract IScriptEditorViewModel CreatePropertyScriptEditor(PropertyScript script);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a view model containing a script editor
|
|
||||||
/// </summary>
|
|
||||||
public interface IScriptEditorViewModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the script this editor is editing
|
|
||||||
/// </summary>
|
|
||||||
Script Script { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,6 +32,9 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
|
|
||||||
#region Overrides of Script
|
#region Overrides of Script
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override ScriptType ScriptType => ScriptType.Global;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override void InternalCleanup()
|
internal override void InternalCleanup()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,74 +0,0 @@
|
|||||||
using SkiaSharp;
|
|
||||||
|
|
||||||
namespace Artemis.Core.ScriptingProviders
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a script bound to a specific <see cref="Layer" /> processed by a <see cref="ScriptingProvider" />.
|
|
||||||
/// </summary>
|
|
||||||
public abstract class LayerScript : Script
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected LayerScript(Layer layer, ScriptConfiguration configuration) : base(configuration)
|
|
||||||
{
|
|
||||||
Layer = layer;
|
|
||||||
lock (Layer.Scripts)
|
|
||||||
{
|
|
||||||
Layer.Scripts.Add(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the layer this script is bound to
|
|
||||||
/// </summary>
|
|
||||||
public Layer Layer { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the layer is about to update
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
|
||||||
public virtual void OnLayerUpdating(double deltaTime)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the layer has been updated
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
|
||||||
public virtual void OnLayerUpdated(double deltaTime)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the layer is about to render
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="canvas">The layer canvas</param>
|
|
||||||
/// <param name="bounds">The area to be filled, covers the shape</param>
|
|
||||||
/// <param name="paint">The paint to be used to fill the shape</param>
|
|
||||||
public virtual void OnLayerRendering(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the layer has been rendered
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="canvas">The layer canvas</param>
|
|
||||||
/// <param name="bounds">The area to be filled, covers the shape</param>
|
|
||||||
/// <param name="paint">The paint to be used to fill the shape</param>
|
|
||||||
public virtual void OnLayerRendered(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Overrides of Script
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
internal override void InternalCleanup()
|
|
||||||
{
|
|
||||||
lock (Layer.Scripts)
|
|
||||||
{
|
|
||||||
Layer.Scripts.Remove(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -58,6 +58,9 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
|
|
||||||
#region Overrides of Script
|
#region Overrides of Script
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override ScriptType ScriptType => ScriptType.Profile;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override void InternalCleanup()
|
internal override void InternalCleanup()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
namespace Artemis.Core.ScriptingProviders
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a script bound to a specific <see cref="LayerProperty{T}" /> processed by a
|
|
||||||
/// <see cref="ScriptingProvider" />.
|
|
||||||
/// </summary>
|
|
||||||
public abstract class PropertyScript : Script
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected PropertyScript(ILayerProperty layerProperty, ScriptConfiguration configuration) : base(configuration)
|
|
||||||
{
|
|
||||||
LayerProperty = layerProperty;
|
|
||||||
lock (LayerProperty.Scripts)
|
|
||||||
{
|
|
||||||
LayerProperty.Scripts.Add(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the layer property this script is bound to
|
|
||||||
/// </summary>
|
|
||||||
public ILayerProperty LayerProperty { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the property is about to update
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
|
||||||
public virtual void OnPropertyUpdating(double deltaTime)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the property has been updated
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
|
||||||
public virtual void OnPropertyUpdated(double deltaTime)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Overrides of Script
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
internal override void InternalCleanup()
|
|
||||||
{
|
|
||||||
lock (LayerProperty.Scripts)
|
|
||||||
{
|
|
||||||
LayerProperty.Scripts.Remove(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -39,6 +39,11 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ScriptConfiguration ScriptConfiguration { get; }
|
public ScriptConfiguration ScriptConfiguration { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the script type of this script
|
||||||
|
/// </summary>
|
||||||
|
public abstract ScriptType ScriptType { get; }
|
||||||
|
|
||||||
#region Event handlers
|
#region Event handlers
|
||||||
|
|
||||||
private void ScriptConfigurationOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
private void ScriptConfigurationOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||||
@ -100,4 +105,20 @@ namespace Artemis.Core.ScriptingProviders
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -18,8 +18,7 @@ namespace Artemis.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
|
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />.
|
||||||
/// .
|
|
||||||
/// </returns>
|
/// </returns>
|
||||||
GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration);
|
GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration);
|
||||||
|
|
||||||
@ -29,33 +28,10 @@ namespace Artemis.Core.Services
|
|||||||
/// <param name="profile">The profile the script configuration is configured for</param>
|
/// <param name="profile">The profile the script configuration is configured for</param>
|
||||||
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
|
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />.
|
||||||
/// .
|
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration);
|
ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="LayerScript" /> instance for the given <paramref name="scriptConfiguration" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layer">The layer the script configuration is configured fo</param>
|
|
||||||
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
|
||||||
/// <returns>
|
|
||||||
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
|
|
||||||
/// .
|
|
||||||
/// </returns>
|
|
||||||
LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="PropertyScript" /> instance for the given <paramref name="scriptConfiguration" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layerProperty">The layer property the script configuration is configured fo</param>
|
|
||||||
/// <param name="scriptConfiguration">The script configuration of the script</param>
|
|
||||||
/// <returns>
|
|
||||||
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
|
|
||||||
/// .
|
|
||||||
/// </returns>
|
|
||||||
PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the provided global script by it's configuration
|
/// Deletes the provided global script by it's configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -12,11 +12,13 @@ namespace Artemis.Core.Services
|
|||||||
internal class ScriptingService : IScriptingService
|
internal class ScriptingService : IScriptingService
|
||||||
{
|
{
|
||||||
private readonly IPluginManagementService _pluginManagementService;
|
private readonly IPluginManagementService _pluginManagementService;
|
||||||
|
private readonly IProfileService _profileService;
|
||||||
private List<ScriptingProvider> _scriptingProviders;
|
private List<ScriptingProvider> _scriptingProviders;
|
||||||
|
|
||||||
public ScriptingService(IPluginManagementService pluginManagementService, IProfileService profileService)
|
public ScriptingService(IPluginManagementService pluginManagementService, IProfileService profileService)
|
||||||
{
|
{
|
||||||
_pluginManagementService = pluginManagementService;
|
_pluginManagementService = pluginManagementService;
|
||||||
|
_profileService = profileService;
|
||||||
|
|
||||||
InternalGlobalScripts = new List<GlobalScript>();
|
InternalGlobalScripts = new List<GlobalScript>();
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ namespace Artemis.Core.Services
|
|||||||
// No need to sub to Deactivated, scripts will deactivate themselves
|
// No need to sub to Deactivated, scripts will deactivate themselves
|
||||||
profileService.ProfileActivated += ProfileServiceOnProfileActivated;
|
profileService.ProfileActivated += ProfileServiceOnProfileActivated;
|
||||||
|
|
||||||
foreach (ProfileConfiguration profileConfiguration in profileService.ProfileConfigurations)
|
foreach (ProfileConfiguration profileConfiguration in _profileService.ProfileConfigurations)
|
||||||
{
|
{
|
||||||
if (profileConfiguration.Profile != null)
|
if (profileConfiguration.Profile != null)
|
||||||
InitializeProfileScripts(profileConfiguration.Profile);
|
InitializeProfileScripts(profileConfiguration.Profile);
|
||||||
@ -54,6 +56,12 @@ namespace Artemis.Core.Services
|
|||||||
private void PluginManagementServiceOnPluginFeatureToggled(object? sender, PluginFeatureEventArgs e)
|
private void PluginManagementServiceOnPluginFeatureToggled(object? sender, PluginFeatureEventArgs e)
|
||||||
{
|
{
|
||||||
_scriptingProviders = _pluginManagementService.GetFeaturesOfType<ScriptingProvider>();
|
_scriptingProviders = _pluginManagementService.GetFeaturesOfType<ScriptingProvider>();
|
||||||
|
|
||||||
|
foreach (ProfileConfiguration profileConfiguration in _profileService.ProfileConfigurations)
|
||||||
|
{
|
||||||
|
if (profileConfiguration.Profile != null)
|
||||||
|
InitializeProfileScripts(profileConfiguration.Profile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProfileServiceOnProfileActivated(object? sender, ProfileConfigurationEventArgs e)
|
private void ProfileServiceOnProfileActivated(object? sender, ProfileConfigurationEventArgs e)
|
||||||
@ -67,30 +75,6 @@ namespace Artemis.Core.Services
|
|||||||
// Initialize the scripts on the profile
|
// Initialize the scripts on the profile
|
||||||
foreach (ScriptConfiguration scriptConfiguration in profile.ScriptConfigurations.Where(c => c.Script == null))
|
foreach (ScriptConfiguration scriptConfiguration in profile.ScriptConfigurations.Where(c => c.Script == null))
|
||||||
CreateScriptInstance(profile, scriptConfiguration);
|
CreateScriptInstance(profile, scriptConfiguration);
|
||||||
|
|
||||||
foreach (Layer layer in profile.GetAllLayers())
|
|
||||||
{
|
|
||||||
// Initialize the scripts on the layers
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in layer.ScriptConfigurations.Where(c => c.Script == null))
|
|
||||||
CreateScriptInstance(layer, scriptConfiguration);
|
|
||||||
|
|
||||||
// Initialize the scripts on the layer properties of layers
|
|
||||||
foreach (ILayerProperty layerProperty in layer.GetAllLayerProperties())
|
|
||||||
{
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in layerProperty.ScriptConfigurations.Where(c => c.Script == null))
|
|
||||||
CreateScriptInstance(layerProperty, scriptConfiguration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Folder folder in profile.GetAllFolders())
|
|
||||||
{
|
|
||||||
// Initialize the scripts on the layer properties of folders
|
|
||||||
foreach (ILayerProperty layerProperty in folder.GetAllLayerProperties())
|
|
||||||
{
|
|
||||||
foreach (ScriptConfiguration scriptConfiguration in layerProperty.ScriptConfigurations.Where(c => c.Script == null))
|
|
||||||
CreateScriptInstance(layerProperty, scriptConfiguration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlyCollection<GlobalScript> GlobalScripts => InternalGlobalScripts.AsReadOnly();
|
public ReadOnlyCollection<GlobalScript> GlobalScripts => InternalGlobalScripts.AsReadOnly();
|
||||||
@ -136,46 +120,6 @@ namespace Artemis.Core.Services
|
|||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration)
|
|
||||||
{
|
|
||||||
if (scriptConfiguration.Script != null)
|
|
||||||
throw new ArtemisCoreException("The provided script configuration already has an active script");
|
|
||||||
|
|
||||||
ScriptingProvider? provider = _scriptingProviders.FirstOrDefault(p => p.Id == scriptConfiguration.ScriptingProviderId);
|
|
||||||
if (provider == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
LayerScript script = (LayerScript) provider.Plugin.Kernel!.Get(
|
|
||||||
provider.LayerScriptType,
|
|
||||||
CreateScriptConstructorArgument(provider.LayerScriptType, layer),
|
|
||||||
CreateScriptConstructorArgument(provider.LayerScriptType, scriptConfiguration)
|
|
||||||
);
|
|
||||||
|
|
||||||
script.ScriptingProvider = provider;
|
|
||||||
provider.InternalScripts.Add(script);
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration)
|
|
||||||
{
|
|
||||||
if (scriptConfiguration.Script != null)
|
|
||||||
throw new ArtemisCoreException("The provided script configuration already has an active script");
|
|
||||||
|
|
||||||
ScriptingProvider? provider = _scriptingProviders.FirstOrDefault(p => p.Id == scriptConfiguration.ScriptingProviderId);
|
|
||||||
if (provider == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
PropertyScript script = (PropertyScript) provider.Plugin.Kernel!.Get(
|
|
||||||
provider.PropertyScriptType,
|
|
||||||
CreateScriptConstructorArgument(provider.PropertyScriptType, layerProperty),
|
|
||||||
CreateScriptConstructorArgument(provider.PropertyScriptType, scriptConfiguration)
|
|
||||||
);
|
|
||||||
|
|
||||||
script.ScriptingProvider = provider;
|
|
||||||
provider.InternalScripts.Add(script);
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void DeleteScript(ScriptConfiguration scriptConfiguration)
|
public void DeleteScript(ScriptConfiguration scriptConfiguration)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Artemis.Storage.Entities.General;
|
|
||||||
using Artemis.Storage.Entities.Profile.Abstract;
|
using Artemis.Storage.Entities.Profile.Abstract;
|
||||||
using Artemis.Storage.Entities.Profile.AdaptionHints;
|
using Artemis.Storage.Entities.Profile.AdaptionHints;
|
||||||
using LiteDB;
|
using LiteDB;
|
||||||
@ -13,7 +12,6 @@ namespace Artemis.Storage.Entities.Profile
|
|||||||
{
|
{
|
||||||
Leds = new List<LedEntity>();
|
Leds = new List<LedEntity>();
|
||||||
AdaptionHints = new List<IAdaptionHintEntity>();
|
AdaptionHints = new List<IAdaptionHintEntity>();
|
||||||
ScriptConfigurations = new List<ScriptConfigurationEntity>();
|
|
||||||
PropertyEntities = new List<PropertyEntity>();
|
PropertyEntities = new List<PropertyEntity>();
|
||||||
LayerEffects = new List<LayerEffectEntity>();
|
LayerEffects = new List<LayerEffectEntity>();
|
||||||
ExpandedPropertyGroups = new List<string>();
|
ExpandedPropertyGroups = new List<string>();
|
||||||
@ -25,7 +23,6 @@ namespace Artemis.Storage.Entities.Profile
|
|||||||
|
|
||||||
public List<LedEntity> Leds { get; set; }
|
public List<LedEntity> Leds { get; set; }
|
||||||
public List<IAdaptionHintEntity> AdaptionHints { get; set; }
|
public List<IAdaptionHintEntity> AdaptionHints { get; set; }
|
||||||
public List<ScriptConfigurationEntity> ScriptConfigurations { get; set; }
|
|
||||||
|
|
||||||
[BsonRef("ProfileEntity")]
|
[BsonRef("ProfileEntity")]
|
||||||
public ProfileEntity Profile { get; set; }
|
public ProfileEntity Profile { get; set; }
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Artemis.Storage.Entities.General;
|
|
||||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||||
|
|
||||||
namespace Artemis.Storage.Entities.Profile
|
namespace Artemis.Storage.Entities.Profile
|
||||||
@ -10,7 +9,6 @@ namespace Artemis.Storage.Entities.Profile
|
|||||||
{
|
{
|
||||||
KeyframeEntities = new List<KeyframeEntity>();
|
KeyframeEntities = new List<KeyframeEntity>();
|
||||||
DataBindingEntities = new List<DataBindingEntity>();
|
DataBindingEntities = new List<DataBindingEntity>();
|
||||||
ScriptConfigurations = new List<ScriptConfigurationEntity>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FeatureId { get; set; }
|
public string FeatureId { get; set; }
|
||||||
@ -21,6 +19,5 @@ namespace Artemis.Storage.Entities.Profile
|
|||||||
|
|
||||||
public List<KeyframeEntity> KeyframeEntities { get; set; }
|
public List<KeyframeEntity> KeyframeEntities { get; set; }
|
||||||
public List<DataBindingEntity> DataBindingEntities { get; set; }
|
public List<DataBindingEntity> DataBindingEntities { get; set; }
|
||||||
public List<ScriptConfigurationEntity> ScriptConfigurations { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,13 +8,49 @@ namespace Artemis.UI.Shared.ScriptingProviders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ScriptEditorViewModel : Screen, IScriptEditorViewModel
|
public class ScriptEditorViewModel : Screen, IScriptEditorViewModel
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
private Script? _script;
|
||||||
public ScriptEditorViewModel(Script script)
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of <see cref="ScriptEditorViewModel" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="scriptType">The script type this view model was created for</param>
|
||||||
|
public ScriptEditorViewModel(ScriptType scriptType)
|
||||||
|
{
|
||||||
|
ScriptType = scriptType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called just before the script is changed to a different one
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="script">The script to display or <see langword="null" /> if no script is to be displayed</param>
|
||||||
|
protected virtual void OnScriptChanging(Script? script)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called after the script was changed to a different one
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="script">The script to display or <see langword="null" /> if no script is to be displayed</param>
|
||||||
|
protected virtual void OnScriptChanged(Script? script)
|
||||||
{
|
{
|
||||||
Script = script;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Script Script { get; }
|
public ScriptType ScriptType { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Script? Script
|
||||||
|
{
|
||||||
|
get => _script;
|
||||||
|
internal set => SetAndNotify(ref _script, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void ChangeScript(Script? script)
|
||||||
|
{
|
||||||
|
OnScriptChanging(script);
|
||||||
|
Script = script;
|
||||||
|
OnScriptChanged(script);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,8 +113,6 @@ namespace Artemis.UI.Ninject.Factories
|
|||||||
public interface IScriptVmFactory : IVmFactory
|
public interface IScriptVmFactory : IVmFactory
|
||||||
{
|
{
|
||||||
ScriptsDialogViewModel ScriptsDialogViewModel(Profile profile);
|
ScriptsDialogViewModel ScriptsDialogViewModel(Profile profile);
|
||||||
ScriptsDialogViewModel ScriptsDialogViewModel(Layer layer);
|
|
||||||
ScriptsDialogViewModel ScriptsDialogViewModel(ILayerProperty layerProperty);
|
|
||||||
ScriptConfigurationViewModel ScriptConfigurationViewModel(ScriptConfiguration scriptConfiguration);
|
ScriptConfigurationViewModel ScriptConfigurationViewModel(ScriptConfiguration scriptConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -462,7 +462,7 @@
|
|||||||
The profile is currently running in normal mode and the timeline cannot be edited.
|
The profile is currently running in normal mode and the timeline cannot be edited.
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center">
|
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center">
|
||||||
Press <Run Text="F5" FontWeight="Bold"/> to switch between editor mode and normal mode. Auto-switching can be disabled in the options menu.
|
Press <Run Text="F5" FontWeight="Bold"/> to switch between editor mode and normal mode. Auto-switching can be disabled in the run menu.
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@ -234,7 +234,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
NotifyOfPropertyChange(nameof(TimeCaretPosition));
|
NotifyOfPropertyChange(nameof(TimeCaretPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e)
|
private void ProfileEditorServiceOnSuspendEditingChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
NotifyOfPropertyChange(nameof(SuspendedEditing));
|
NotifyOfPropertyChange(nameof(SuspendedEditing));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,9 @@
|
|||||||
<MenuItem Header="View Properties"
|
<MenuItem Header="View Properties"
|
||||||
Icon="{materialDesign:PackIcon Kind=Settings}"
|
Icon="{materialDesign:PackIcon Kind=Settings}"
|
||||||
Command="{s:Action ViewProperties}"/>
|
Command="{s:Action ViewProperties}"/>
|
||||||
|
<MenuItem Header="_View Scripts"
|
||||||
|
Icon="{materialDesign:PackIcon Kind=BookEdit}"
|
||||||
|
Command="{s:Action ViewScripts}"/>
|
||||||
<MenuItem Header="Adapt Profile"
|
<MenuItem Header="Adapt Profile"
|
||||||
Icon="{materialDesign:PackIcon Kind=Magic}"
|
Icon="{materialDesign:PackIcon Kind=Magic}"
|
||||||
Command="{s:Action AdaptProfile}"/>
|
Command="{s:Action AdaptProfile}"/>
|
||||||
@ -110,19 +113,6 @@
|
|||||||
IsChecked="{Binding StopOnFocusLoss.Value}"
|
IsChecked="{Binding StopOnFocusLoss.Value}"
|
||||||
InputGestureText="Shift+F5" />
|
InputGestureText="Shift+F5" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="_Scripting" IsEnabled="False">
|
|
||||||
<MenuItem Header="_Profile Scripts"
|
|
||||||
Icon="{materialDesign:PackIcon Kind=BookEdit}"
|
|
||||||
Command="{s:Action OpenProfileScripts}"/>
|
|
||||||
<MenuItem Header="_Layer Scripts"
|
|
||||||
Icon="{materialDesign:PackIcon Kind=Layers}"
|
|
||||||
IsEnabled="{Binding HasSelectedElement}"
|
|
||||||
Command="{s:Action OpenLayerScripts}"/>
|
|
||||||
<MenuItem Header="_Property Scripts"
|
|
||||||
Icon="{materialDesign:PackIcon Kind=FormTextbox}"
|
|
||||||
IsEnabled="{Binding HasSelectedElement}"
|
|
||||||
Command="{s:Action OpenLayerPropertyScripts}"/>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="_Options">
|
<MenuItem Header="_Options">
|
||||||
<MenuItem Header="Focus Selected Layer"
|
<MenuItem Header="Focus Selected Layer"
|
||||||
ToolTip="If enabled, displays only the layer you currently have selected"
|
ToolTip="If enabled, displays only the layer you currently have selected"
|
||||||
|
|||||||
@ -249,6 +249,11 @@ namespace Artemis.UI.Screens.ProfileEditor
|
|||||||
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).ViewProperties();
|
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).ViewProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ViewScripts()
|
||||||
|
{
|
||||||
|
_windowManager.ShowWindow(_scriptVmFactory.ScriptsDialogViewModel(ProfileConfiguration.Profile));
|
||||||
|
}
|
||||||
|
|
||||||
public async Task AdaptProfile()
|
public async Task AdaptProfile()
|
||||||
{
|
{
|
||||||
if (_profileEditorService.SelectedProfileConfiguration?.Profile == null)
|
if (_profileEditorService.SelectedProfileConfiguration?.Profile == null)
|
||||||
@ -305,21 +310,6 @@ namespace Artemis.UI.Screens.ProfileEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenProfileScripts()
|
|
||||||
{
|
|
||||||
_windowManager.ShowWindow(_scriptVmFactory.ScriptsDialogViewModel(ProfileConfiguration.Profile));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenLayerScripts()
|
|
||||||
{
|
|
||||||
if (_profileEditorService.SelectedProfileElement is Layer layer)
|
|
||||||
_windowManager.ShowWindow(_scriptVmFactory.ScriptsDialogViewModel(layer));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenLayerPropertyScripts()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenDebugger()
|
public void OpenDebugger()
|
||||||
{
|
{
|
||||||
_debugService.ShowDebugger();
|
_debugService.ShowDebugger();
|
||||||
|
|||||||
@ -391,7 +391,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
|||||||
ActivateToolByIndex(2);
|
ActivateToolByIndex(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e)
|
private void ProfileEditorServiceOnSuspendEditingChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
NotifyOfPropertyChange(nameof(SuspendedEditing));
|
NotifyOfPropertyChange(nameof(SuspendedEditing));
|
||||||
UpdateCanSelectEditTool();
|
UpdateCanSelectEditTool();
|
||||||
|
|||||||
@ -3,16 +3,15 @@ using System.Threading.Tasks;
|
|||||||
using Artemis.Core.ScriptingProviders;
|
using Artemis.Core.ScriptingProviders;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Screens.Scripting.Dialogs;
|
using Artemis.UI.Screens.Scripting.Dialogs;
|
||||||
using Artemis.UI.Shared.ScriptingProviders;
|
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Scripting
|
namespace Artemis.UI.Screens.Scripting
|
||||||
{
|
{
|
||||||
public class ScriptConfigurationViewModel : Conductor<IScriptEditorViewModel>
|
public class ScriptConfigurationViewModel : PropertyChangedBase
|
||||||
{
|
{
|
||||||
private readonly IScriptingService _scriptingService;
|
|
||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
|
private readonly IScriptingService _scriptingService;
|
||||||
|
|
||||||
public ScriptConfigurationViewModel(ScriptConfiguration scriptConfiguration, IScriptingService scriptingService, IDialogService dialogService)
|
public ScriptConfigurationViewModel(ScriptConfiguration scriptConfiguration, IScriptingService scriptingService, IDialogService dialogService)
|
||||||
{
|
{
|
||||||
@ -20,64 +19,9 @@ namespace Artemis.UI.Screens.Scripting
|
|||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
ScriptConfiguration = scriptConfiguration;
|
ScriptConfiguration = scriptConfiguration;
|
||||||
Script = ScriptConfiguration.Script;
|
Script = ScriptConfiguration.Script;
|
||||||
|
|
||||||
ActiveItem = Script switch
|
|
||||||
{
|
|
||||||
GlobalScript globalScript => Script.ScriptingProvider.CreateGlobalScriptEditor(globalScript),
|
|
||||||
LayerScript layerScript => Script.ScriptingProvider.CreateLayerScriptScriptEditor(layerScript),
|
|
||||||
ProfileScript profileScript => Script.ScriptingProvider.CreateProfileScriptEditor(profileScript),
|
|
||||||
PropertyScript propertyScript => Script.ScriptingProvider.CreatePropertyScriptEditor(propertyScript),
|
|
||||||
_ => new UnknownScriptEditorViewModel(null)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Script Script { get; set; }
|
public Script Script { get; set; }
|
||||||
public ScriptConfiguration ScriptConfiguration { get; }
|
public ScriptConfiguration ScriptConfiguration { get; }
|
||||||
|
|
||||||
public async Task ViewProperties()
|
|
||||||
{
|
|
||||||
object result = await _dialogService.ShowDialog<ScriptConfigurationEditViewModel>(new Dictionary<string, object>
|
|
||||||
{
|
|
||||||
{"scriptConfiguration", ScriptConfiguration}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result is nameof(ScriptConfigurationEditViewModel.Delete))
|
|
||||||
await Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task Delete()
|
|
||||||
{
|
|
||||||
bool result = await _dialogService.ShowConfirmDialogAt("ScriptsDialog", "Delete script", $"Are you sure you want to delete '{ScriptConfiguration.Name}'?");
|
|
||||||
if (!result)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (Script)
|
|
||||||
{
|
|
||||||
case GlobalScript globalScript:
|
|
||||||
_scriptingService.DeleteScript(ScriptConfiguration);
|
|
||||||
break;
|
|
||||||
case LayerScript layerScript:
|
|
||||||
layerScript.Layer.ScriptConfigurations.Remove(ScriptConfiguration);
|
|
||||||
break;
|
|
||||||
case ProfileScript profileScript:
|
|
||||||
profileScript.Profile.ScriptConfigurations.Remove(ScriptConfiguration);
|
|
||||||
break;
|
|
||||||
case PropertyScript propertyScript:
|
|
||||||
propertyScript.LayerProperty.ScriptConfigurations.Remove(ScriptConfiguration);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptConfiguration.DiscardPendingChanges();
|
|
||||||
ScriptConfiguration.Script?.Dispose();
|
|
||||||
RequestClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UnknownScriptEditorViewModel : ScriptEditorViewModel
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public UnknownScriptEditorViewModel(Script script) : base(script)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,6 +25,7 @@
|
|||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceDictionary Source="../Sidebar/ArtemisSidebar.xaml" />
|
<ResourceDictionary Source="../Sidebar/ArtemisSidebar.xaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</mde:MaterialWindow.Resources>
|
</mde:MaterialWindow.Resources>
|
||||||
<materialDesign:DialogHost IsTabStop="False" Focusable="False" Identifier="ScriptsDialog" DialogTheme="Inherit">
|
<materialDesign:DialogHost IsTabStop="False" Focusable="False" Identifier="ScriptsDialog" DialogTheme="Inherit">
|
||||||
@ -45,8 +46,8 @@
|
|||||||
Margin="0 10 0 0"
|
Margin="0 10 0 0"
|
||||||
ItemContainerStyle="{StaticResource SidebarListBoxItem}"
|
ItemContainerStyle="{StaticResource SidebarListBoxItem}"
|
||||||
HorizontalContentAlignment="Stretch"
|
HorizontalContentAlignment="Stretch"
|
||||||
ItemsSource="{Binding Items}"
|
ItemsSource="{Binding ScriptConfigurations}"
|
||||||
SelectedItem="{Binding ActiveItem}">
|
SelectedItem="{Binding SelectedScript}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type local:ScriptConfigurationViewModel}">
|
<DataTemplate DataType="{x:Type local:ScriptConfigurationViewModel}">
|
||||||
<Grid>
|
<Grid>
|
||||||
@ -81,7 +82,15 @@
|
|||||||
Foreground="{DynamicResource MaterialDesignBodyLight}"
|
Foreground="{DynamicResource MaterialDesignBodyLight}"
|
||||||
VerticalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
|
|
||||||
<Button Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" ToolTip="View properties" Width="20" Height="20" Command="{s:Action ViewProperties}" s:View.ActionTarget="{Binding}" HorizontalAlignment="Right">
|
<Button Grid.Row="0"
|
||||||
|
Grid.RowSpan="2"
|
||||||
|
Grid.Column="2"
|
||||||
|
ToolTip="View properties"
|
||||||
|
Width="20"
|
||||||
|
Height="20"
|
||||||
|
Command="{s:Action ViewProperties}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
HorizontalAlignment="Right">
|
||||||
<Button.Style>
|
<Button.Style>
|
||||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||||
<Setter Property="Visibility" Value="Collapsed" />
|
<Setter Property="Visibility" Value="Collapsed" />
|
||||||
@ -94,7 +103,8 @@
|
|||||||
</Button.Style>
|
</Button.Style>
|
||||||
<materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
|
<materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
|
||||||
</Button>
|
</Button>
|
||||||
<ToggleButton Grid.Row="0" Grid.RowSpan="2" Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0" IsChecked="{Binding ScriptConfiguration.IsSuspended}">
|
<ToggleButton Grid.Row="0" Grid.RowSpan="2" Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0"
|
||||||
|
IsChecked="{Binding ScriptConfiguration.IsSuspended}">
|
||||||
<ToggleButton.Style>
|
<ToggleButton.Style>
|
||||||
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
||||||
<Setter Property="Visibility" Value="Collapsed" />
|
<Setter Property="Visibility" Value="Collapsed" />
|
||||||
@ -113,6 +123,12 @@
|
|||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="0"
|
||||||
|
Visibility="{Binding HasScripts, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center" Margin="0 20 0 10">
|
||||||
|
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}" HorizontalAlignment="Center">Your scripts will be listed here</TextBlock>
|
||||||
|
</StackPanel>
|
||||||
<Button Grid.Row="1"
|
<Button Grid.Row="1"
|
||||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||||
Content="ADD NEW SCRIPT"
|
Content="ADD NEW SCRIPT"
|
||||||
@ -123,7 +139,15 @@
|
|||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Script editor -->
|
<!-- Script editor -->
|
||||||
<ContentControl Grid.Column="1" s:View.Model="{Binding ActiveItem.ActiveItem}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
<ContentControl Grid.Column="1" s:View.Model="{Binding ActiveItem}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||||
|
<StackPanel Grid.Column="1"
|
||||||
|
Visibility="{Binding ActiveItem, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center">
|
||||||
|
<materialDesign:PackIcon Kind="CodeGreaterThanOrEqual" Width="150" Height="150" HorizontalAlignment="Center" />
|
||||||
|
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" HorizontalAlignment="Center">Get ready to start scripting!</TextBlock>
|
||||||
|
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" HorizontalAlignment="Center">Use the sidebar to create new scripts and manage existing scripts.</TextBlock>
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</materialDesign:DialogHost>
|
</materialDesign:DialogHost>
|
||||||
</mde:MaterialWindow>
|
</mde:MaterialWindow>
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
@ -11,16 +13,15 @@ using Stylet;
|
|||||||
|
|
||||||
namespace Artemis.UI.Screens.Scripting
|
namespace Artemis.UI.Screens.Scripting
|
||||||
{
|
{
|
||||||
public class ScriptsDialogViewModel : Conductor<ScriptConfigurationViewModel>.Collection.OneActive
|
public class ScriptsDialogViewModel : Conductor<IScriptEditorViewModel>
|
||||||
{
|
{
|
||||||
private readonly IScriptingService _scriptingService;
|
private readonly IScriptingService _scriptingService;
|
||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
private readonly IProfileService _profileService;
|
private readonly IProfileService _profileService;
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
private readonly IScriptVmFactory _scriptVmFactory;
|
private readonly IScriptVmFactory _scriptVmFactory;
|
||||||
public Profile Profile { get; }
|
private readonly Dictionary<ScriptingProvider, IScriptEditorViewModel> _providerViewModels = new();
|
||||||
public Layer Layer { get; }
|
private ScriptConfigurationViewModel _selectedScript;
|
||||||
public ILayerProperty LayerProperty { get; }
|
|
||||||
|
|
||||||
public ScriptsDialogViewModel(Profile profile,
|
public ScriptsDialogViewModel(Profile profile,
|
||||||
IScriptingService scriptingService,
|
IScriptingService scriptingService,
|
||||||
@ -36,27 +37,56 @@ namespace Artemis.UI.Screens.Scripting
|
|||||||
_scriptVmFactory = scriptVmFactory;
|
_scriptVmFactory = scriptVmFactory;
|
||||||
|
|
||||||
DisplayName = "Artemis | Profile Scripts";
|
DisplayName = "Artemis | Profile Scripts";
|
||||||
|
ScriptType = ScriptType.Profile;
|
||||||
Profile = profile ?? throw new ArgumentNullException(nameof(profile));
|
Profile = profile ?? throw new ArgumentNullException(nameof(profile));
|
||||||
|
|
||||||
Items.AddRange(Profile.ScriptConfigurations.Select(scriptVmFactory.ScriptConfigurationViewModel));
|
ScriptConfigurations.AddRange(Profile.ScriptConfigurations.Select(scriptVmFactory.ScriptConfigurationViewModel));
|
||||||
|
ScriptConfigurations.CollectionChanged += ItemsOnCollectionChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptsDialogViewModel(Layer layer, IDialogService dialogService)
|
public ScriptType ScriptType { get; }
|
||||||
{
|
public Profile Profile { get; }
|
||||||
_dialogService = dialogService;
|
public BindableCollection<ScriptConfigurationViewModel> ScriptConfigurations { get; } = new();
|
||||||
DisplayName = "Artemins | Layer Scripts";
|
public bool HasScripts => ScriptConfigurations.Any();
|
||||||
Layer = layer ?? throw new ArgumentNullException(nameof(layer));
|
|
||||||
|
|
||||||
Items.AddRange(Layer.ScriptConfigurations.Select(_scriptVmFactory.ScriptConfigurationViewModel));
|
public ScriptConfigurationViewModel SelectedScript
|
||||||
|
{
|
||||||
|
get => _selectedScript;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!SetAndNotify(ref _selectedScript, value)) return;
|
||||||
|
SetupScriptEditor(_selectedScript?.ScriptConfiguration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptsDialogViewModel(ILayerProperty layerProperty, IDialogService dialogService)
|
private void SetupScriptEditor(ScriptConfiguration scriptConfiguration)
|
||||||
{
|
{
|
||||||
_dialogService = dialogService;
|
if (scriptConfiguration == null)
|
||||||
DisplayName = "Artemins | Layer Property Scripts";
|
{
|
||||||
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
|
ActiveItem = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Items.AddRange(Layer.ScriptConfigurations.Select(_scriptVmFactory.ScriptConfigurationViewModel));
|
// The script is null if the provider is missing
|
||||||
|
if (scriptConfiguration.Script == null)
|
||||||
|
{
|
||||||
|
ActiveItem = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_providerViewModels.TryGetValue(scriptConfiguration.Script.ScriptingProvider, out IScriptEditorViewModel viewModel))
|
||||||
|
{
|
||||||
|
viewModel = scriptConfiguration.Script.ScriptingProvider.CreateScriptEditor(ScriptType);
|
||||||
|
_providerViewModels.Add(scriptConfiguration.Script.ScriptingProvider, viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveItem = viewModel;
|
||||||
|
ActiveItem.ChangeScript(scriptConfiguration.Script);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
NotifyOfPropertyChange(nameof(HasScripts));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddScriptConfiguration()
|
public async Task AddScriptConfiguration()
|
||||||
@ -70,30 +100,71 @@ namespace Artemis.UI.Screens.Scripting
|
|||||||
Profile.ScriptConfigurations.Add(scriptConfiguration);
|
Profile.ScriptConfigurations.Add(scriptConfiguration);
|
||||||
_scriptingService.CreateScriptInstance(Profile, scriptConfiguration);
|
_scriptingService.CreateScriptInstance(Profile, scriptConfiguration);
|
||||||
}
|
}
|
||||||
else if (Layer != null)
|
|
||||||
{
|
ScriptConfigurationViewModel viewModel = _scriptVmFactory.ScriptConfigurationViewModel(scriptConfiguration);
|
||||||
Layer.ScriptConfigurations.Add(scriptConfiguration);
|
ScriptConfigurations.Add(viewModel);
|
||||||
_scriptingService.CreateScriptInstance(Layer, scriptConfiguration);
|
SelectedScript = viewModel;
|
||||||
}
|
|
||||||
else if (LayerProperty != null)
|
|
||||||
{
|
|
||||||
LayerProperty.ScriptConfigurations.Add(scriptConfiguration);
|
|
||||||
_scriptingService.CreateScriptInstance(LayerProperty, scriptConfiguration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Items.Add(_scriptVmFactory.ScriptConfigurationViewModel(scriptConfiguration));
|
public async Task ViewProperties(ScriptConfigurationViewModel scriptConfigurationViewModel)
|
||||||
|
{
|
||||||
|
object result = await _dialogService.ShowDialogAt<ScriptConfigurationEditViewModel>(
|
||||||
|
"ScriptsDialog",
|
||||||
|
new Dictionary<string, object> {{"scriptConfiguration", scriptConfigurationViewModel.ScriptConfiguration}}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result is nameof(ScriptConfigurationEditViewModel.Delete))
|
||||||
|
await Delete(scriptConfigurationViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Overrides of OneActive
|
private async Task Delete(ScriptConfigurationViewModel scriptConfigurationViewModel)
|
||||||
|
{
|
||||||
|
bool result = await _dialogService.ShowConfirmDialogAt(
|
||||||
|
"ScriptsDialog",
|
||||||
|
"Delete script",
|
||||||
|
$"Are you sure you want to delete '{scriptConfigurationViewModel.ScriptConfiguration.Name}'?"
|
||||||
|
);
|
||||||
|
if (!result)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (scriptConfigurationViewModel.Script)
|
||||||
|
{
|
||||||
|
case GlobalScript:
|
||||||
|
_scriptingService.DeleteScript(scriptConfigurationViewModel.ScriptConfiguration);
|
||||||
|
break;
|
||||||
|
case ProfileScript profileScript:
|
||||||
|
profileScript.Profile.ScriptConfigurations.Remove(scriptConfigurationViewModel.ScriptConfiguration);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptConfigurationViewModel.ScriptConfiguration.DiscardPendingChanges();
|
||||||
|
scriptConfigurationViewModel.ScriptConfiguration.Script?.Dispose();
|
||||||
|
|
||||||
|
SelectedScript = null;
|
||||||
|
ScriptConfigurations.Remove(scriptConfigurationViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Overrides of Screen
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void OnInitialActivate()
|
||||||
|
{
|
||||||
|
SelectedScript = ScriptConfigurations.FirstOrDefault();
|
||||||
|
base.OnInitialActivate();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnClose()
|
protected override void OnClose()
|
||||||
|
{
|
||||||
|
if (Profile != null)
|
||||||
{
|
{
|
||||||
if (_profileEditorService.SelectedProfile == Profile)
|
if (_profileEditorService.SelectedProfile == Profile)
|
||||||
_profileEditorService.SaveSelectedProfileConfiguration();
|
_profileEditorService.SaveSelectedProfileConfiguration();
|
||||||
else
|
else
|
||||||
_profileService.SaveProfile(Profile, false);
|
_profileService.SaveProfile(Profile, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptConfigurations.CollectionChanged -= ItemsOnCollectionChanged;
|
||||||
base.OnClose();
|
base.OnClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -154,7 +154,7 @@ namespace Artemis.UI.Screens.Sidebar
|
|||||||
VistaOpenFileDialog dialog = new()
|
VistaOpenFileDialog dialog = new()
|
||||||
{
|
{
|
||||||
Filter = "Artemis Profile|*.json",
|
Filter = "Artemis Profile|*.json",
|
||||||
Title = "Export Artemis profile"
|
Title = "Import Artemis profile"
|
||||||
};
|
};
|
||||||
bool? result = dialog.ShowDialog();
|
bool? result = dialog.ShowDialog();
|
||||||
if (result != true)
|
if (result != true)
|
||||||
|
|||||||
@ -92,9 +92,8 @@ namespace Artemis.UI.Screens.Sidebar
|
|||||||
ProfileConfigurationExportModel profileConfigurationExportModel = _profileService.ExportProfile(ProfileConfiguration);
|
ProfileConfigurationExportModel profileConfigurationExportModel = _profileService.ExportProfile(ProfileConfiguration);
|
||||||
string json = JsonConvert.SerializeObject(profileConfigurationExportModel, IProfileService.ExportSettings);
|
string json = JsonConvert.SerializeObject(profileConfigurationExportModel, IProfileService.ExportSettings);
|
||||||
|
|
||||||
if (!dialog.FileName.EndsWith(".json"))
|
string path = Path.ChangeExtension(dialog.FileName, ".json");
|
||||||
dialog.FileName += ".json";
|
await File.WriteAllTextAsync(path, json);
|
||||||
await File.WriteAllTextAsync(dialog.FileName, json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Duplicate()
|
public void Duplicate()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user