From f269aeea27e3825eff715172cf88e1edb99d978e Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sun, 29 Aug 2021 13:20:19 -0400 Subject: [PATCH] refactor: move to net5 --- Macrology/Commands.cs | 14 +++---- Macrology/Configuration.cs | 17 +++++---- Macrology/DalamudPackager.targets | 5 +-- Macrology/ILRepack.targets | 19 ---------- Macrology/MacroHandler.cs | 14 +++---- Macrology/Macrology.cs | 63 ++++++++++++++++++++----------- Macrology/Macrology.csproj | 11 +++--- Macrology/Macrology.yaml | 1 + Macrology/PluginUI.cs | 24 +++++++----- 9 files changed, 86 insertions(+), 82 deletions(-) delete mode 100644 Macrology/ILRepack.targets diff --git a/Macrology/Commands.cs b/Macrology/Commands.cs index babcd3a..f304622 100644 --- a/Macrology/Commands.cs +++ b/Macrology/Commands.cs @@ -32,7 +32,7 @@ namespace Macrology { this.OnMacroCancelCommand(args); break; default: - this.Plugin.Interface.Framework.Gui.Chat.PrintError($"The command {command} was passed to Macrology, but there is no handler available."); + this.Plugin.ChatGui.PrintError($"The command {command} was passed to Macrology, but there is no handler available."); break; } } @@ -44,13 +44,13 @@ namespace Macrology { private void OnMacroCommand(string args) { var first = args.Trim().Split(' ').FirstOrDefault() ?? ""; if (!Guid.TryParse(first, out var id)) { - this.Plugin.Interface.Framework.Gui.Chat.PrintError("First argument must be the UUID of the macro to execute."); + this.Plugin.ChatGui.PrintError("First argument must be the UUID of the macro to execute."); return; } var macro = this.Plugin.Config.FindMacro(id); if (macro == null) { - this.Plugin.Interface.Framework.Gui.Chat.PrintError($"No macro with ID {id} found."); + this.Plugin.ChatGui.PrintError($"No macro with ID {id} found."); return; } @@ -68,19 +68,19 @@ namespace Macrology { } if (!Guid.TryParse(first, out var id)) { - this.Plugin.Interface.Framework.Gui.Chat.PrintError("First argument must either be \"all\" or the UUID of the macro to cancel."); + this.Plugin.ChatGui.PrintError("First argument must either be \"all\" or the UUID of the macro to cancel."); return; } var macro = this.Plugin.Config.FindMacro(id); if (macro == null) { - this.Plugin.Interface.Framework.Gui.Chat.PrintError($"No macro with ID {id} found."); + this.Plugin.ChatGui.PrintError($"No macro with ID {id} found."); return; } - var entry = this.Plugin.MacroHandler.Running.FirstOrDefault(e => e.Value.Id == id); + var entry = this.Plugin.MacroHandler.Running.FirstOrDefault(e => e.Value?.Id == id); if (entry.Value == null) { - this.Plugin.Interface.Framework.Gui.Chat.PrintError($"That macro is not running."); + this.Plugin.ChatGui.PrintError("That macro is not running."); return; } diff --git a/Macrology/Configuration.cs b/Macrology/Configuration.cs index d096183..218ad91 100644 --- a/Macrology/Configuration.cs +++ b/Macrology/Configuration.cs @@ -1,13 +1,14 @@ using Dalamud.Configuration; -using Dalamud.Plugin; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Dalamud.Logging; namespace Macrology { + [Serializable] public class Configuration : IPluginConfiguration { private Macrology Plugin { get; set; } = null!; @@ -136,7 +137,7 @@ namespace Macrology { return objectType == typeof(INode); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { throw new InvalidOperationException("Use default serialization."); } @@ -148,16 +149,16 @@ namespace Macrology { INode node; if (jsonObject.ContainsKey("Contents")) { node = new Macro( - jsonObject["Id"].ToObject(), - jsonObject["Name"].ToObject(), - jsonObject["Contents"].ToObject() + jsonObject["Id"]!.ToObject(), + jsonObject["Name"]!.ToObject()!, + jsonObject["Contents"]!.ToObject()! ); } else { node = new Folder( - jsonObject["Id"].ToObject(), - jsonObject["Name"].ToObject(), - (List) this.ReadJson(jsonObject["Children"].CreateReader(), typeof(List), null, serializer) + jsonObject["Id"]!.ToObject(), + jsonObject["Name"]!.ToObject()!, + (List) this.ReadJson(jsonObject["Children"]!.CreateReader(), typeof(List), null, serializer) ); } diff --git a/Macrology/DalamudPackager.targets b/Macrology/DalamudPackager.targets index f6104d5..d199ac1 100644 --- a/Macrology/DalamudPackager.targets +++ b/Macrology/DalamudPackager.targets @@ -1,13 +1,12 @@  - + + MakeZip="true"/> diff --git a/Macrology/ILRepack.targets b/Macrology/ILRepack.targets deleted file mode 100644 index 2522eff..0000000 --- a/Macrology/ILRepack.targets +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - diff --git a/Macrology/MacroHandler.cs b/Macrology/MacroHandler.cs index 8110118..c9b3c4d 100644 --- a/Macrology/MacroHandler.cs +++ b/Macrology/MacroHandler.cs @@ -1,11 +1,11 @@ -using Dalamud.Game.Internal; -using System; +using System; using System.Collections.Concurrent; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Channels; using System.Threading.Tasks; +using Dalamud.Game; namespace Macrology { public class MacroHandler { @@ -21,13 +21,13 @@ namespace Macrology { private Macrology Plugin { get; } private readonly Channel _commands = Channel.CreateUnbounded(); - public ConcurrentDictionary Running { get; } = new(); + public ConcurrentDictionary Running { get; } = new(); private readonly ConcurrentDictionary _cancelled = new(); private readonly ConcurrentDictionary _paused = new(); public MacroHandler(Macrology plugin) { this.Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Macrology cannot be null"); - this._ready = this.Plugin.Interface.ClientState.LocalPlayer != null; + this._ready = this.Plugin.ClientState.LocalPlayer != null; } private static string[] ExtractCommands(string macro) { @@ -138,7 +138,7 @@ namespace Macrology { return cancelled; } - public void OnFrameworkUpdate(Framework framework) { + public void OnFrameworkUpdate(Framework framework1) { // get a message to send, but discard it if we're not ready if (!this._commands.Reader.TryRead(out var command) || !this._ready) { return; @@ -165,11 +165,11 @@ namespace Macrology { return TimeSpan.FromSeconds(seconds); } - internal void OnLogin(object sender, EventArgs args) { + internal void OnLogin(object? sender, EventArgs args) { this._ready = true; } - internal void OnLogout(object sender, EventArgs args) { + internal void OnLogout(object? sender, EventArgs args) { this._ready = false; foreach (var id in this.Running.Keys) { diff --git a/Macrology/Macrology.cs b/Macrology/Macrology.cs index 0535537..810e216 100644 --- a/Macrology/Macrology.cs +++ b/Macrology/Macrology.cs @@ -1,6 +1,10 @@ using Dalamud.Game.Command; using Dalamud.Plugin; using System; +using Dalamud.Game; +using Dalamud.Game.ClientState; +using Dalamud.Game.Gui; +using Dalamud.IoC; using XivCommon; namespace Macrology { @@ -9,30 +13,43 @@ namespace Macrology { public string Name => "Macrology"; - public DalamudPluginInterface Interface { get; private set; } = null!; - public XivCommonBase Common { get; private set; } = null!; - public PluginUi Ui { get; private set; } = null!; - public MacroHandler MacroHandler { get; private set; } = null!; - public Configuration Config { get; private set; } = null!; - private Commands Commands { get; set; } = null!; + [PluginService] + internal DalamudPluginInterface Interface { get; private init; } = null!; - public void Initialize(DalamudPluginInterface pluginInterface) { - this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null"); - this.Common = new XivCommonBase(this.Interface); + [PluginService] + internal ChatGui ChatGui { get; private init; } = null!; + + [PluginService] + internal ClientState ClientState { get; private init; } = null!; + + [PluginService] + internal CommandManager CommandManager { get; private init; } = null!; + + [PluginService] + internal Framework Framework { get; private init; } = null!; + + public XivCommonBase Common { get; } + public PluginUi Ui { get; } + public MacroHandler MacroHandler { get; } + public Configuration Config { get; } + private Commands Commands { get; } + + public Macrology() { + this.Common = new XivCommonBase(); this.Ui = new PluginUi(this); this.MacroHandler = new MacroHandler(this); this.Config = Configuration.Load(this) ?? new Configuration(); this.Config.Initialise(this); this.Commands = new Commands(this); - this.Interface.UiBuilder.OnBuildUi += this.Ui.Draw; - this.Interface.UiBuilder.OnOpenConfigUi += this.Ui.OpenSettings; - this.Interface.Framework.OnUpdateEvent += this.MacroHandler.OnFrameworkUpdate; - this.Interface.ClientState.OnLogin += this.MacroHandler.OnLogin; - this.Interface.ClientState.OnLogout += this.MacroHandler.OnLogout; - foreach (var entry in Commands.Descriptions) { - this.Interface.CommandManager.AddHandler(entry.Key, new CommandInfo(this.Commands.OnCommand) { - HelpMessage = entry.Value, + this.Interface.UiBuilder.Draw += this.Ui.Draw; + this.Interface.UiBuilder.OpenConfigUi += this.Ui.OpenSettings; + this.Framework.Update += this.MacroHandler.OnFrameworkUpdate; + this.ClientState.Login += this.MacroHandler.OnLogin; + this.ClientState.Logout += this.MacroHandler.OnLogout; + foreach (var (name, desc) in Commands.Descriptions) { + this.CommandManager.AddHandler(name, new CommandInfo(this.Commands.OnCommand) { + HelpMessage = desc, }); } } @@ -43,13 +60,13 @@ namespace Macrology { } if (disposing) { - this.Interface.UiBuilder.OnBuildUi -= this.Ui.Draw; - this.Interface.UiBuilder.OnOpenConfigUi -= this.Ui.OpenSettings; - this.Interface.Framework.OnUpdateEvent -= this.MacroHandler.OnFrameworkUpdate; - this.Interface.ClientState.OnLogin -= this.MacroHandler.OnLogin; - this.Interface.ClientState.OnLogout -= this.MacroHandler.OnLogout; + this.Interface.UiBuilder.Draw -= this.Ui.Draw; + this.Interface.UiBuilder.OpenConfigUi -= this.Ui.OpenSettings; + this.Framework.Update -= this.MacroHandler.OnFrameworkUpdate; + this.ClientState.Login -= this.MacroHandler.OnLogin; + this.ClientState.Logout -= this.MacroHandler.OnLogout; foreach (var command in Commands.Descriptions.Keys) { - this.Interface.CommandManager.RemoveHandler(command); + this.CommandManager.RemoveHandler(command); } } diff --git a/Macrology/Macrology.csproj b/Macrology/Macrology.csproj index fe8d23f..115a584 100755 --- a/Macrology/Macrology.csproj +++ b/Macrology/Macrology.csproj @@ -4,8 +4,10 @@ latest enable 1.0.0 - net48 + net5-windows true + false + true @@ -26,9 +28,8 @@ - - - - + + + diff --git a/Macrology/Macrology.yaml b/Macrology/Macrology.yaml index 1fa47dd..80d79f1 100644 --- a/Macrology/Macrology.yaml +++ b/Macrology/Macrology.yaml @@ -1,5 +1,6 @@ author: ascclemens name: Macrology +punchline: Adds a better macro system to the game. description: |- Adds a better macro system to the game. diff --git a/Macrology/PluginUI.cs b/Macrology/PluginUI.cs index e3aab6a..9200552 100644 --- a/Macrology/PluginUI.cs +++ b/Macrology/PluginUI.cs @@ -23,7 +23,7 @@ namespace Macrology { this.Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Macrology cannot be null"); } - public void OpenSettings(object sender, EventArgs e) { + public void OpenSettings() { this.SettingsVisible = true; } @@ -83,21 +83,25 @@ namespace Macrology { ImGui.Text("Running macros"); ImGui.PushItemWidth(-1f); if (ImGui.BeginListBox("##running-macros")) { - foreach (var entry in this.Plugin.MacroHandler.Running) { - var name = $"{entry.Value.Name}"; - if (this._showIdents) { - var ident = entry.Key.ToString(); - name += $" ({ident.Substring(ident.Length - 7)})"; + foreach (var (id, value) in this.Plugin.MacroHandler.Running) { + if (value == null) { + continue; } - if (this.Plugin.MacroHandler.IsPaused(entry.Key)) { + var name = $"{value.Name}"; + if (this._showIdents) { + var ident = id.ToString(); + name += $" ({ident[^7..]})"; + } + + if (this.Plugin.MacroHandler.IsPaused(id)) { name += " (paused)"; } - var cancelled = this.Plugin.MacroHandler.IsCancelled(entry.Key); + var cancelled = this.Plugin.MacroHandler.IsCancelled(id); var flags = cancelled ? ImGuiSelectableFlags.Disabled : ImGuiSelectableFlags.None; - if (ImGui.Selectable($"{name}##{entry.Key}", this.RunningChoice == entry.Key, flags)) { - this.RunningChoice = entry.Key; + if (ImGui.Selectable($"{name}##{id}", this.RunningChoice == id, flags)) { + this.RunningChoice = id; } }