Profiles - Added system that displays when a layer is causing errors

This commit is contained in:
Robert committed 2021-07-11 19:32:27 +02:00
1 parent 3b7e226885
commit 5b6fc9eec7
18 files changed
+457 -95

No files matched your search

+14 -11
View File
@@ -183,18 +183,15 @@ namespace Artemis.Core
lock (Timeline)
{
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
{
baseLayerEffect.BaseProperties?.Update(Timeline);
baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
}
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.InternalUpdate(Timeline);
SKPaint layerPaint = new() {FilterQuality = SKFilterQuality.Low};
try
{
SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.PreProcess(canvas, rendererBounds, layerPaint);
baseLayerEffect.InternalPreProcess(canvas, rendererBounds, layerPaint);
// No point rendering if the alpha was set to zero by one of the effects
if (layerPaint.Color.Alpha == 0)
@@ -208,7 +205,7 @@ namespace Artemis.Core
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.PostProcess(canvas, rendererBounds, layerPaint);
baseLayerEffect.InternalPostProcess(canvas, rendererBounds, layerPaint);
}
finally
{
@@ -228,8 +225,6 @@ namespace Artemis.Core
if (Enabled)
return;
Debug.WriteLine($"Enabling {this}");
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalEnable();
@@ -248,8 +243,6 @@ namespace Artemis.Core
if (!Enabled)
return;
Debug.WriteLine($"Disabled {this}");
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalDisable();
@@ -344,5 +337,15 @@ namespace Artemis.Core
{
RenderPropertiesUpdated?.Invoke(this, EventArgs.Empty);
}
#region Overrides of BreakableModel
/// <inheritdoc />
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
{
return LayerEffects.Where(e => e.BrokenState != null);
}
#endregion
}
}
+48 -25
View File
@@ -206,6 +206,7 @@ namespace Artemis.Core
GetType().GetProperty(nameof(Transform))!,
typeof(PropertyGroupDescriptionAttribute)
)!;
General.GroupDescription = (PropertyGroupDescriptionAttribute) generalAttribute;
General.Initialize(this, "General.", Constants.CorePluginFeature);
Transform.GroupDescription = (PropertyGroupDescriptionAttribute) transformAttribute;
@@ -288,7 +289,7 @@ namespace Artemis.Core
// Adaption hints
Adapter.Save();
SaveRenderElement();
}
@@ -320,7 +321,7 @@ namespace Artemis.Core
{
if (Disposed)
throw new ObjectDisposedException("Layer");
UpdateDisplayCondition();
UpdateTimeline(deltaTime);
@@ -366,9 +367,17 @@ namespace Artemis.Core
if (Enabled)
return;
LayerBrush?.InternalEnable();
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalEnable();
bool tryOrBreak = TryOrBreak(() => LayerBrush?.InternalEnable(), "Failed to enable layer brush");
if (!tryOrBreak)
return;
tryOrBreak = TryOrBreak(() =>
{
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalEnable();
}, "Failed to enable one or more effects");
if (!tryOrBreak)
return;
Enabled = true;
}
@@ -393,17 +402,10 @@ namespace Artemis.Core
General.Update(timeline);
Transform.Update(timeline);
if (LayerBrush != null)
{
LayerBrush.BaseProperties?.Update(timeline);
LayerBrush.Update(timeline.Delta.TotalSeconds);
}
LayerBrush?.InternalUpdate(timeline);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
{
baseLayerEffect.BaseProperties?.Update(timeline);
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
}
baseLayerEffect.InternalUpdate(timeline);
}
private void RenderTimeline(Timeline timeline, SKCanvas canvas, SKPointI basePosition)
@@ -477,9 +479,9 @@ namespace Artemis.Core
{
if (LayerBrush == null)
throw new ArtemisCoreException("The layer is not yet ready for rendering");
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.PreProcess(canvas, bounds, layerPaint);
baseLayerEffect.InternalPreProcess(canvas, bounds, layerPaint);
try
{
@@ -492,7 +494,7 @@ namespace Artemis.Core
LayerBrush.InternalRender(canvas, bounds, layerPaint);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.PostProcess(canvas, bounds, layerPaint);
baseLayerEffect.InternalPostProcess(canvas, bounds, layerPaint);
}
finally
@@ -722,16 +724,24 @@ namespace Artemis.Core
internal void ActivateLayerBrush()
{
LayerBrushReference? current = General.BrushReference.CurrentValue;
if (current == null)
return;
try
{
LayerBrushReference? current = General.BrushReference.CurrentValue;
if (current == null)
return;
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
: null;
descriptor?.CreateInstance(this);
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
: null;
descriptor?.CreateInstance(this);
OnLayerBrushUpdated();
OnLayerBrushUpdated();
ClearBrokenState("Failed to initialize layer brush");
}
catch (Exception e)
{
SetBrokenState("Failed to initialize layer brush", e);
}
}
internal void DeactivateLayerBrush()
@@ -747,6 +757,19 @@ namespace Artemis.Core
}
#endregion
#region Overrides of BreakableModel
/// <inheritdoc />
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
{
if (LayerBrush?.BrokenState != null)
yield return LayerBrush;
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.BrokenState != null))
yield return baseLayerEffect;
}
#endregion
}
/// <summary>
@@ -27,6 +27,7 @@ namespace Artemis.Core
UndoStack = new MaxStack<string>(20);
RedoStack = new MaxStack<string>(20);
Exceptions = new List<Exception>();
Load();
}
@@ -77,6 +78,7 @@ namespace Artemis.Core
internal MaxStack<string> UndoStack { get; set; }
internal MaxStack<string> RedoStack { get; set; }
internal List<Exception> Exceptions { get; }
/// <inheritdoc />
public override void Update(double deltaTime)
@@ -113,6 +115,13 @@ namespace Artemis.Core
foreach (ProfileScript profileScript in Scripts)
profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds);
if (!Exceptions.Any())
return;
List<Exception> exceptions = new(Exceptions);
Exceptions.Clear();
throw new AggregateException($"One or more exceptions while rendering profile {Name}", exceptions);
}
}
@@ -238,5 +247,18 @@ namespace Artemis.Core
ProfileEntity.ScriptConfigurations.Add(scriptConfiguration.Entity);
}
}
#region Overrides of BreakableModel
/// <inheritdoc />
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
{
foreach (IBreakableModel breakableModel in GetAllFolders().SelectMany(folders => folders.GetBrokenHierarchy()))
yield return breakableModel;
foreach (IBreakableModel breakableModel in GetAllLayers().SelectMany(layer => layer.GetBrokenHierarchy()))
yield return breakableModel;
}
#endregion
}
}
@@ -9,7 +9,7 @@ namespace Artemis.Core
/// <summary>
/// Represents an element of a <see cref="Profile" />
/// </summary>
public abstract class ProfileElement : CorePropertyChanged, IDisposable
public abstract class ProfileElement : BreakableModel, IDisposable
{
private Guid _entityId;
private string? _name;
@@ -25,7 +25,7 @@ namespace Artemis.Core
_profile = profile;
ChildrenList = new List<ProfileElement>();
}
/// <summary>
/// Gets the unique ID of this profile element
/// </summary>
@@ -121,6 +121,13 @@ namespace Artemis.Core
return $"{nameof(EntityId)}: {EntityId}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
}
#region Overrides of BreakableModel
/// <inheritdoc />
public override string BrokenDisplayName => Name ?? GetType().Name;
#endregion
#region Hierarchy
/// <summary>
@@ -234,7 +241,7 @@ namespace Artemis.Core
internal abstract void Save();
#endregion
#region IDisposable
/// <inheritdoc />