1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

Profiles - Avoid unnecessary OnBrokenStateChanged calls

Profiles - Fixed int range/float range deserialization
Profiles - Use Random.Shared where applicable
This commit is contained in:
RobertBeekman 2024-03-02 17:38:20 +01:00
parent 5c7497a859
commit 28640f9502
5 changed files with 14 additions and 5 deletions

View File

@ -61,6 +61,9 @@ public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
/// <inheritdoc />
public void SetBrokenState(string state, Exception? exception = null)
{
if (state == BrokenState && BrokenStateException?.StackTrace == exception?.StackTrace)
return;
BrokenState = state ?? throw new ArgumentNullException(nameof(state));
BrokenStateException = exception;
OnBrokenStateChanged();

View File

@ -160,10 +160,12 @@ public sealed class Layer : RenderProfileElement
public LayerAdapter Adapter { get; }
/// <inheritdoc />
public override bool ShouldBeEnabled => !Suspended && DisplayConditionMet;
public override bool ShouldBeEnabled => !Suspended && DisplayConditionMet && HasBounds;
internal override RenderElementEntity RenderElementEntity => LayerEntity;
private bool HasBounds => Bounds.Width > 0 && Bounds.Height > 0;
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
@ -383,7 +385,7 @@ public sealed class Layer : RenderProfileElement
if (ShouldBeEnabled)
Enable();
else if (Suspended || (Timeline.IsFinished && !_renderCopies.Any()))
else if (Suspended || !HasBounds || (Timeline.IsFinished && !_renderCopies.Any()))
Disable();
if (!Enabled || Timeline.Delta == TimeSpan.Zero)

View File

@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;
namespace Artemis.Core;
@ -14,12 +15,13 @@ public readonly struct FloatRange
/// </summary>
/// <param name="start">The start value of the range</param>
/// <param name="end">The end value of the range</param>
[JsonConstructor]
public FloatRange(float start, float end)
{
Start = start;
End = end;
_rand = new Random();
_rand = Random.Shared;
}
/// <summary>

View File

@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;
namespace Artemis.Core;
@ -14,12 +15,13 @@ public readonly struct IntRange
/// </summary>
/// <param name="start">The start value of the range</param>
/// <param name="end">The end value of the range</param>
[JsonConstructor]
public IntRange(int start, int end)
{
Start = start;
End = end;
_rand = new Random();
_rand = Random.Shared;
}
/// <summary>

View File

@ -162,7 +162,7 @@ public partial class ProfileConfigurationEditViewModel : DialogViewModelBase<Pro
// Preselect the icon or fall back to a random one
SelectedMaterialIcon = !IsNew && Enum.TryParse(_profileConfiguration.Icon.IconName, out MaterialIconKind enumValue)
? icons.FirstOrDefault(m => m.Icon == enumValue)
: icons.ElementAt(new Random().Next(0, icons.Count - 1));
: icons.ElementAt(Random.Shared.Next(0, icons.Count - 1));
}
private async Task SaveIcon()