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:
parent
eec2419005
commit
5c4175ed9c
@ -38,7 +38,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// The full path to the Artemis data folder
|
||||
/// </summary>
|
||||
public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis.Avalonia");
|
||||
public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis");
|
||||
|
||||
/// <summary>
|
||||
/// The full path to the Artemis logs folder
|
||||
|
||||
@ -382,7 +382,7 @@ namespace Artemis.Core
|
||||
|
||||
if (ShouldBeEnabled)
|
||||
Enable();
|
||||
else if (Timeline.IsFinished && !_renderCopies.Any())
|
||||
else if (Suspended || (Timeline.IsFinished && !_renderCopies.Any()))
|
||||
Disable();
|
||||
|
||||
if (Timeline.Delta == TimeSpan.Zero)
|
||||
|
||||
@ -60,6 +60,7 @@ namespace Artemis.Core
|
||||
int value => value,
|
||||
double value => (float) value,
|
||||
byte value => value,
|
||||
Numeric value => value,
|
||||
_ => ParseFloatOrDefault(pathValue?.ToString())
|
||||
};
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ namespace Artemis.Core
|
||||
: base(node, name)
|
||||
{
|
||||
Value = default;
|
||||
IsNumeric = typeof(T) == typeof(Numeric);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -80,6 +81,7 @@ namespace Artemis.Core
|
||||
{
|
||||
_type = type;
|
||||
_value = type.GetDefault();
|
||||
IsNumeric = type == typeof(Numeric);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -103,6 +105,7 @@ namespace Artemis.Core
|
||||
// Change the type
|
||||
SetAndNotify(ref _type, type, nameof(Type));
|
||||
Value = type.GetDefault();
|
||||
IsNumeric = type == typeof(Numeric);
|
||||
}
|
||||
|
||||
private void Evaluate()
|
||||
@ -169,7 +172,7 @@ namespace Artemis.Core
|
||||
OnPropertyChanged(nameof(PinValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -29,6 +29,11 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
Type Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the type of this pin is numeric.
|
||||
/// </summary>
|
||||
bool IsNumeric { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value the pin holds
|
||||
/// </summary>
|
||||
|
||||
@ -47,7 +47,10 @@ internal class EventConditionEventStartNode : DefaultNode, IEventConditionNode
|
||||
foreach ((PropertyInfo propertyInfo, OutputPin outputPin) in _propertyPins)
|
||||
{
|
||||
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
|
||||
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 (pin == null)
|
||||
{
|
||||
|
||||
@ -20,10 +20,11 @@ internal class EventConditionValueChangedStartNode : DefaultNode, IEventConditio
|
||||
|
||||
public void UpdateOutputPins(DataModelPath dataModelPath)
|
||||
{
|
||||
Type? type = dataModelPath?.GetPropertyType();
|
||||
if (Numeric.IsTypeCompatible(type))
|
||||
Type? type = dataModelPath.GetPropertyType();
|
||||
if (type == null)
|
||||
type = typeof(object);
|
||||
else if (Numeric.IsTypeCompatible(type))
|
||||
type = typeof(Numeric);
|
||||
type ??= typeof(object);
|
||||
|
||||
if (NewValue.Type != type)
|
||||
NewValue.ChangeType(type);
|
||||
@ -33,8 +34,8 @@ internal class EventConditionValueChangedStartNode : DefaultNode, IEventConditio
|
||||
|
||||
public void UpdateValues(object? newValue, object? oldValue)
|
||||
{
|
||||
_newValue = newValue;
|
||||
_oldValue = oldValue;
|
||||
_newValue = NewValue.IsNumeric ? new Numeric(newValue) : newValue;
|
||||
_oldValue = OldValue.IsNumeric ? new Numeric(oldValue) : oldValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -17,6 +17,7 @@ namespace Artemis.Core
|
||||
: base(node, name)
|
||||
{
|
||||
_value = default;
|
||||
IsNumeric = typeof(T) == typeof(Numeric);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -70,6 +71,7 @@ namespace Artemis.Core
|
||||
{
|
||||
_type = type;
|
||||
_value = type.GetDefault();
|
||||
IsNumeric = type == typeof(Numeric);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -90,6 +92,7 @@ namespace Artemis.Core
|
||||
// Change the type
|
||||
SetAndNotify(ref _type, type, nameof(Type));
|
||||
Value = type.GetDefault();
|
||||
IsNumeric = type == typeof(Numeric);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -50,10 +50,19 @@ namespace Artemis.Core
|
||||
get => _isEvaluated;
|
||||
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 string _name;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IPin> ConnectedTo => new ReadOnlyCollection<IPin>(_connectedTo);
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ public class DataModelDebugViewModel : ActivatableViewModelBase, IRoutableViewMo
|
||||
{
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(25), DispatcherPriority.Normal, (_, _) => Update());
|
||||
_updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(25), DispatcherPriority.DataBind, (_, _) => Update());
|
||||
|
||||
HostScreen = hostScreen;
|
||||
Modules = new ObservableCollection<Module>();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
@ -13,52 +14,36 @@ namespace Artemis.UI.Screens.Plugins;
|
||||
public class PluginSettingsViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private Plugin _plugin;
|
||||
|
||||
private readonly ISettingsVmFactory _settingsVmFactory;
|
||||
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly INotificationService _notificationService;
|
||||
|
||||
private PluginViewModel _pluginViewModel;
|
||||
|
||||
public PluginSettingsViewModel(Plugin plugin, ISettingsVmFactory settingsVmFactory, IPluginManagementService pluginManagementService, INotificationService notificationService)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_settingsVmFactory = settingsVmFactory;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_notificationService = notificationService;
|
||||
|
||||
Reload = ReactiveCommand.CreateFromTask(ExecuteReload);
|
||||
|
||||
PluginViewModel = settingsVmFactory.PluginViewModel(_plugin, Reload);
|
||||
PluginFeatures = new ObservableCollection<PluginFeatureViewModel>();
|
||||
foreach (PluginFeatureInfo pluginFeatureInfo in _plugin.Features)
|
||||
PluginFeatures.Add(settingsVmFactory.PluginFeatureViewModel(pluginFeatureInfo, false));
|
||||
PluginFeatures = new ObservableCollection<PluginFeatureViewModel>(_plugin.Features.Select(f => settingsVmFactory.PluginFeatureViewModel(f, false)));
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Reload { get; }
|
||||
|
||||
public PluginViewModel PluginViewModel
|
||||
{
|
||||
get => _pluginViewModel;
|
||||
private set => RaiseAndSetIfChanged(ref _pluginViewModel, value);
|
||||
}
|
||||
public PluginViewModel PluginViewModel { get; }
|
||||
|
||||
public ObservableCollection<PluginFeatureViewModel> PluginFeatures { get; }
|
||||
|
||||
private async Task ExecuteReload()
|
||||
{
|
||||
// Unloading the plugin will remove this viewmodel, this method is it's final act 😭
|
||||
bool wasEnabled = _plugin.IsEnabled;
|
||||
await Task.Run(() => _pluginManagementService.UnloadPlugin(_plugin));
|
||||
|
||||
PluginFeatures.Clear();
|
||||
_plugin = _pluginManagementService.LoadPlugin(_plugin.Directory);
|
||||
|
||||
PluginViewModel = _settingsVmFactory.PluginViewModel(_plugin, Reload);
|
||||
foreach (PluginFeatureInfo pluginFeatureInfo in _plugin.Features)
|
||||
PluginFeatures.Add(_settingsVmFactory.PluginFeatureViewModel(pluginFeatureInfo, false));
|
||||
|
||||
if (wasEnabled)
|
||||
await PluginViewModel.UpdateEnabled(true);
|
||||
await Task.Run(() => _pluginManagementService.EnablePlugin(_plugin, true, true));
|
||||
|
||||
_notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show();
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class DisplayConditionScriptViewModel : ActivatableViewModelBase
|
||||
.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;
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
Classes="icon-button icon-button-small"
|
||||
ToolTip.Tip="Toggle suspended state"
|
||||
IsChecked="{CompiledBinding Folder.Suspended}"
|
||||
Focusable="False"
|
||||
VerticalAlignment="Center"
|
||||
Margin="4 0">
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
Classes="icon-button icon-button-small"
|
||||
ToolTip.Tip="Toggle suspended state"
|
||||
IsChecked="{CompiledBinding Layer.Suspended}"
|
||||
Focusable="False"
|
||||
VerticalAlignment="Center"
|
||||
Margin="4 0">
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
|
||||
@ -31,6 +31,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
|
||||
private ProfileElement? _profileElement;
|
||||
private string? _renameValue;
|
||||
private bool _renaming;
|
||||
private TimeSpan _time;
|
||||
|
||||
protected TreeItemViewModel(TreeItemViewModel? parent,
|
||||
ProfileElement? profileElement,
|
||||
@ -56,6 +57,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
ProfileEditorService.Time.Subscribe(t => _time = t).DisposeWith(d);
|
||||
ProfileEditorService.ProfileElement.Subscribe(element => _currentProfileElement = element).DisposeWith(d);
|
||||
SubscribeToProfileElement(d);
|
||||
CreateTreeItems();
|
||||
@ -173,6 +175,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase
|
||||
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildRemoved += x, x => ProfileElement.ChildRemoved -= x)
|
||||
.Subscribe(c => RemoveTreeItemsIfFound(c.Sender, c.EventArgs.ProfileElement))
|
||||
.DisposeWith(d);
|
||||
ProfileElement.WhenAnyValue(e => e.Suspended).Subscribe(_ => ProfileEditorService.ChangeTime(_time)).DisposeWith(d);
|
||||
}
|
||||
|
||||
protected void RemoveTreeItemsIfFound(object? sender, ProfileElement profileElement)
|
||||
|
||||
@ -42,16 +42,17 @@ public class DataModelNode : Node<DataModelPathEntity, DataModelNodeCustomViewMo
|
||||
}
|
||||
else
|
||||
{
|
||||
Output.Value = Output.Type == typeof(Numeric) ? new Numeric(pathValue) : pathValue;
|
||||
Output.Value = Output.IsNumeric ? new Numeric(pathValue) : pathValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateOutputPin()
|
||||
{
|
||||
Type? type = _dataModelPath?.GetPropertyType();
|
||||
if (Numeric.IsTypeCompatible(type))
|
||||
if (type == null)
|
||||
type = typeof(object);
|
||||
else if (Numeric.IsTypeCompatible(type))
|
||||
type = typeof(Numeric);
|
||||
type ??= typeof(object);
|
||||
|
||||
if (Output.Type != type)
|
||||
Output.ChangeType(type);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user