-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #815 from Artemis-RGB/development
Adaption hints - Added more hints and sections
- Loading branch information
Showing
21 changed files
with
433 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/Artemis.Core/Models/Profile/AdaptionHints/SingeLedAdaptionHint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Artemis.Storage.Entities.Profile.AdaptionHints; | ||
using RGB.NET.Core; | ||
|
||
namespace Artemis.Core; | ||
|
||
/// <summary> | ||
/// Represents a hint that adapts layers to a single LED of one or more devices | ||
/// </summary> | ||
public class SingleLedAdaptionHint : CorePropertyChanged, IAdaptionHint | ||
{ | ||
private LedId _ledId; | ||
private int _skip; | ||
private bool _limitAmount; | ||
private int _amount; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="SingleLedAdaptionHint" /> class | ||
/// </summary> | ||
public SingleLedAdaptionHint() | ||
{ | ||
} | ||
|
||
internal SingleLedAdaptionHint(SingleLedAdaptionHintEntity entity) | ||
{ | ||
LedId = (LedId) entity.LedId; | ||
Skip = entity.Skip; | ||
LimitAmount = entity.LimitAmount; | ||
Amount = entity.Amount; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the LED ID to apply to. | ||
/// </summary> | ||
public LedId LedId | ||
{ | ||
get => _ledId; | ||
set => SetAndNotify(ref _ledId, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the amount of devices to skip | ||
/// </summary> | ||
public int Skip | ||
{ | ||
get => _skip; | ||
set => SetAndNotify(ref _skip, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a boolean indicating whether a limited amount of devices should be used | ||
/// </summary> | ||
public bool LimitAmount | ||
{ | ||
get => _limitAmount; | ||
set => SetAndNotify(ref _limitAmount, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the amount of devices to limit to if <see cref="LimitAmount" /> is <see langword="true" /> | ||
/// </summary> | ||
public int Amount | ||
{ | ||
get => _amount; | ||
set => SetAndNotify(ref _amount, value); | ||
} | ||
|
||
#region Implementation of IAdaptionHint | ||
|
||
/// <inheritdoc /> | ||
public void Apply(Layer layer, List<ArtemisDevice> devices) | ||
{ | ||
IEnumerable<ArtemisDevice> matches = devices | ||
.Where(d => d.Leds.Any(l => l.RgbLed.Id == LedId)) | ||
.OrderBy(d => d.Rectangle.Top) | ||
.ThenBy(d => d.Rectangle.Left) | ||
.Skip(Skip); | ||
if (LimitAmount) | ||
matches = matches.Take(Amount); | ||
|
||
foreach (ArtemisDevice artemisDevice in matches) | ||
{ | ||
ArtemisLed led = artemisDevice.Leds.First(l => l.RgbLed.Id == LedId); | ||
layer.AddLed(led); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IAdaptionHintEntity GetEntry() | ||
{ | ||
return new SingleLedAdaptionHintEntity {Amount = Amount, LimitAmount = LimitAmount, Skip = Skip, LedId = (int) LedId}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"Single LED adaption - {nameof(LedId)}: {LedId}, {nameof(Skip)}: {Skip}, {nameof(LimitAmount)}: {LimitAmount}, {nameof(Amount)}: {Amount}"; | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Artemis.Storage/Entities/Profile/AdaptionHints/SingleLedAdaptionHintEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Artemis.Storage.Entities.Profile.AdaptionHints; | ||
|
||
public class SingleLedAdaptionHintEntity : IAdaptionHintEntity | ||
{ | ||
public int LedId { get; set; } | ||
|
||
public bool LimitAmount { get; set; } | ||
public int Skip { get; set; } | ||
public int Amount { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Artemis.UI.Shared/Services/ProfileEditor/Commands/ApplyAdaptionHints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Generic; | ||
using Artemis.Core; | ||
|
||
namespace Artemis.UI.Shared.Services.ProfileEditor.Commands; | ||
|
||
/// <summary> | ||
/// Represents a profile editor command that can be used to apply adaption hints to a layer. | ||
/// </summary> | ||
public class ApplyAdaptionHints : IProfileEditorCommand | ||
{ | ||
private readonly Layer _layer; | ||
private readonly List<ArtemisDevice> _devices; | ||
private readonly List<ArtemisLed> _originalLeds; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="ApplyAdaptionHints" /> class. | ||
/// </summary> | ||
public ApplyAdaptionHints(Layer layer, List<ArtemisDevice> devices) | ||
{ | ||
_layer = layer; | ||
_devices = devices; | ||
_originalLeds = new List<ArtemisLed>(_layer.Leds); | ||
} | ||
|
||
#region Implementation of IProfileEditorCommand | ||
|
||
/// <inheritdoc /> | ||
public string DisplayName => "Apply adaption hints"; | ||
|
||
/// <inheritdoc /> | ||
public void Execute() | ||
{ | ||
_layer.ClearLeds(); | ||
_layer.Adapter.Adapt(_devices); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Undo() | ||
{ | ||
_layer.ClearLeds(); | ||
_layer.AddLeds(_originalLeds); | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.