refactor: move to net5

This commit is contained in:
Anna 2021-08-29 13:20:19 -04:00
parent c1f788f357
commit f269aeea27
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
9 changed files with 86 additions and 82 deletions

View File

@ -32,7 +32,7 @@ namespace Macrology {
this.OnMacroCancelCommand(args); this.OnMacroCancelCommand(args);
break; break;
default: 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; break;
} }
} }
@ -44,13 +44,13 @@ namespace Macrology {
private void OnMacroCommand(string args) { private void OnMacroCommand(string args) {
var first = args.Trim().Split(' ').FirstOrDefault() ?? ""; var first = args.Trim().Split(' ').FirstOrDefault() ?? "";
if (!Guid.TryParse(first, out var id)) { 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; return;
} }
var macro = this.Plugin.Config.FindMacro(id); var macro = this.Plugin.Config.FindMacro(id);
if (macro == null) { 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; return;
} }
@ -68,19 +68,19 @@ namespace Macrology {
} }
if (!Guid.TryParse(first, out var id)) { 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; return;
} }
var macro = this.Plugin.Config.FindMacro(id); var macro = this.Plugin.Config.FindMacro(id);
if (macro == null) { 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; 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) { 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; return;
} }

View File

@ -1,13 +1,14 @@
using Dalamud.Configuration; using Dalamud.Configuration;
using Dalamud.Plugin;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Dalamud.Logging;
namespace Macrology { namespace Macrology {
[Serializable]
public class Configuration : IPluginConfiguration { public class Configuration : IPluginConfiguration {
private Macrology Plugin { get; set; } = null!; private Macrology Plugin { get; set; } = null!;
@ -136,7 +137,7 @@ namespace Macrology {
return objectType == typeof(INode); 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."); throw new InvalidOperationException("Use default serialization.");
} }
@ -148,16 +149,16 @@ namespace Macrology {
INode node; INode node;
if (jsonObject.ContainsKey("Contents")) { if (jsonObject.ContainsKey("Contents")) {
node = new Macro( node = new Macro(
jsonObject["Id"].ToObject<Guid>(), jsonObject["Id"]!.ToObject<Guid>(),
jsonObject["Name"].ToObject<string>(), jsonObject["Name"]!.ToObject<string>()!,
jsonObject["Contents"].ToObject<string>() jsonObject["Contents"]!.ToObject<string>()!
); );
} }
else { else {
node = new Folder( node = new Folder(
jsonObject["Id"].ToObject<Guid>(), jsonObject["Id"]!.ToObject<Guid>(),
jsonObject["Name"].ToObject<string>(), jsonObject["Name"]!.ToObject<string>()!,
(List<INode>) this.ReadJson(jsonObject["Children"].CreateReader(), typeof(List<INode>), null, serializer) (List<INode>) this.ReadJson(jsonObject["Children"]!.CreateReader(), typeof(List<INode>), null, serializer)
); );
} }

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project> <Project>
<Target Name="PackagePlugin" AfterTargets="ILRepacker" Condition="'$(Configuration)' == 'Release'"> <Target Name="PackagePlugin" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<DalamudPackager <DalamudPackager
ProjectDir="$(ProjectDir)" ProjectDir="$(ProjectDir)"
OutputPath="$(OutputPath)" OutputPath="$(OutputPath)"
AssemblyName="$(AssemblyName)" AssemblyName="$(AssemblyName)"
VersionComponents="3" VersionComponents="3"
MakeZip="true" MakeZip="true"/>
Include="Macrology.dll;Macrology.pdb;Macrology.json"/>
</Target> </Target>
</Project> </Project>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ILRepacker" AfterTargets="Build">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll"/>
<InputAssemblies Include="$(OutputPath)\*.dll"
Exclude="$(OutputPath)\$(AssemblyName).dll"/>
</ItemGroup>
<ILRepack
Parallel="true"
Internalize="false"
InputAssemblies="@(InputAssemblies)"
TargetKind="Dll"
TargetPlatformVersion="v4"
LibraryPath="$(OutputPath);$(AppData)\XIVLauncher\addon\Hooks\dev"
OutputFile="$(OutputPath)\$(AssemblyName).dll"/>
</Target>
</Project>

View File

@ -1,11 +1,11 @@
using Dalamud.Game.Internal; using System;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Channels; using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Game;
namespace Macrology { namespace Macrology {
public class MacroHandler { public class MacroHandler {
@ -21,13 +21,13 @@ namespace Macrology {
private Macrology Plugin { get; } private Macrology Plugin { get; }
private readonly Channel<string> _commands = Channel.CreateUnbounded<string>(); private readonly Channel<string> _commands = Channel.CreateUnbounded<string>();
public ConcurrentDictionary<Guid, Macro> Running { get; } = new(); public ConcurrentDictionary<Guid, Macro?> Running { get; } = new();
private readonly ConcurrentDictionary<Guid, bool> _cancelled = new(); private readonly ConcurrentDictionary<Guid, bool> _cancelled = new();
private readonly ConcurrentDictionary<Guid, bool> _paused = new(); private readonly ConcurrentDictionary<Guid, bool> _paused = new();
public MacroHandler(Macrology plugin) { public MacroHandler(Macrology plugin) {
this.Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Macrology cannot be null"); 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) { private static string[] ExtractCommands(string macro) {
@ -138,7 +138,7 @@ namespace Macrology {
return cancelled; 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 // get a message to send, but discard it if we're not ready
if (!this._commands.Reader.TryRead(out var command) || !this._ready) { if (!this._commands.Reader.TryRead(out var command) || !this._ready) {
return; return;
@ -165,11 +165,11 @@ namespace Macrology {
return TimeSpan.FromSeconds(seconds); return TimeSpan.FromSeconds(seconds);
} }
internal void OnLogin(object sender, EventArgs args) { internal void OnLogin(object? sender, EventArgs args) {
this._ready = true; this._ready = true;
} }
internal void OnLogout(object sender, EventArgs args) { internal void OnLogout(object? sender, EventArgs args) {
this._ready = false; this._ready = false;
foreach (var id in this.Running.Keys) { foreach (var id in this.Running.Keys) {

View File

@ -1,6 +1,10 @@
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Plugin; using Dalamud.Plugin;
using System; using System;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using XivCommon; using XivCommon;
namespace Macrology { namespace Macrology {
@ -9,30 +13,43 @@ namespace Macrology {
public string Name => "Macrology"; public string Name => "Macrology";
public DalamudPluginInterface Interface { get; private set; } = null!; [PluginService]
public XivCommonBase Common { get; private set; } = null!; internal DalamudPluginInterface Interface { get; private init; } = 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!;
public void Initialize(DalamudPluginInterface pluginInterface) { [PluginService]
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null"); internal ChatGui ChatGui { get; private init; } = null!;
this.Common = new XivCommonBase(this.Interface);
[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.Ui = new PluginUi(this);
this.MacroHandler = new MacroHandler(this); this.MacroHandler = new MacroHandler(this);
this.Config = Configuration.Load(this) ?? new Configuration(); this.Config = Configuration.Load(this) ?? new Configuration();
this.Config.Initialise(this); this.Config.Initialise(this);
this.Commands = new Commands(this); this.Commands = new Commands(this);
this.Interface.UiBuilder.OnBuildUi += this.Ui.Draw; this.Interface.UiBuilder.Draw += this.Ui.Draw;
this.Interface.UiBuilder.OnOpenConfigUi += this.Ui.OpenSettings; this.Interface.UiBuilder.OpenConfigUi += this.Ui.OpenSettings;
this.Interface.Framework.OnUpdateEvent += this.MacroHandler.OnFrameworkUpdate; this.Framework.Update += this.MacroHandler.OnFrameworkUpdate;
this.Interface.ClientState.OnLogin += this.MacroHandler.OnLogin; this.ClientState.Login += this.MacroHandler.OnLogin;
this.Interface.ClientState.OnLogout += this.MacroHandler.OnLogout; this.ClientState.Logout += this.MacroHandler.OnLogout;
foreach (var entry in Commands.Descriptions) { foreach (var (name, desc) in Commands.Descriptions) {
this.Interface.CommandManager.AddHandler(entry.Key, new CommandInfo(this.Commands.OnCommand) { this.CommandManager.AddHandler(name, new CommandInfo(this.Commands.OnCommand) {
HelpMessage = entry.Value, HelpMessage = desc,
}); });
} }
} }
@ -43,13 +60,13 @@ namespace Macrology {
} }
if (disposing) { if (disposing) {
this.Interface.UiBuilder.OnBuildUi -= this.Ui.Draw; this.Interface.UiBuilder.Draw -= this.Ui.Draw;
this.Interface.UiBuilder.OnOpenConfigUi -= this.Ui.OpenSettings; this.Interface.UiBuilder.OpenConfigUi -= this.Ui.OpenSettings;
this.Interface.Framework.OnUpdateEvent -= this.MacroHandler.OnFrameworkUpdate; this.Framework.Update -= this.MacroHandler.OnFrameworkUpdate;
this.Interface.ClientState.OnLogin -= this.MacroHandler.OnLogin; this.ClientState.Login -= this.MacroHandler.OnLogin;
this.Interface.ClientState.OnLogout -= this.MacroHandler.OnLogout; this.ClientState.Logout -= this.MacroHandler.OnLogout;
foreach (var command in Commands.Descriptions.Keys) { foreach (var command in Commands.Descriptions.Keys) {
this.Interface.CommandManager.RemoveHandler(command); this.CommandManager.RemoveHandler(command);
} }
} }

View File

@ -4,8 +4,10 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<TargetFramework>net48</TargetFramework> <TargetFramework>net5-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Dalamud"> <Reference Include="Dalamud">
@ -26,9 +28,8 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/> <PackageReference Include="DalamudPackager" Version="2.1.2" />
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2"/> <PackageReference Include="System.Threading.Channels" Version="5.0.0" />
<PackageReference Include="System.Threading.Channels" Version="5.0.0"/> <PackageReference Include="XivCommon" Version="3.0.1" />
<PackageReference Include="XivCommon" Version="1.2.0"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,6 @@
author: ascclemens author: ascclemens
name: Macrology name: Macrology
punchline: Adds a better macro system to the game.
description: |- description: |-
Adds a better macro system to the game. Adds a better macro system to the game.

View File

@ -23,7 +23,7 @@ namespace Macrology {
this.Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Macrology cannot be null"); 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; this.SettingsVisible = true;
} }
@ -83,21 +83,25 @@ namespace Macrology {
ImGui.Text("Running macros"); ImGui.Text("Running macros");
ImGui.PushItemWidth(-1f); ImGui.PushItemWidth(-1f);
if (ImGui.BeginListBox("##running-macros")) { if (ImGui.BeginListBox("##running-macros")) {
foreach (var entry in this.Plugin.MacroHandler.Running) { foreach (var (id, value) in this.Plugin.MacroHandler.Running) {
var name = $"{entry.Value.Name}"; if (value == null) {
if (this._showIdents) { continue;
var ident = entry.Key.ToString();
name += $" ({ident.Substring(ident.Length - 7)})";
} }
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)"; name += " (paused)";
} }
var cancelled = this.Plugin.MacroHandler.IsCancelled(entry.Key); var cancelled = this.Plugin.MacroHandler.IsCancelled(id);
var flags = cancelled ? ImGuiSelectableFlags.Disabled : ImGuiSelectableFlags.None; var flags = cancelled ? ImGuiSelectableFlags.Disabled : ImGuiSelectableFlags.None;
if (ImGui.Selectable($"{name}##{entry.Key}", this.RunningChoice == entry.Key, flags)) { if (ImGui.Selectable($"{name}##{id}", this.RunningChoice == id, flags)) {
this.RunningChoice = entry.Key; this.RunningChoice = id;
} }
} }