add ICondition.Only() to check for a set of flags

This commit is contained in:
goat 2024-06-12 00:01:50 +02:00
parent a12edcbae0
commit bc0bea03e0
2 changed files with 27 additions and 0 deletions

View file

@ -1,3 +1,5 @@
using System.Linq;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
@ -98,6 +100,20 @@ internal sealed class Condition : IInternalDisposableService, ICondition
return false;
}
/// <inheritdoc/>
public bool Only(params ConditionFlag[] flags)
{
for (var i = 0; i < MaxConditionEntries; i++)
{
if (this[i] && flags.All(f => (int)f != i))
{
return false;
}
}
return true;
}
private void Dispose(bool disposing)
{
if (this.isDisposed)
@ -181,6 +197,9 @@ internal class ConditionPluginScoped : IInternalDisposableService, ICondition
/// <inheritdoc/>
public bool Any(params ConditionFlag[] flags) => this.conditionService.Any(flags);
/// <inheritdoc/>
public bool Only(params ConditionFlag[] flags) => this.conditionService.Only(flags);
private void ConditionChangedForward(ConditionFlag flag, bool value) => this.ConditionChange?.Invoke(flag, value);
}

View file

@ -51,4 +51,12 @@ public interface ICondition
/// <returns>Whether any single provided flag is set.</returns>
/// <param name="flags">The condition flags to check.</param>
public bool Any(params ConditionFlag[] flags);
/// <summary>
/// Check if none but the provided condition flags are set.
/// This is not an exclusive check, it will return true if the provided flags are the only ones set.
/// </summary>
/// <param name="flags">The condition flags to check for.</param>
/// <returns>Whether only flags passed in are set.</returns>
public bool Only(params ConditionFlag[] flags);
}