Profile editor - Integrated visual scripting

This commit is contained in:
Robert committed 2022-04-03 22:21:56 +02:00
1 parent 372991a69b
commit 66ea718316
96 files changed
+2413 -238

No files matched your search

@@ -195,6 +195,9 @@ namespace Artemis.Core
_entity.EventPath = EventPath?.Entity;
}
/// <inheritdoc />
public INodeScript NodeScript => Script;
/// <inheritdoc />
public void LoadNodeScript()
{
@@ -1,51 +1,55 @@
using System;
using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core
namespace Artemis.Core;
/// <summary>
/// Represents a condition applied to a <see cref="ProfileElement" />
/// </summary>
public interface ICondition : IDisposable, IStorageModel
{
/// <summary>
/// Represents a condition applied to a <see cref="ProfileElement" />
/// Gets the entity used to store this condition
/// </summary>
public interface ICondition : IDisposable, IStorageModel
{
/// <summary>
/// Gets the entity used to store this condition
/// </summary>
public IConditionEntity Entity { get; }
/// <summary>
/// Gets the profile element this condition applies to
/// </summary>
public ProfileElement ProfileElement { get; }
/// <summary>
/// Gets a boolean indicating whether the condition is currently met
/// </summary>
bool IsMet { get; }
/// <summary>
/// Updates the condition
/// </summary>
void Update();
/// <summary>
/// Applies the display condition to the provided timeline
/// </summary>
/// <param name="isMet"></param>
/// <param name="wasMet"></param>
/// <param name="timeline">The timeline to apply the display condition to</param>
void ApplyToTimeline(bool isMet, bool wasMet, Timeline timeline);
}
public IConditionEntity Entity { get; }
/// <summary>
/// Represents a condition applied to a <see cref="ProfileElement" /> using a <see cref="INodeScript" />
/// Gets the profile element this condition applies to
/// </summary>
public interface INodeScriptCondition : ICondition
{
/// <summary>
/// Loads the node script this node script condition uses
/// </summary>
void LoadNodeScript();
}
public ProfileElement ProfileElement { get; }
/// <summary>
/// Gets a boolean indicating whether the condition is currently met
/// </summary>
bool IsMet { get; }
/// <summary>
/// Updates the condition
/// </summary>
void Update();
/// <summary>
/// Applies the display condition to the provided timeline
/// </summary>
/// <param name="isMet"></param>
/// <param name="wasMet"></param>
/// <param name="timeline">The timeline to apply the display condition to</param>
void ApplyToTimeline(bool isMet, bool wasMet, Timeline timeline);
}
/// <summary>
/// Represents a condition applied to a <see cref="ProfileElement" /> using a <see cref="INodeScript" />
/// </summary>
public interface INodeScriptCondition : ICondition
{
/// <summary>
/// Gets the node script of this node script condition
/// </summary>
INodeScript? NodeScript { get; }
/// <summary>
/// Loads the node script this node script condition uses
/// </summary>
void LoadNodeScript();
}
@@ -91,6 +91,9 @@ namespace Artemis.Core
_entity.Script = Script.Entity;
}
/// <inheritdoc />
public INodeScript? NodeScript => Script;
/// <inheritdoc />
public void LoadNodeScript()
{
@@ -39,10 +39,8 @@ namespace Artemis.Core
/// Gets the layer property this data binding targets
/// </summary>
public LayerProperty<TLayerProperty> LayerProperty { get; }
/// <summary>
/// Gets the script used to populate the data binding
/// </summary>
/// <inheritdoc />
public INodeScript Script => _script;
/// <summary>
@@ -126,7 +124,7 @@ namespace Artemis.Core
}
/// <summary>
/// Invokes the <see cref="DataBindingDisabled" /> event
/// Invokes the <see cref="DataBindingPropertiesCleared" /> event
/// </summary>
protected virtual void OnDataBindingPropertiesCleared()
{
@@ -11,7 +11,7 @@ namespace Artemis.Core
Setter = setter ?? throw new ArgumentNullException(nameof(setter));
DisplayName = displayName ?? throw new ArgumentNullException(nameof(displayName));
}
/// <summary>
/// Gets the function to call to get the value of the property
/// </summary>
@@ -37,10 +37,27 @@ namespace Artemis.Core
/// <inheritdoc />
public void SetValue(object? value)
{
if (value is TProperty match)
Setter(match);
else
throw new ArgumentException("Value must match the type of the data binding registration", nameof(value));
// Numeric has a bunch of conversion, this seems the cheapest way to use them :)
switch (value)
{
case TProperty match:
Setter(match);
break;
case Numeric numeric when Setter is Action<float> floatSetter:
floatSetter(numeric);
break;
case Numeric numeric when Setter is Action<int> intSetter:
intSetter(numeric);
break;
case Numeric numeric when Setter is Action<double> doubleSetter:
doubleSetter(numeric);
break;
case Numeric numeric when Setter is Action<byte> byteSetter:
byteSetter(numeric);
break;
default:
throw new ArgumentException("Value must match the type of the data binding registration", nameof(value));
}
}
}
}
@@ -15,6 +15,11 @@ namespace Artemis.Core
/// </summary>
ILayerProperty BaseLayerProperty { get; }
/// <summary>
/// Gets the script used to populate the data binding
/// </summary>
INodeScript Script { get; }
/// <summary>
/// Gets a list of sub-properties this data binding applies to
/// </summary>
@@ -363,7 +363,7 @@ namespace Artemis.Core
private bool _displayConditionMet;
/// <summary>
/// Gets the display condition used to determine whether this element is active or not
/// Gets or sets the display condition used to determine whether this element is active or not
/// </summary>
public ICondition? DisplayCondition
{
@@ -28,11 +28,11 @@ namespace Artemis.Core.Internal
{
if (inputPin.ConnectedTo.Any())
_propertyValues[property] = inputPin.Value!;
else
else
_propertyValues.Remove(property);
}
}
public void ApplyToDataBinding()
{
foreach (var (property, pendingValue) in _propertyValues)
@@ -53,9 +53,14 @@ namespace Artemis.Core.Internal
ClearInputPins();
foreach (IDataBindingProperty property in DataBinding.Properties)
_propertyPins.Add(property, CreateInputPin(property.ValueType, property.DisplayName));
{
_propertyPins.Add(property, Numeric.IsTypeCompatible(property.ValueType)
? CreateInputPin(typeof(Numeric), property.DisplayName)
: CreateInputPin(property.ValueType, property.DisplayName)
);
}
}
#region Event handlers
private void DataBindingOnDataBindingPropertyRegistered(object? sender, DataBindingEventArgs e)
@@ -67,7 +72,7 @@ namespace Artemis.Core.Internal
{
ClearInputPins();
}
#endregion
}
}