1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Scripting - Fixed broken scripts being applied to profiles in an invalid state

UI - Updated about tab link
This commit is contained in:
Robert 2021-08-30 16:05:11 +02:00
parent fcdfbe61bb
commit 7ad7eaad89
7 changed files with 97 additions and 43 deletions

View File

@ -11,10 +11,6 @@ namespace Artemis.Core.ScriptingProviders
protected ProfileScript(Profile profile, ScriptConfiguration configuration) : base(configuration) protected ProfileScript(Profile profile, ScriptConfiguration configuration) : base(configuration)
{ {
Profile = profile; Profile = profile;
lock (Profile.Scripts)
{
Profile.Scripts.Add(this);
}
} }
/// <summary> /// <summary>

View File

@ -20,8 +20,6 @@ namespace Artemis.Core.ScriptingProviders
throw new ArtemisCoreException("The provided script configuration already has an active script"); throw new ArtemisCoreException("The provided script configuration already has an active script");
ScriptConfiguration = configuration; ScriptConfiguration = configuration;
ScriptConfiguration.Script = this;
ScriptConfiguration.PropertyChanged += ScriptConfigurationOnPropertyChanged; ScriptConfiguration.PropertyChanged += ScriptConfigurationOnPropertyChanged;
} }

View File

@ -305,10 +305,17 @@ namespace Artemis.Core.Services
} }
} }
public bool IsKeyDown(KeyboardKey key)
{
return _pressedKeys.Any(p => p.Value.Contains(key));
}
#endregion #endregion
#region Mouse #region Mouse
private readonly HashSet<MouseButton> _pressedButtons = new();
private void InputProviderOnMouseButtonDataReceived(object? sender, InputProviderMouseButtonEventArgs e) private void InputProviderOnMouseButtonDataReceived(object? sender, InputProviderMouseButtonEventArgs e)
{ {
bool foundLedId = InputKeyUtilities.MouseButtonLedIdMap.TryGetValue(e.Button, out LedId ledId); bool foundLedId = InputKeyUtilities.MouseButtonLedIdMap.TryGetValue(e.Button, out LedId ledId);
@ -320,9 +327,17 @@ namespace Artemis.Core.Services
ArtemisMouseButtonUpDownEventArgs eventArgs = new(e.Device, led, e.Button, e.IsDown); ArtemisMouseButtonUpDownEventArgs eventArgs = new(e.Device, led, e.Button, e.IsDown);
OnMouseButtonUpDown(eventArgs); OnMouseButtonUpDown(eventArgs);
if (e.IsDown) if (e.IsDown)
{
if (!_pressedButtons.Contains(e.Button))
_pressedButtons.Add(e.Button);
OnMouseButtonDown(eventArgs); OnMouseButtonDown(eventArgs);
}
else else
{
if (_pressedButtons.Contains(e.Button))
_pressedButtons.Remove(e.Button);
OnMouseButtonUp(eventArgs); OnMouseButtonUp(eventArgs);
}
// _logger.Verbose("Mouse button data: LED ID: {ledId}, button: {button}, is down: {isDown}, device: {device} ", ledId, e.Button, e.IsDown, e.Device); // _logger.Verbose("Mouse button data: LED ID: {ledId}, button: {button}, is down: {isDown}, device: {device} ", ledId, e.Button, e.IsDown, e.Device);
} }
@ -339,6 +354,11 @@ namespace Artemis.Core.Services
// _logger.Verbose("Mouse move data: XY: {X},{Y} - delta XY: {deltaX},{deltaY} - device: {device} ", e.CursorX, e.CursorY, e.DeltaX, e.DeltaY, e.Device); // _logger.Verbose("Mouse move data: XY: {X},{Y} - delta XY: {deltaX},{deltaY} - device: {device} ", e.CursorX, e.CursorY, e.DeltaX, e.DeltaY, e.Device);
} }
public bool IsButtonDown(MouseButton button)
{
return _pressedButtons.Contains(button);
}
#endregion #endregion
#region Events #region Events

View File

@ -40,7 +40,19 @@ namespace Artemis.Core.Services
/// </summary> /// </summary>
void ReleaseAll(); void ReleaseAll();
#region Events /// <summary>
/// Determines whether the provided key is pressed by any device
/// </summary>
/// <param name="key">The key to check</param>
/// <returns><see langword="true" /> if the key is pressed; otherwise <see langword="false" /></returns>
bool IsKeyDown(KeyboardKey key);
/// <summary>
/// Determines whether the button key is pressed by any device
/// </summary>
/// <param name="button">The button to check</param>
/// <returns><see langword="true" /> if the button is pressed; otherwise <see langword="false" /></returns>
bool IsButtonDown(MouseButton button);
/// <summary> /// <summary>
/// Occurs whenever a key on a keyboard was pressed or released /// Occurs whenever a key on a keyboard was pressed or released
@ -92,8 +104,6 @@ namespace Artemis.Core.Services
/// </summary> /// </summary>
public event EventHandler DeviceIdentified; public event EventHandler DeviceIdentified;
#endregion
#region Identification #region Identification
/// <summary> /// <summary>

View File

@ -6,17 +6,20 @@ using System.Reflection;
using Artemis.Core.ScriptingProviders; using Artemis.Core.ScriptingProviders;
using Ninject; using Ninject;
using Ninject.Parameters; using Ninject.Parameters;
using Serilog;
namespace Artemis.Core.Services namespace Artemis.Core.Services
{ {
internal class ScriptingService : IScriptingService internal class ScriptingService : IScriptingService
{ {
private readonly ILogger _logger;
private readonly IPluginManagementService _pluginManagementService; private readonly IPluginManagementService _pluginManagementService;
private readonly IProfileService _profileService; private readonly IProfileService _profileService;
private List<ScriptingProvider> _scriptingProviders; private List<ScriptingProvider> _scriptingProviders;
public ScriptingService(IPluginManagementService pluginManagementService, IProfileService profileService) public ScriptingService(ILogger logger, IPluginManagementService pluginManagementService, IProfileService profileService)
{ {
_logger = logger;
_pluginManagementService = pluginManagementService; _pluginManagementService = pluginManagementService;
_profileService = profileService; _profileService = profileService;
@ -80,6 +83,9 @@ namespace Artemis.Core.Services
public ReadOnlyCollection<GlobalScript> GlobalScripts => InternalGlobalScripts.AsReadOnly(); public ReadOnlyCollection<GlobalScript> GlobalScripts => InternalGlobalScripts.AsReadOnly();
public GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration) public GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration)
{
GlobalScript? script = null;
try
{ {
if (scriptConfiguration.Script != null) if (scriptConfiguration.Script != null)
throw new ArtemisCoreException("The provided script configuration already has an active script"); throw new ArtemisCoreException("The provided script configuration already has an active script");
@ -88,7 +94,7 @@ namespace Artemis.Core.Services
if (provider == null) if (provider == null)
return null; return null;
GlobalScript script = (GlobalScript) provider.Plugin.Kernel!.Get( script = (GlobalScript) provider.Plugin.Kernel!.Get(
provider.GlobalScriptType, provider.GlobalScriptType,
CreateScriptConstructorArgument(provider.GlobalScriptType, scriptConfiguration) CreateScriptConstructorArgument(provider.GlobalScriptType, scriptConfiguration)
); );
@ -97,10 +103,22 @@ namespace Artemis.Core.Services
script.ScriptingService = this; script.ScriptingService = this;
provider.InternalScripts.Add(script); provider.InternalScripts.Add(script);
InternalGlobalScripts.Add(script); InternalGlobalScripts.Add(script);
scriptConfiguration.Script = script;
return script; return script;
} }
catch (Exception e)
{
_logger.Warning(e, "Failed to initialize global script");
script?.Dispose();
return null;
}
}
public ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration) public ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration)
{
ProfileScript? script = null;
try
{ {
if (scriptConfiguration.Script != null) if (scriptConfiguration.Script != null)
throw new ArtemisCoreException("The provided script configuration already has an active script"); throw new ArtemisCoreException("The provided script configuration already has an active script");
@ -109,7 +127,7 @@ namespace Artemis.Core.Services
if (provider == null) if (provider == null)
return null; return null;
ProfileScript script = (ProfileScript) provider.Plugin.Kernel!.Get( script = (ProfileScript) provider.Plugin.Kernel!.Get(
provider.ProfileScriptType, provider.ProfileScriptType,
CreateScriptConstructorArgument(provider.ProfileScriptType, profile), CreateScriptConstructorArgument(provider.ProfileScriptType, profile),
CreateScriptConstructorArgument(provider.ProfileScriptType, scriptConfiguration) CreateScriptConstructorArgument(provider.ProfileScriptType, scriptConfiguration)
@ -117,8 +135,21 @@ namespace Artemis.Core.Services
script.ScriptingProvider = provider; script.ScriptingProvider = provider;
provider.InternalScripts.Add(script); provider.InternalScripts.Add(script);
lock (profile)
{
scriptConfiguration.Script = script;
profile.Scripts.Add(script);
}
return script; return script;
} }
catch (Exception e)
{
_logger.Warning(e, "Failed to initialize profile script");
script?.Dispose();
return null;
}
}
/// <inheritdoc /> /// <inheritdoc />
public void DeleteScript(ScriptConfiguration scriptConfiguration) public void DeleteScript(ScriptConfiguration scriptConfiguration)

View File

@ -3,7 +3,6 @@ using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Castle.Core.Internal;
using FluentValidation; using FluentValidation;
using Stylet; using Stylet;
@ -70,7 +69,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Dialogs
if (parts.Length == 1) if (parts.Length == 1)
return TimeSpan.FromSeconds(double.Parse(parts[0])); return TimeSpan.FromSeconds(double.Parse(parts[0]));
// Only milliseconds provided with a leading . // Only milliseconds provided with a leading .
if (parts[0].IsNullOrEmpty()) if (string.IsNullOrEmpty(parts[0]))
{ {
// Add trailing zeros so 2.5 becomes 2.500, can't seem to make double.Parse do that // Add trailing zeros so 2.5 becomes 2.500, can't seem to make double.Parse do that
while (parts[0].Length < 3) parts[0] += "0"; while (parts[0].Length < 3) parts[0] += "0";

View File

@ -96,7 +96,7 @@
Grid.Column="1" Grid.Column="1"
Style="{StaticResource MaterialDesignBody1TextBlock}" Style="{StaticResource MaterialDesignBody1TextBlock}"
Padding="0"> Padding="0">
Robert 'Spoinky' Beekman Robert Beekman
</TextBlock> </TextBlock>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
Grid.Row="1" Grid.Row="1"
@ -111,7 +111,7 @@
Style="{StaticResource MaterialDesignIconForegroundButton}" Style="{StaticResource MaterialDesignIconForegroundButton}"
ToolTip="View GitHub profile" ToolTip="View GitHub profile"
Command="{s:Action OpenUrl}" Command="{s:Action OpenUrl}"
CommandParameter="https://github.com/SpoinkyNL/"> CommandParameter="https://github.com/RobertWasTaken/">
<materialDesign:PackIcon Kind="Github" Width="20" Height="20" /> <materialDesign:PackIcon Kind="Github" Width="20" Height="20" />
</Button> </Button>
</StackPanel> </StackPanel>