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

Editor - Fixed suspending layers

Editor - Disable suspending layers with spacebar
Nodes - Fixed changed event source node not using numerics
Nodes - Simplify checking wether a pin is numeric
This commit is contained in:
Robert 2022-07-31 17:17:37 +02:00
parent eec2419005
commit 5c4175ed9c
16 changed files with 55 additions and 36 deletions

View File

@ -38,7 +38,7 @@ namespace Artemis.Core
/// <summary> /// <summary>
/// The full path to the Artemis data folder /// The full path to the Artemis data folder
/// </summary> /// </summary>
public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis.Avalonia"); public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis");
/// <summary> /// <summary>
/// The full path to the Artemis logs folder /// The full path to the Artemis logs folder

View File

@ -382,7 +382,7 @@ namespace Artemis.Core
if (ShouldBeEnabled) if (ShouldBeEnabled)
Enable(); Enable();
else if (Timeline.IsFinished && !_renderCopies.Any()) else if (Suspended || (Timeline.IsFinished && !_renderCopies.Any()))
Disable(); Disable();
if (Timeline.Delta == TimeSpan.Zero) if (Timeline.Delta == TimeSpan.Zero)

View File

@ -60,6 +60,7 @@ namespace Artemis.Core
int value => value, int value => value,
double value => (float) value, double value => (float) value,
byte value => value, byte value => value,
Numeric value => value,
_ => ParseFloatOrDefault(pathValue?.ToString()) _ => ParseFloatOrDefault(pathValue?.ToString())
}; };
} }

View File

@ -17,6 +17,7 @@ namespace Artemis.Core
: base(node, name) : base(node, name)
{ {
Value = default; Value = default;
IsNumeric = typeof(T) == typeof(Numeric);
} }
#endregion #endregion
@ -80,6 +81,7 @@ namespace Artemis.Core
{ {
_type = type; _type = type;
_value = type.GetDefault(); _value = type.GetDefault();
IsNumeric = type == typeof(Numeric);
} }
#endregion #endregion
@ -103,6 +105,7 @@ namespace Artemis.Core
// Change the type // Change the type
SetAndNotify(ref _type, type, nameof(Type)); SetAndNotify(ref _type, type, nameof(Type));
Value = type.GetDefault(); Value = type.GetDefault();
IsNumeric = type == typeof(Numeric);
} }
private void Evaluate() private void Evaluate()

View File

@ -29,6 +29,11 @@ namespace Artemis.Core
/// </summary> /// </summary>
Type Type { get; } Type Type { get; }
/// <summary>
/// Gets a boolean indicating whether the type of this pin is numeric.
/// </summary>
bool IsNumeric { get; }
/// <summary> /// <summary>
/// Gets the value the pin holds /// Gets the value the pin holds
/// </summary> /// </summary>

View File

@ -47,7 +47,10 @@ internal class EventConditionEventStartNode : DefaultNode, IEventConditionNode
foreach ((PropertyInfo propertyInfo, OutputPin outputPin) in _propertyPins) foreach ((PropertyInfo propertyInfo, OutputPin outputPin) in _propertyPins)
{ {
if (outputPin.ConnectedTo.Any()) if (outputPin.ConnectedTo.Any())
outputPin.Value = propertyInfo.GetValue(_dataModelEvent.LastEventArgumentsUntyped) ?? outputPin.Type.GetDefault()!; {
object value = propertyInfo.GetValue(_dataModelEvent.LastEventArgumentsUntyped) ?? outputPin.Type.GetDefault()!;
outputPin.Value = outputPin.IsNumeric ? new Numeric(value) : value;
}
} }
} }
@ -61,6 +64,9 @@ internal class EventConditionEventStartNode : DefaultNode, IEventConditionNode
// Grab the first pin from the bucket that isn't on the node yet // Grab the first pin from the bucket that isn't on the node yet
OutputPin? pin = _pinBucket.FirstOrDefault(p => !Pins.Contains(p)); OutputPin? pin = _pinBucket.FirstOrDefault(p => !Pins.Contains(p));
if (Numeric.IsTypeCompatible(valueType))
valueType = typeof(Numeric);
// If there is none, create a new one and add it to the bucket // If there is none, create a new one and add it to the bucket
if (pin == null) if (pin == null)
{ {

View File

@ -20,10 +20,11 @@ internal class EventConditionValueChangedStartNode : DefaultNode, IEventConditio
public void UpdateOutputPins(DataModelPath dataModelPath) public void UpdateOutputPins(DataModelPath dataModelPath)
{ {
Type? type = dataModelPath?.GetPropertyType(); Type? type = dataModelPath.GetPropertyType();
if (Numeric.IsTypeCompatible(type)) if (type == null)
type = typeof(object);
else if (Numeric.IsTypeCompatible(type))
type = typeof(Numeric); type = typeof(Numeric);
type ??= typeof(object);
if (NewValue.Type != type) if (NewValue.Type != type)
NewValue.ChangeType(type); NewValue.ChangeType(type);
@ -33,8 +34,8 @@ internal class EventConditionValueChangedStartNode : DefaultNode, IEventConditio
public void UpdateValues(object? newValue, object? oldValue) public void UpdateValues(object? newValue, object? oldValue)
{ {
_newValue = newValue; _newValue = NewValue.IsNumeric ? new Numeric(newValue) : newValue;
_oldValue = oldValue; _oldValue = OldValue.IsNumeric ? new Numeric(oldValue) : oldValue;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -17,6 +17,7 @@ namespace Artemis.Core
: base(node, name) : base(node, name)
{ {
_value = default; _value = default;
IsNumeric = typeof(T) == typeof(Numeric);
} }
#endregion #endregion
@ -70,6 +71,7 @@ namespace Artemis.Core
{ {
_type = type; _type = type;
_value = type.GetDefault(); _value = type.GetDefault();
IsNumeric = type == typeof(Numeric);
} }
#endregion #endregion
@ -90,6 +92,7 @@ namespace Artemis.Core
// Change the type // Change the type
SetAndNotify(ref _type, type, nameof(Type)); SetAndNotify(ref _type, type, nameof(Type));
Value = type.GetDefault(); Value = type.GetDefault();
IsNumeric = type == typeof(Numeric);
} }
#endregion #endregion

View File

@ -51,6 +51,15 @@ namespace Artemis.Core
set => SetAndNotify(ref _isEvaluated, value); set => SetAndNotify(ref _isEvaluated, value);
} }
private bool _isNumeric;
/// <inheritdoc />
public bool IsNumeric
{
get => _isNumeric;
protected set => SetAndNotify(ref _isNumeric, value);
}
private readonly List<IPin> _connectedTo = new(); private readonly List<IPin> _connectedTo = new();
private string _name; private string _name;

View File

@ -32,7 +32,7 @@ public class DataModelDebugViewModel : ActivatableViewModelBase, IRoutableViewMo
{ {
_dataModelUIService = dataModelUIService; _dataModelUIService = dataModelUIService;
_pluginManagementService = pluginManagementService; _pluginManagementService = pluginManagementService;
_updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(25), DispatcherPriority.Normal, (_, _) => Update()); _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(25), DispatcherPriority.DataBind, (_, _) => Update());
HostScreen = hostScreen; HostScreen = hostScreen;
Modules = new ObservableCollection<Module>(); Modules = new ObservableCollection<Module>();

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Core; using Artemis.Core;
@ -14,51 +15,35 @@ public class PluginSettingsViewModel : ActivatableViewModelBase
{ {
private Plugin _plugin; private Plugin _plugin;
private readonly ISettingsVmFactory _settingsVmFactory;
private readonly IPluginManagementService _pluginManagementService; private readonly IPluginManagementService _pluginManagementService;
private readonly INotificationService _notificationService; private readonly INotificationService _notificationService;
private PluginViewModel _pluginViewModel;
public PluginSettingsViewModel(Plugin plugin, ISettingsVmFactory settingsVmFactory, IPluginManagementService pluginManagementService, INotificationService notificationService) public PluginSettingsViewModel(Plugin plugin, ISettingsVmFactory settingsVmFactory, IPluginManagementService pluginManagementService, INotificationService notificationService)
{ {
_plugin = plugin; _plugin = plugin;
_settingsVmFactory = settingsVmFactory;
_pluginManagementService = pluginManagementService; _pluginManagementService = pluginManagementService;
_notificationService = notificationService; _notificationService = notificationService;
Reload = ReactiveCommand.CreateFromTask(ExecuteReload); Reload = ReactiveCommand.CreateFromTask(ExecuteReload);
PluginViewModel = settingsVmFactory.PluginViewModel(_plugin, Reload); PluginViewModel = settingsVmFactory.PluginViewModel(_plugin, Reload);
PluginFeatures = new ObservableCollection<PluginFeatureViewModel>(); PluginFeatures = new ObservableCollection<PluginFeatureViewModel>(_plugin.Features.Select(f => settingsVmFactory.PluginFeatureViewModel(f, false)));
foreach (PluginFeatureInfo pluginFeatureInfo in _plugin.Features)
PluginFeatures.Add(settingsVmFactory.PluginFeatureViewModel(pluginFeatureInfo, false));
} }
public ReactiveCommand<Unit, Unit> Reload { get; } public ReactiveCommand<Unit, Unit> Reload { get; }
public PluginViewModel PluginViewModel public PluginViewModel PluginViewModel { get; }
{
get => _pluginViewModel;
private set => RaiseAndSetIfChanged(ref _pluginViewModel, value);
}
public ObservableCollection<PluginFeatureViewModel> PluginFeatures { get; } public ObservableCollection<PluginFeatureViewModel> PluginFeatures { get; }
private async Task ExecuteReload() private async Task ExecuteReload()
{ {
// Unloading the plugin will remove this viewmodel, this method is it's final act 😭
bool wasEnabled = _plugin.IsEnabled; bool wasEnabled = _plugin.IsEnabled;
await Task.Run(() => _pluginManagementService.UnloadPlugin(_plugin)); await Task.Run(() => _pluginManagementService.UnloadPlugin(_plugin));
PluginFeatures.Clear();
_plugin = _pluginManagementService.LoadPlugin(_plugin.Directory); _plugin = _pluginManagementService.LoadPlugin(_plugin.Directory);
PluginViewModel = _settingsVmFactory.PluginViewModel(_plugin, Reload);
foreach (PluginFeatureInfo pluginFeatureInfo in _plugin.Features)
PluginFeatures.Add(_settingsVmFactory.PluginFeatureViewModel(pluginFeatureInfo, false));
if (wasEnabled) if (wasEnabled)
await PluginViewModel.UpdateEnabled(true); await Task.Run(() => _pluginManagementService.EnablePlugin(_plugin, true, true));
_notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show(); _notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show();
} }

View File

@ -44,7 +44,7 @@ public class DisplayConditionScriptViewModel : ActivatableViewModelBase
.DisposeWith(d); .DisposeWith(d);
}); });
_conditionViewModel = this.WhenAnyValue(vm => vm.SelectedConditionTypeViewModel).Select(_ => CreateConditionViewModel()).ToProperty(this, vm => vm.ConditionViewModel); _conditionViewModel = this.WhenAnyValue(vm => vm.SelectedConditionTypeViewModel, vm => vm.ProfileElement).Select(_ => CreateConditionViewModel()).ToProperty(this, vm => vm.ConditionViewModel);
} }
public RenderProfileElement? ProfileElement => _profileElement?.Value; public RenderProfileElement? ProfileElement => _profileElement?.Value;

View File

@ -40,6 +40,7 @@
Classes="icon-button icon-button-small" Classes="icon-button icon-button-small"
ToolTip.Tip="Toggle suspended state" ToolTip.Tip="Toggle suspended state"
IsChecked="{CompiledBinding Folder.Suspended}" IsChecked="{CompiledBinding Folder.Suspended}"
Focusable="False"
VerticalAlignment="Center" VerticalAlignment="Center"
Margin="4 0"> Margin="4 0">
<avalonia:MaterialIcon Kind="Pause" /> <avalonia:MaterialIcon Kind="Pause" />

View File

@ -31,6 +31,7 @@
Classes="icon-button icon-button-small" Classes="icon-button icon-button-small"
ToolTip.Tip="Toggle suspended state" ToolTip.Tip="Toggle suspended state"
IsChecked="{CompiledBinding Layer.Suspended}" IsChecked="{CompiledBinding Layer.Suspended}"
Focusable="False"
VerticalAlignment="Center" VerticalAlignment="Center"
Margin="4 0"> Margin="4 0">
<avalonia:MaterialIcon Kind="Pause" /> <avalonia:MaterialIcon Kind="Pause" />

View File

@ -31,6 +31,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
private ProfileElement? _profileElement; private ProfileElement? _profileElement;
private string? _renameValue; private string? _renameValue;
private bool _renaming; private bool _renaming;
private TimeSpan _time;
protected TreeItemViewModel(TreeItemViewModel? parent, protected TreeItemViewModel(TreeItemViewModel? parent,
ProfileElement? profileElement, ProfileElement? profileElement,
@ -56,6 +57,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
this.WhenActivated(d => this.WhenActivated(d =>
{ {
ProfileEditorService.Time.Subscribe(t => _time = t).DisposeWith(d);
ProfileEditorService.ProfileElement.Subscribe(element => _currentProfileElement = element).DisposeWith(d); ProfileEditorService.ProfileElement.Subscribe(element => _currentProfileElement = element).DisposeWith(d);
SubscribeToProfileElement(d); SubscribeToProfileElement(d);
CreateTreeItems(); CreateTreeItems();
@ -173,6 +175,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildRemoved += x, x => ProfileElement.ChildRemoved -= x) Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildRemoved += x, x => ProfileElement.ChildRemoved -= x)
.Subscribe(c => RemoveTreeItemsIfFound(c.Sender, c.EventArgs.ProfileElement)) .Subscribe(c => RemoveTreeItemsIfFound(c.Sender, c.EventArgs.ProfileElement))
.DisposeWith(d); .DisposeWith(d);
ProfileElement.WhenAnyValue(e => e.Suspended).Subscribe(_ => ProfileEditorService.ChangeTime(_time)).DisposeWith(d);
} }
protected void RemoveTreeItemsIfFound(object? sender, ProfileElement profileElement) protected void RemoveTreeItemsIfFound(object? sender, ProfileElement profileElement)

View File

@ -42,16 +42,17 @@ public class DataModelNode : Node<DataModelPathEntity, DataModelNodeCustomViewMo
} }
else else
{ {
Output.Value = Output.Type == typeof(Numeric) ? new Numeric(pathValue) : pathValue; Output.Value = Output.IsNumeric ? new Numeric(pathValue) : pathValue;
} }
} }
public void UpdateOutputPin() public void UpdateOutputPin()
{ {
Type? type = _dataModelPath?.GetPropertyType(); Type? type = _dataModelPath?.GetPropertyType();
if (Numeric.IsTypeCompatible(type)) if (type == null)
type = typeof(object);
else if (Numeric.IsTypeCompatible(type))
type = typeof(Numeric); type = typeof(Numeric);
type ??= typeof(object);
if (Output.Type != type) if (Output.Type != type)
Output.ChangeType(type); Output.ChangeType(type);