refactor: update for api 9

This commit is contained in:
Anna 2023-09-28 02:56:38 -04:00
parent 24564a6928
commit 49b16463bb
Signed by: anna
GPG Key ID: D0943384CD9F87D1
6 changed files with 41 additions and 46 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Nullable>enable</Nullable>
<RootNamespace>PeepingTom.Ipc</RootNamespace>
</PropertyGroup>

View File

@ -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;
}
}

View File

@ -8,12 +8,12 @@ using PeepingTom.Ipc.To;
namespace PeepingTom {
internal class IpcManager : IDisposable {
private PeepingTomPlugin Plugin { get; }
private Plugin Plugin { get; }
private ICallGateProvider<IFromMessage, object> Provider { get; }
private ICallGateSubscriber<IToMessage, object> Subscriber { get; }
internal IpcManager(PeepingTomPlugin plugin) {
internal IpcManager(Plugin plugin) {
this.Plugin = plugin;
this.Provider = this.Plugin.Interface.GetIpcProvider<IFromMessage, object>(IpcInfo.FromRegistrationName);

View File

@ -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<TerritoryType>()!.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();
}

View File

@ -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),
});
}

View File

@ -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<Targeter> 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,
});
}