From e3d688141c21daaa3d8b8f04bb7140edf83b956c Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Mon, 11 Sep 2023 22:20:05 -0700
Subject: [PATCH] Add ConditionPluginScoped (#1385)
---
.../Game/ClientState/Conditions/Condition.cs | 57 +++++++++++++++++--
1 file changed, 51 insertions(+), 6 deletions(-)
diff --git a/Dalamud/Game/ClientState/Conditions/Condition.cs b/Dalamud/Game/ClientState/Conditions/Condition.cs
index b72c91c74..585b762bf 100644
--- a/Dalamud/Game/ClientState/Conditions/Condition.cs
+++ b/Dalamud/Game/ClientState/Conditions/Condition.cs
@@ -10,13 +10,9 @@ namespace Dalamud.Game.ClientState.Conditions;
///
/// Provides access to conditions (generally player state). You can check whether a player is in combat, mounted, etc.
///
-[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService]
-#pragma warning disable SA1015
-[ResolveVia]
-#pragma warning restore SA1015
-public sealed partial class Condition : IServiceType, ICondition
+internal sealed partial class Condition : IServiceType, ICondition
{
///
/// Gets the current max number of conditions. You can get this just by looking at the condition sheet and how many rows it has.
@@ -122,7 +118,7 @@ public sealed partial class Condition : IServiceType, ICondition
///
/// Provides access to conditions (generally player state). You can check whether a player is in combat, mounted, etc.
///
-public sealed partial class Condition : IDisposable
+internal sealed partial class Condition : IDisposable
{
private bool isDisposed;
@@ -156,3 +152,52 @@ public sealed partial class Condition : IDisposable
this.isDisposed = true;
}
}
+
+///
+/// Plugin-scoped version of a Condition service.
+///
+[PluginInterface]
+[InterfaceVersion("1.0")]
+[ServiceManager.ScopedService]
+#pragma warning disable SA1015
+[ResolveVia]
+#pragma warning restore SA1015
+internal class ConditionPluginScoped : IDisposable, IServiceType, ICondition
+{
+ [ServiceManager.ServiceDependency]
+ private readonly Condition conditionService = Service.Get();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ internal ConditionPluginScoped()
+ {
+ this.conditionService.ConditionChange += this.ConditionChangedForward;
+ }
+
+ ///
+ public event ICondition.ConditionChangeDelegate? ConditionChange;
+
+ ///
+ public int MaxEntries => this.conditionService.MaxEntries;
+
+ ///
+ public IntPtr Address => this.conditionService.Address;
+
+ ///
+ public bool this[int flag] => this.conditionService[flag];
+
+ ///
+ public void Dispose()
+ {
+ this.conditionService.ConditionChange -= this.ConditionChangedForward;
+ }
+
+ ///
+ public bool Any() => this.conditionService.Any();
+
+ ///
+ public bool Any(params ConditionFlag[] flags) => this.conditionService.Any(flags);
+
+ private void ConditionChangedForward(ConditionFlag flag, bool value) => this.ConditionChange?.Invoke(flag, value);
+}