Răsfoiți Sursa

Move IPC consumer validation to abstract base

Lilith Song 2 ani în urmă
părinte
comite
84e1048f57
2 a modificat fișierele cu 34 adăugiri și 21 ștergeri
  1. 30 0
      HuntBuddy/Ipc/ConsumerBase.cs
  2. 4 21
      HuntBuddy/Ipc/TeleportConsumer.cs

+ 30 - 0
HuntBuddy/Ipc/ConsumerBase.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HuntBuddy.Ipc;
+public abstract class ConsumerBase {
+	public const int MS_PER_AVAILABILITY_RECHECK = 5000;
+	private bool isAvailable;
+	private long timeSinceLastCheck;
+
+	public bool IsAvailable {
+		get {
+			if (Environment.TickCount64 > this.timeSinceLastCheck + MS_PER_AVAILABILITY_RECHECK) {
+				try {
+					this.isAvailable = this.Validate();
+				}
+				catch {
+					this.isAvailable = false;
+				}
+				this.timeSinceLastCheck = Environment.TickCount64;
+			}
+
+			return this.isAvailable;
+		}
+	}
+
+	protected abstract bool Validate();
+}

+ 4 - 21
HuntBuddy/Ipc/TeleportConsumer.cs

@@ -4,27 +4,10 @@ using Dalamud.Plugin.Ipc;
 
 
 namespace HuntBuddy.Ipc;
 namespace HuntBuddy.Ipc;
 
 
-public class TeleportConsumer {
-	private bool isAvailable;
-	private long timeSinceLastCheck;
-
-	public bool IsAvailable {
-		get {
-			if (this.timeSinceLastCheck + 5000 > Environment.TickCount64) {
-				return this.isAvailable;
-			}
-
-			try {
-				this.consumerMessageSetting.InvokeFunc();
-				this.isAvailable = true;
-				this.timeSinceLastCheck = Environment.TickCount64;
-			}
-			catch {
-				this.isAvailable = false;
-			}
-
-			return this.isAvailable;
-		}
+public class TeleportConsumer: ConsumerBase {
+	protected override bool Validate() {
+		this.consumerMessageSetting.InvokeFunc();
+		return true;
 	}
 	}
 
 
 	private ICallGateSubscriber<bool> consumerMessageSetting = null!;
 	private ICallGateSubscriber<bool> consumerMessageSetting = null!;