mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 13:14:17 +01:00
use kaz's api for conditions instead
This commit is contained in:
parent
31ba979a83
commit
c4e31bc5f1
3 changed files with 51 additions and 12 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
|
|
@ -101,17 +102,33 @@ internal sealed class Condition : IInternalDisposableService, ICondition
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Only(params ConditionFlag[] flags)
|
public bool OnlyAny(params ConditionFlag[] other)
|
||||||
{
|
{
|
||||||
|
var resultSet = this.AsReadOnlySet();
|
||||||
|
return !resultSet.Except(other).Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool OnlyAll(params ConditionFlag[] other)
|
||||||
|
{
|
||||||
|
var resultSet = this.AsReadOnlySet();
|
||||||
|
return resultSet.SetEquals(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IReadOnlySet<ConditionFlag> AsReadOnlySet()
|
||||||
|
{
|
||||||
|
var result = new HashSet<ConditionFlag>();
|
||||||
|
|
||||||
for (var i = 0; i < MaxConditionEntries; i++)
|
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)
|
private void Dispose(bool disposing)
|
||||||
|
|
@ -191,6 +208,9 @@ internal class ConditionPluginScoped : IInternalDisposableService, ICondition
|
||||||
|
|
||||||
this.ConditionChange = null;
|
this.ConditionChange = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IReadOnlySet<ConditionFlag> AsReadOnlySet() => this.conditionService.AsReadOnlySet();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Any() => this.conditionService.Any();
|
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 Any(params ConditionFlag[] flags) => this.conditionService.Any(flags);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Only(params ConditionFlag[] flags) => this.conditionService.Only(flags);
|
public bool OnlyAny(params ConditionFlag[] other) => this.conditionService.OnlyAny(other);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool OnlyAll(params ConditionFlag[] other) => this.conditionService.OnlyAll(other);
|
||||||
|
|
||||||
private void ConditionChangedForward(ConditionFlag flag, bool value) => this.ConditionChange?.Invoke(flag, value);
|
private void ConditionChangedForward(ConditionFlag flag, bool value) => this.ConditionChange?.Invoke(flag, value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ internal class AutoUpdateManager : IServiceType
|
||||||
var condition = Service<Condition>.Get();
|
var condition = Service<Condition>.Get();
|
||||||
return this.IsPluginManagerReady() &&
|
return this.IsPluginManagerReady() &&
|
||||||
!this.dalamudInterface.IsPluginInstallerOpen &&
|
!this.dalamudInterface.IsPluginInstallerOpen &&
|
||||||
condition.Only(ConditionFlag.NormalConditions,
|
condition.OnlyAny(ConditionFlag.NormalConditions,
|
||||||
ConditionFlag.Jumping,
|
ConditionFlag.Jumping,
|
||||||
ConditionFlag.Mounted,
|
ConditionFlag.Mounted,
|
||||||
ConditionFlag.UsingParasol);
|
ConditionFlag.UsingParasol);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using Dalamud.Game.ClientState.Conditions;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Dalamud.Game.ClientState.Conditions;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Services;
|
namespace Dalamud.Plugin.Services;
|
||||||
|
|
||||||
|
|
@ -53,10 +55,24 @@ public interface ICondition
|
||||||
public bool Any(params ConditionFlag[] flags);
|
public bool Any(params ConditionFlag[] flags);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if none but the provided condition flags are set.
|
/// Check that *only* any of the condition flags specified are set. Useful to test if the client is in one of any
|
||||||
/// This is not an exclusive check, it will return true if the provided flags are the only ones set.
|
/// of a few specific condiiton states.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="flags">The condition flags to check for.</param>
|
/// <param name="other">The array of flags to check.</param>
|
||||||
/// <returns>Whether only flags passed in are set.</returns>
|
/// <returns>Returns a bool.</returns>
|
||||||
public bool Only(params ConditionFlag[] flags);
|
public bool OnlyAny(params ConditionFlag[] other);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check that *only* the specified flags are set. Unlike <see cref="OnlyAny"/>, this method requires that all the
|
||||||
|
/// specified flags are set and no others are present.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">The array of flags to check.</param>
|
||||||
|
/// <returns>Returns a bool.</returns>
|
||||||
|
public bool OnlyAll(params ConditionFlag[] other);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert the conditions array to a set of all set condition flags.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Returns a set.</returns>
|
||||||
|
public IReadOnlySet<ConditionFlag> AsReadOnlySet();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue