mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Nodes - Added enum equality node
Conditions - Implemented event trigger conditions
This commit is contained in:
1 parent
00125d1478
commit
d6372dffad
16 files changed
+321
-93
No files matched your search
@@ -10,18 +10,21 @@ namespace Artemis.Core
|
||||
{
|
||||
private readonly string _displayName;
|
||||
private readonly EventConditionEntity _entity;
|
||||
private EventDefaultNode _eventNode;
|
||||
private EventDefaultNode? _eventNode;
|
||||
private TimeLineEventOverlapMode _eventOverlapMode;
|
||||
private DataModelPath? _eventPath;
|
||||
private DateTime _lastProcessedTrigger;
|
||||
private NodeScript<bool>? _script;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="EventCondition" /> class
|
||||
/// </summary>
|
||||
public EventCondition(ProfileElement profileElement)
|
||||
{
|
||||
_entity = new EventConditionEntity();
|
||||
_displayName = profileElement.GetType().Name;
|
||||
|
||||
ProfileElement = profileElement;
|
||||
Script = new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", profileElement.Profile);
|
||||
}
|
||||
|
||||
internal EventCondition(EventConditionEntity entity, ProfileElement profileElement)
|
||||
@@ -36,18 +39,21 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets the script that drives the event condition
|
||||
/// </summary>
|
||||
public NodeScript<bool> Script { get; private set; }
|
||||
public NodeScript<bool>? Script
|
||||
{
|
||||
get => _script;
|
||||
set => SetAndNotify(ref _script, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the event that drives this event condition
|
||||
/// </summary>
|
||||
public DataModelPath? EventPath
|
||||
{
|
||||
set => SetAndNotify(ref _eventPath, value);
|
||||
get => _eventPath;
|
||||
set => SetAndNotify(ref _eventPath, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets how the condition behaves when events trigger before the timeline finishes
|
||||
/// </summary>
|
||||
@@ -62,7 +68,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void UpdateEventNode()
|
||||
{
|
||||
if (EventPath?.GetValue() is not IDataModelEvent dataModelEvent)
|
||||
if (Script == null || EventPath?.GetValue() is not IDataModelEvent dataModelEvent)
|
||||
return;
|
||||
|
||||
if (Script.Nodes.FirstOrDefault(n => n is EventDefaultNode) is EventDefaultNode existing)
|
||||
@@ -72,7 +78,7 @@ namespace Artemis.Core
|
||||
}
|
||||
else
|
||||
{
|
||||
_eventNode = new EventDefaultNode();
|
||||
_eventNode = new EventDefaultNode() {X = -300};
|
||||
_eventNode.UpdateDataModelEvent(dataModelEvent);
|
||||
}
|
||||
|
||||
@@ -82,13 +88,24 @@ namespace Artemis.Core
|
||||
Script.RemoveNode(_eventNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="Script" /> with a new empty node script
|
||||
/// </summary>
|
||||
public void CreateEmptyNodeScript()
|
||||
{
|
||||
Script?.Dispose();
|
||||
Script = new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", ProfileElement.Profile);
|
||||
UpdateEventNode();
|
||||
}
|
||||
|
||||
private bool Evaluate()
|
||||
{
|
||||
if (EventPath?.GetValue() is not IDataModelEvent dataModelEvent || dataModelEvent.LastTrigger <= _lastProcessedTrigger)
|
||||
return false;
|
||||
|
||||
_lastProcessedTrigger = dataModelEvent.LastTrigger;
|
||||
if (!Script.ExitNodeConnected)
|
||||
|
||||
if (Script == null)
|
||||
return true;
|
||||
|
||||
Script.Run();
|
||||
@@ -149,7 +166,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Script.Dispose();
|
||||
Script?.Dispose();
|
||||
EventPath?.Dispose();
|
||||
}
|
||||
|
||||
@@ -159,16 +176,18 @@ namespace Artemis.Core
|
||||
public void Load()
|
||||
{
|
||||
EventOverlapMode = (TimeLineEventOverlapMode) _entity.EventOverlapMode;
|
||||
Script = new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", _entity.Script, ProfileElement.Profile);
|
||||
EventPath = new DataModelPath(_entity.EventPath);
|
||||
if (_entity.Script != null)
|
||||
Script = new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", _entity.Script, ProfileElement.Profile);
|
||||
if (_entity.EventPath != null)
|
||||
EventPath = new DataModelPath(_entity.EventPath);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
_entity.EventOverlapMode = (int) EventOverlapMode;
|
||||
Script.Save();
|
||||
_entity.Script = Script.Entity;
|
||||
Script?.Save();
|
||||
_entity.Script = Script?.Entity;
|
||||
EventPath?.Save();
|
||||
_entity.EventPath = EventPath?.Entity;
|
||||
}
|
||||
@@ -176,6 +195,9 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public void LoadNodeScript()
|
||||
{
|
||||
if (Script == null)
|
||||
return;
|
||||
|
||||
Script.Load();
|
||||
UpdateEventNode();
|
||||
Script.LoadConnections();
|
||||
|
||||
Reference in new issue
Block a user