1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.VisualScripting/Nodes/Static/Screens/DisplayValueNodeCustomViewModel.cs
Robert d2e0607622 Nodes - Fixed string format node not outputting numerics
Data model event node - Renamed to Data Model-Event Value Cycle
Data model event node - Added new data model event node that outputs the latest event data
Event conditions - Performance improvements
2022-08-23 20:35:25 +02:00

45 lines
1.3 KiB
C#

using System.Reactive.Disposables;
using Artemis.Core;
using Artemis.UI.Shared.VisualScripting;
using Avalonia.Threading;
using ReactiveUI;
namespace Artemis.VisualScripting.Nodes.Static.Screens;
public class DisplayValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly DisplayValueNode _node;
private object? _currentValue;
public DisplayValueNodeCustomViewModel(DisplayValueNode node, INodeScript script) : base(node, script)
{
_node = node;
// Because the DisplayValueNode has no output it never evaluates, manually do so here
this.WhenActivated(d =>
{
DispatcherTimer updateTimer = new(TimeSpan.FromMilliseconds(25.0 / 1000), DispatcherPriority.Normal, Update);
updateTimer.Start();
Disposable.Create(() => updateTimer.Stop()).DisposeWith(d);
});
}
public object? CurrentValue
{
get => _currentValue;
private set => this.RaiseAndSetIfChanged(ref _currentValue, value);
}
private void Update(object? sender, EventArgs e)
{
try
{
CurrentValue = _node.Input.Value;
}
catch (Exception ex)
{
// Don't crash the timer on exceptions and display the messages as a bit of a nice to have
CurrentValue = ex.Message;
}
}
}