diff --git a/Dalamud/Game/ClientState/Conditions/Condition.cs b/Dalamud/Game/ClientState/Conditions/Condition.cs index 23778288e..faafe05e0 100644 --- a/Dalamud/Game/ClientState/Conditions/Condition.cs +++ b/Dalamud/Game/ClientState/Conditions/Condition.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using Dalamud.IoC; @@ -101,17 +102,33 @@ internal sealed class Condition : IInternalDisposableService, ICondition } /// - public bool Only(params ConditionFlag[] flags) + public bool OnlyAny(params ConditionFlag[] other) { + var resultSet = this.AsReadOnlySet(); + return !resultSet.Except(other).Any(); + } + + /// + public bool OnlyAll(params ConditionFlag[] other) + { + var resultSet = this.AsReadOnlySet(); + return resultSet.SetEquals(other); + } + + /// + public IReadOnlySet AsReadOnlySet() + { + var result = new HashSet(); + for (var i = 0; i < MaxConditionEntries; i++) { - if (this[i] && flags.All(f => (int)f != i)) + if (this[i]) { - return false; + result.Add((ConditionFlag)i); } } - return true; + return result; } private void Dispose(bool disposing) @@ -191,6 +208,9 @@ internal class ConditionPluginScoped : IInternalDisposableService, ICondition this.ConditionChange = null; } + + /// + public IReadOnlySet AsReadOnlySet() => this.conditionService.AsReadOnlySet(); /// public bool Any() => this.conditionService.Any(); @@ -199,7 +219,10 @@ internal class ConditionPluginScoped : IInternalDisposableService, ICondition public bool Any(params ConditionFlag[] flags) => this.conditionService.Any(flags); /// - public bool Only(params ConditionFlag[] flags) => this.conditionService.Only(flags); + public bool OnlyAny(params ConditionFlag[] other) => this.conditionService.OnlyAny(other); + + /// + public bool OnlyAll(params ConditionFlag[] other) => this.conditionService.OnlyAll(other); private void ConditionChangedForward(ConditionFlag flag, bool value) => this.ConditionChange?.Invoke(flag, value); } diff --git a/Dalamud/Plugin/Internal/AutoUpdate/AutoUpdateManager.cs b/Dalamud/Plugin/Internal/AutoUpdate/AutoUpdateManager.cs index d6d1165c3..ce7b5af9d 100644 --- a/Dalamud/Plugin/Internal/AutoUpdate/AutoUpdateManager.cs +++ b/Dalamud/Plugin/Internal/AutoUpdate/AutoUpdateManager.cs @@ -407,7 +407,7 @@ internal class AutoUpdateManager : IServiceType var condition = Service.Get(); return this.IsPluginManagerReady() && !this.dalamudInterface.IsPluginInstallerOpen && - condition.Only(ConditionFlag.NormalConditions, + condition.OnlyAny(ConditionFlag.NormalConditions, ConditionFlag.Jumping, ConditionFlag.Mounted, ConditionFlag.UsingParasol); diff --git a/Dalamud/Plugin/Services/ICondition.cs b/Dalamud/Plugin/Services/ICondition.cs index 3b74c333c..7215cdac6 100644 --- a/Dalamud/Plugin/Services/ICondition.cs +++ b/Dalamud/Plugin/Services/ICondition.cs @@ -1,4 +1,6 @@ -using Dalamud.Game.ClientState.Conditions; +using System.Collections.Generic; + +using Dalamud.Game.ClientState.Conditions; namespace Dalamud.Plugin.Services; @@ -53,10 +55,24 @@ public interface ICondition public bool Any(params ConditionFlag[] flags); /// - /// 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. + /// Check that *only* any of the condition flags specified are set. Useful to test if the client is in one of any + /// of a few specific condiiton states. /// - /// The condition flags to check for. - /// Whether only flags passed in are set. - public bool Only(params ConditionFlag[] flags); + /// The array of flags to check. + /// Returns a bool. + public bool OnlyAny(params ConditionFlag[] other); + + /// + /// Check that *only* the specified flags are set. Unlike , this method requires that all the + /// specified flags are set and no others are present. + /// + /// The array of flags to check. + /// Returns a bool. + public bool OnlyAll(params ConditionFlag[] other); + + /// + /// Convert the conditions array to a set of all set condition flags. + /// + /// Returns a set. + public IReadOnlySet AsReadOnlySet(); }