1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Added methods/properties to check if specific effects are added to an effecttarget

This commit is contained in:
Darth Affe 2017-04-16 08:41:19 +02:00
parent 22412317f2
commit d23191c20a
2 changed files with 45 additions and 3 deletions

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using RGB.NET.Core.Exceptions; using RGB.NET.Core.Exceptions;
@ -24,7 +25,10 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets all <see cref="IEffect{T}" /> attached to this <see cref="IEffectTarget{T}"/>. /// Gets all <see cref="IEffect{T}" /> attached to this <see cref="IEffectTarget{T}"/>.
/// </summary> /// </summary>
protected IList<IEffect<T>> Effects => EffectTimes.Select(x => x.Effect).Cast<IEffect<T>>().ToList(); protected IList<IEffect<T>> InternalEffects => EffectTimes.Select(x => x.Effect).Cast<IEffect<T>>().ToList();
/// <inheritdoc />
public IEnumerable<IEffect<T>> Effects => new ReadOnlyCollection<IEffect<T>>(InternalEffects);
/// <summary> /// <summary>
/// Gets the strongly-typed target used for the <see cref="IEffect{T}"/>. /// Gets the strongly-typed target used for the <see cref="IEffect{T}"/>.
@ -40,7 +44,7 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
public virtual void UpdateEffects() public virtual void UpdateEffects()
{ {
lock (Effects) lock (InternalEffects)
{ {
for (int i = EffectTimes.Count - 1; i >= 0; i--) for (int i = EffectTimes.Count - 1; i >= 0; i--)
{ {
@ -96,6 +100,19 @@ namespace RGB.NET.Core
EffectTimes.Remove(effectTimeToRemove); EffectTimes.Remove(effectTimeToRemove);
} }
/// <inheritdoc />
public bool HasEffect(IEffect<T> effect)
{
return InternalEffects.Contains(effect);
}
/// <inheritdoc />
public bool HasEffect<TEffect>()
where TEffect : IEffect
{
return InternalEffects.Any(x => x.GetType() == typeof(TEffect));
}
#endregion #endregion
} }
} }

View File

@ -1,14 +1,25 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System.Collections.Generic;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {
/// <summary> /// <summary>
/// Represents a basic effect-target. /// Represents a basic effect-target.
/// </summary> /// </summary>
/// <typeparam name="T">The type this target represents.</typeparam> /// <typeparam name="T">The type this target represents.</typeparam>
public interface IEffectTarget<out T> public interface IEffectTarget<T>
where T : IEffectTarget<T> where T : IEffectTarget<T>
{ {
#region Properties & Fields
/// <summary>
/// Gets a readonly collection of all <see cref="IEffect{T}"/> of this <see cref="IEffectTarget{T}"/>.
/// </summary>
IEnumerable<IEffect<T>> Effects { get; }
#endregion
#region Methods #region Methods
/// <summary> /// <summary>
@ -28,6 +39,20 @@ namespace RGB.NET.Core
/// <param name="effect">The <see cref="IEffect{T}"/> to remove.</param> /// <param name="effect">The <see cref="IEffect{T}"/> to remove.</param>
void RemoveEffect(IEffect<T> effect); void RemoveEffect(IEffect<T> effect);
/// <summary>
/// Checks if the <see cref="IEffect{T}"/> is added to this <see cref="IEffectTarget{T}"/>.
/// </summary>
/// <param name="effect">The <see cref="IEffect{T}"/> to check.</param>
/// <returns><c>true</c> if the <see cref="IEffect{T}"/> is added to this <see cref="IEffectTarget{T}"/>.; otherwise, <c>false</c>.</returns>
bool HasEffect(IEffect<T> effect);
/// <summary>
/// Checks if any <see cref="IEffect{T}"/> of the provided generic type is added to this <see cref="IEffectTarget{T}"/>.
/// </summary>
/// <typeparam name="TEffect">The generic type of the <see cref="IEffect{T}"/> to check.</typeparam>
/// <returns><c>true</c> if any <see cref="IEffect{T}"/> of the provided type is added to this <see cref="IEffectTarget{T}"/>.; otherwise, <c>false</c>.</returns>
bool HasEffect<TEffect>() where TEffect : IEffect;
#endregion #endregion
} }
} }