From 49b16463bb1f9507079aed50e017880234affc5c Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 28 Sep 2023 02:56:38 -0400 Subject: [PATCH] refactor: update for api 9 --- Peeping Tom.Ipc/Peeping Tom.Ipc.csproj | 2 +- Peeping Tom.Ipc/Targeter.cs | 4 +-- Peeping Tom/IpcManager.cs | 4 +-- Peeping Tom/Plugin.cs | 46 ++++++++++++-------------- Peeping Tom/PluginUi.cs | 12 +++---- Peeping Tom/TargetWatcher.cs | 19 +++++------ 6 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj b/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj index 7bf61d0..4642b71 100755 --- a/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj +++ b/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj @@ -2,7 +2,7 @@ net7.0-windows - 1.0.1 + 1.0.2 enable PeepingTom.Ipc diff --git a/Peeping Tom.Ipc/Targeter.cs b/Peeping Tom.Ipc/Targeter.cs index 3f30eed..ff93b8f 100755 --- a/Peeping Tom.Ipc/Targeter.cs +++ b/Peeping Tom.Ipc/Targeter.cs @@ -1,8 +1,8 @@ using System; using System.Linq; -using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Plugin.Services; using Newtonsoft.Json; namespace PeepingTom.Ipc { @@ -29,7 +29,7 @@ namespace PeepingTom.Ipc { this.When = when; } - public PlayerCharacter? GetPlayerCharacter(ObjectTable objectTable) { + public PlayerCharacter? GetPlayerCharacter(IObjectTable objectTable) { return objectTable.FirstOrDefault(actor => actor.ObjectId == this.ObjectId && actor is PlayerCharacter) as PlayerCharacter; } } diff --git a/Peeping Tom/IpcManager.cs b/Peeping Tom/IpcManager.cs index d6b0757..2137539 100755 --- a/Peeping Tom/IpcManager.cs +++ b/Peeping Tom/IpcManager.cs @@ -8,12 +8,12 @@ using PeepingTom.Ipc.To; namespace PeepingTom { internal class IpcManager : IDisposable { - private PeepingTomPlugin Plugin { get; } + private Plugin Plugin { get; } private ICallGateProvider Provider { get; } private ICallGateSubscriber Subscriber { get; } - internal IpcManager(PeepingTomPlugin plugin) { + internal IpcManager(Plugin plugin) { this.Plugin = plugin; this.Provider = this.Plugin.Interface.GetIpcProvider(IpcInfo.FromRegistrationName); diff --git a/Peeping Tom/Plugin.cs b/Peeping Tom/Plugin.cs index cc23b08..6f01899 100644 --- a/Peeping Tom/Plugin.cs +++ b/Peeping Tom/Plugin.cs @@ -1,58 +1,54 @@ using Dalamud.Game.Command; using Dalamud.Plugin; -using System; using System.Collections.Generic; using System.Globalization; -using Dalamud.Data; -using Dalamud.Game; -using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Objects; -using Dalamud.Game.Gui; -using Dalamud.Game.Gui.Toast; using Dalamud.IoC; -using Dalamud.Logging; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; using PeepingTom.Resources; using XivCommon; -using Condition = Dalamud.Game.ClientState.Conditions.Condition; namespace PeepingTom { // ReSharper disable once ClassNeverInstantiated.Global - public class PeepingTomPlugin : IDalamudPlugin { - public string Name => "Peeping Tom"; + public class Plugin : IDalamudPlugin { + internal static string Name => "Peeping Tom"; + + [PluginService] + internal static IPluginLog Log { get; private set; } = null!; [PluginService] internal DalamudPluginInterface Interface { get; init; } = null!; [PluginService] - internal ChatGui ChatGui { get; init; } = null!; + internal IChatGui ChatGui { get; init; } = null!; [PluginService] - internal ClientState ClientState { get; init; } = null!; + internal IClientState ClientState { get; init; } = null!; [PluginService] - private CommandManager CommandManager { get; init; } = null!; + private ICommandManager CommandManager { get; init; } = null!; [PluginService] - internal Condition Condition { get; init; } = null!; + internal ICondition Condition { get; init; } = null!; [PluginService] - internal DataManager DataManager { get; init; } = null!; + internal IDataManager DataManager { get; init; } = null!; [PluginService] - internal Framework Framework { get; init; } = null!; + internal IFramework Framework { get; init; } = null!; [PluginService] - internal GameGui GameGui { get; init; } = null!; + internal IGameGui GameGui { get; init; } = null!; [PluginService] - internal ObjectTable ObjectTable { get; init; } = null!; + internal IObjectTable ObjectTable { get; init; } = null!; [PluginService] - internal TargetManager TargetManager { get; init; } = null!; + internal ITargetManager TargetManager { get; init; } = null!; [PluginService] - internal ToastGui ToastGui { get; init; } = null!; + internal IToastGui ToastGui { get; init; } = null!; internal Configuration Config { get; } internal PluginUi Ui { get; } @@ -62,7 +58,7 @@ namespace PeepingTom { internal bool InPvp { get; private set; } - public PeepingTomPlugin() { + public Plugin() { this.Common = new XivCommonBase(); this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration(); this.Config.Initialize(this.Interface); @@ -110,12 +106,12 @@ namespace PeepingTom { Language.Culture = new CultureInfo(langCode); } - private void OnTerritoryChange(object? sender, ushort e) { + private void OnTerritoryChange(ushort e) { try { var territory = this.DataManager.GetExcelSheet()!.GetRow(e); this.InPvp = territory?.IsPvpZone == true; } catch (KeyNotFoundException) { - PluginLog.Warning("Could not get territory for current zone"); + Log.Warning("Could not get territory for current zone"); } } @@ -127,7 +123,7 @@ namespace PeepingTom { } } - private void OnLogin(object? sender, EventArgs args) { + private void OnLogin() { if (!this.Config.OpenOnLogin) { return; } @@ -135,7 +131,7 @@ namespace PeepingTom { this.Ui.WantsOpen = true; } - private void OnLogout(object? sender, EventArgs args) { + private void OnLogout() { this.Ui.WantsOpen = false; this.Watcher.ClearPrevious(); } diff --git a/Peeping Tom/PluginUi.cs b/Peeping Tom/PluginUi.cs index 89e2a80..95ce9fd 100644 --- a/Peeping Tom/PluginUi.cs +++ b/Peeping Tom/PluginUi.cs @@ -11,13 +11,13 @@ using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; -using Dalamud.Interface; +using Dalamud.Interface.Utility; using PeepingTom.Ipc; using PeepingTom.Resources; namespace PeepingTom { internal class PluginUi : IDisposable { - private PeepingTomPlugin Plugin { get; } + private Plugin Plugin { get; } private uint? PreviousFocus { get; set; } = new(); @@ -37,7 +37,7 @@ namespace PeepingTom { set => this._settingsOpen = value; } - public PluginUi(PeepingTomPlugin plugin) { + public PluginUi(Plugin plugin) { this.Plugin = plugin; } @@ -124,7 +124,7 @@ namespace PeepingTom { private void ShowSettings() { ImGui.SetNextWindowSize(new Vector2(700, 250)); - var windowTitle = string.Format(Language.SettingsTitle, this.Plugin.Name); + var windowTitle = string.Format(Language.SettingsTitle, Plugin.Name); if (!ImGui.Begin($"{windowTitle}###ptom-settings", ref this._settingsOpen, ImGuiWindowFlags.NoResize)) { ImGui.End(); return; @@ -392,7 +392,7 @@ namespace PeepingTom { } ImGui.SetNextWindowSize(new Vector2(290, 195), ImGuiCond.FirstUseEver); - if (!ImGui.Begin(this.Plugin.Name, ref this._wantsOpen, flags)) { + if (!ImGui.Begin(Plugin.Name, ref this._wantsOpen, flags)) { ImGui.End(); return; } @@ -522,7 +522,7 @@ namespace PeepingTom { } else { var payload = new PlayerPayload(targeter.Name.TextValue, targeter.HomeWorldId); Payload[] payloads = { payload }; - this.Plugin.ChatGui.PrintChat(new XivChatEntry { + this.Plugin.ChatGui.Print(new XivChatEntry { Message = new SeString(payloads), }); } diff --git a/Peeping Tom/TargetWatcher.cs b/Peeping Tom/TargetWatcher.cs index 83e6022..259dc4c 100644 --- a/Peeping Tom/TargetWatcher.cs +++ b/Peeping Tom/TargetWatcher.cs @@ -6,17 +6,16 @@ using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Threading; -using Dalamud.Game; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text; -using Dalamud.Logging; +using Dalamud.Plugin.Services; using PeepingTom.Ipc; using PeepingTom.Resources; namespace PeepingTom { internal class TargetWatcher : IDisposable { - private PeepingTomPlugin Plugin { get; } + private Plugin Plugin { get; } private Stopwatch UpdateWatch { get; } = new(); private Stopwatch? SoundWatch { get; set; } @@ -30,7 +29,7 @@ namespace PeepingTom { public IReadOnlyCollection PreviousTargeters => this.Previous; - public TargetWatcher(PeepingTomPlugin plugin) { + public TargetWatcher(Plugin plugin) { this.Plugin = plugin; this.UpdateWatch.Start(); @@ -45,7 +44,7 @@ namespace PeepingTom { this.Previous.Clear(); } - private void OnFrameworkUpdate(Framework framework) { + private void OnFrameworkUpdate(IFramework framework1) { if (this.Plugin.InPvp) { return; } @@ -68,7 +67,7 @@ namespace PeepingTom { try { this.Plugin.IpcManager.SendNewTargeter(newTargeter); } catch (Exception ex) { - PluginLog.LogError(ex, "Failed to send IPC message"); + Plugin.Log.Error(ex, "Failed to send IPC message"); } } @@ -76,7 +75,7 @@ namespace PeepingTom { try { this.Plugin.IpcManager.SendStoppedTargeting(stopped); } catch (Exception ex) { - PluginLog.LogError(ex, "Failed to send IPC message"); + Plugin.Log.Error(ex, "Failed to send IPC message"); } } @@ -195,15 +194,15 @@ namespace PeepingTom { Thread.Sleep(500); } } catch (Exception ex) { - PluginLog.LogError(ex, "Exception playing sound"); + Plugin.Log.Error(ex, "Exception playing sound"); } } }).Start(); } private void SendError(string message) { - this.Plugin.ChatGui.PrintChat(new XivChatEntry { - Message = $"[{this.Plugin.Name}] {message}", + this.Plugin.ChatGui.Print(new XivChatEntry { + Message = $"[{Plugin.Name}] {message}", Type = XivChatType.ErrorMessage, }); }