mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add self test
This commit is contained in:
parent
409ce984da
commit
a8e00f91e7
18 changed files with 1004 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ using System.Numerics;
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
using Dalamud.Interface.Internal.Windows;
|
||||
using Dalamud.Interface.Internal.Windows.SelfTest;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Logging.Internal;
|
||||
|
|
@ -36,6 +37,7 @@ namespace Dalamud.Interface.Internal
|
|||
private readonly PluginInstallerWindow pluginWindow;
|
||||
private readonly ScratchpadWindow scratchpadWindow;
|
||||
private readonly SettingsWindow settingsWindow;
|
||||
private readonly SelfTestWindow selfTestWindow;
|
||||
|
||||
private ulong frameCount = 0;
|
||||
|
||||
|
|
@ -67,6 +69,7 @@ namespace Dalamud.Interface.Internal
|
|||
this.pluginWindow = new PluginInstallerWindow(dalamud) { IsOpen = false };
|
||||
this.scratchpadWindow = new ScratchpadWindow(dalamud) { IsOpen = false };
|
||||
this.settingsWindow = new SettingsWindow(dalamud) { IsOpen = false };
|
||||
this.selfTestWindow = new SelfTestWindow(dalamud) { IsOpen = false };
|
||||
|
||||
this.windowSystem.AddWindow(this.changelogWindow);
|
||||
this.windowSystem.AddWindow(this.colorDemoWindow);
|
||||
|
|
@ -79,6 +82,7 @@ namespace Dalamud.Interface.Internal
|
|||
this.windowSystem.AddWindow(this.pluginWindow);
|
||||
this.windowSystem.AddWindow(this.scratchpadWindow);
|
||||
this.windowSystem.AddWindow(this.settingsWindow);
|
||||
this.windowSystem.AddWindow(this.selfTestWindow);
|
||||
|
||||
this.dalamud.InterfaceManager.OnDraw += this.OnDraw;
|
||||
|
||||
|
|
@ -181,6 +185,11 @@ namespace Dalamud.Interface.Internal
|
|||
/// </summary>
|
||||
public void OpenSettings() => this.settingsWindow.IsOpen = true;
|
||||
|
||||
/// <summary>
|
||||
/// Opens the <see cref="SelfTestWindow"/>.
|
||||
/// </summary>
|
||||
public void OpenSelfTest() => this.selfTestWindow.IsOpen = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Toggle
|
||||
|
|
@ -253,6 +262,11 @@ namespace Dalamud.Interface.Internal
|
|||
/// </summary>
|
||||
public void ToggleSettingsWindow() => this.settingsWindow.Toggle();
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the <see cref="SelfTestWindow"/>.
|
||||
/// </summary>
|
||||
public void ToggleSelfTestWindow() => this.selfTestWindow.Toggle();
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnDraw()
|
||||
|
|
@ -383,6 +397,13 @@ namespace Dalamud.Interface.Internal
|
|||
this.OpenColorsDemoWindow();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open Self-Test"))
|
||||
{
|
||||
this.OpenSelfTest();
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImGuiDrawDemoWindow);
|
||||
|
||||
ImGui.Separator();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the Actor Table.
|
||||
/// </summary>
|
||||
internal class ActorTableAgingStep : IAgingStep
|
||||
{
|
||||
private int index = 0;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test ActorTable";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.Text("Checking actor table...");
|
||||
|
||||
if (this.index == dalamud.ClientState.Actors.Length - 1)
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
var actor = dalamud.ClientState.Actors[this.index];
|
||||
this.index++;
|
||||
|
||||
if (actor == null)
|
||||
{
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
Util.ShowObject(actor);
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for Chat.
|
||||
/// </summary>
|
||||
internal class ChatAgingStep : IAgingStep
|
||||
{
|
||||
private int step = 0;
|
||||
private bool subscribed = false;
|
||||
private bool hasPassed = false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Chat";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
switch (this.step)
|
||||
{
|
||||
case 0:
|
||||
dalamud.Framework.Gui.Chat.Print("Testing!");
|
||||
this.step++;
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ImGui.Text("Type \"/e DALAMUD\" in chat...");
|
||||
|
||||
if (!this.subscribed)
|
||||
{
|
||||
this.subscribed = true;
|
||||
dalamud.Framework.Gui.Chat.OnChatMessage += this.ChatOnOnChatMessage;
|
||||
}
|
||||
|
||||
if (this.hasPassed)
|
||||
{
|
||||
dalamud.Framework.Gui.Chat.OnChatMessage -= this.ChatOnOnChatMessage;
|
||||
this.subscribed = false;
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
dalamud.Framework.Gui.Chat.OnChatMessage -= this.ChatOnOnChatMessage;
|
||||
this.subscribed = false;
|
||||
}
|
||||
|
||||
private void ChatOnOnChatMessage(
|
||||
XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool ishandled)
|
||||
{
|
||||
if (type == XivChatType.Echo && message.TextValue == "DALAMUD")
|
||||
{
|
||||
this.hasPassed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
using Dalamud.Game.ClientState.Conditions;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for Condition.
|
||||
/// </summary>
|
||||
internal class ConditionAgingStep : IAgingStep
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Condition";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
if (!dalamud.ClientState.Condition.Any())
|
||||
{
|
||||
Log.Error("No condition flags present.");
|
||||
return SelfTestStepResult.Fail;
|
||||
}
|
||||
|
||||
ImGui.Text("Please jump...");
|
||||
|
||||
return dalamud.ClientState.Condition[ConditionFlag.Jumping] ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for Territory Change.
|
||||
/// </summary>
|
||||
internal class EnterTerritoryAgingStep : IAgingStep
|
||||
{
|
||||
private readonly ushort territory;
|
||||
private readonly string terriName;
|
||||
private bool subscribed = false;
|
||||
private bool hasPassed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnterTerritoryAgingStep"/> class.
|
||||
/// </summary>
|
||||
/// <param name="terri">The territory to check for.</param>
|
||||
/// <param name="name">Name to show.</param>
|
||||
public EnterTerritoryAgingStep(ushort terri, string name)
|
||||
{
|
||||
this.terriName = name;
|
||||
this.territory = terri;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => $"Enter Terri: {this.terriName}";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.TextUnformatted(this.Name);
|
||||
|
||||
if (!this.subscribed)
|
||||
{
|
||||
dalamud.ClientState.TerritoryChanged += this.ClientStateOnTerritoryChanged;
|
||||
this.subscribed = true;
|
||||
}
|
||||
|
||||
if (this.hasPassed)
|
||||
{
|
||||
dalamud.ClientState.TerritoryChanged -= this.ClientStateOnTerritoryChanged;
|
||||
this.subscribed = false;
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
dalamud.ClientState.TerritoryChanged -= this.ClientStateOnTerritoryChanged;
|
||||
this.subscribed = false;
|
||||
}
|
||||
|
||||
private void ClientStateOnTerritoryChanged(object sender, ushort e)
|
||||
{
|
||||
if (e == this.territory)
|
||||
{
|
||||
this.hasPassed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the Fate Table.
|
||||
/// </summary>
|
||||
internal class FateTableAgingStep : IAgingStep
|
||||
{
|
||||
private int index = 0;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test FateTable";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.Text("Checking fate table...");
|
||||
|
||||
if (this.index == dalamud.ClientState.Fates.Length - 1)
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
var actor = dalamud.ClientState.Fates[this.index];
|
||||
this.index++;
|
||||
|
||||
if (actor == null)
|
||||
{
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
Util.ShowObject(actor);
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
using Dalamud.Game.ClientState.GamePad;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the Gamepad State.
|
||||
/// </summary>
|
||||
internal class GamepadStateAgingStep : IAgingStep
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test GamePadState";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.Text("Hold down North, East, L1");
|
||||
|
||||
if (dalamud.ClientState.GamepadState.Pressed(GamepadButtons.North) == 1
|
||||
&& dalamud.ClientState.GamepadState.Pressed(GamepadButtons.East) == 1
|
||||
&& dalamud.ClientState.GamepadState.Pressed(GamepadButtons.L1) == 1)
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
using Dalamud.Game.Gui;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the Hover events.
|
||||
/// </summary>
|
||||
internal class HoverAgingStep : IAgingStep
|
||||
{
|
||||
private bool clearedItem = false;
|
||||
private bool clearedAction = false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Hover";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
var hoverItem = dalamud.Framework.Gui.HoveredItem;
|
||||
var hoverAction = dalamud.Framework.Gui.HoveredAction;
|
||||
|
||||
if (!this.clearedItem)
|
||||
{
|
||||
ImGui.Text("Hover WHM soul crystal...");
|
||||
|
||||
if (hoverItem == 4547)
|
||||
{
|
||||
this.clearedItem = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.clearedAction)
|
||||
{
|
||||
ImGui.Text("Hover \"Open Linkshells\" action...");
|
||||
|
||||
if (hoverAction != null && hoverAction.ActionKind == HoverActionKind.MainCommand &&
|
||||
hoverAction.ActionID == 28)
|
||||
{
|
||||
this.clearedAction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.clearedItem && this.clearedAction)
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for test implementations.
|
||||
/// </summary>
|
||||
internal interface IAgingStep
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the test.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Run the test step, once per frame it is active.
|
||||
/// </summary>
|
||||
/// <param name="dalamud">Dalamud instance to act on.</param>
|
||||
/// <returns>The result of this frame, test is discarded once a result other than <see cref="SelfTestStepResult.Waiting"/> is returned.</returns>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud);
|
||||
|
||||
/// <summary>
|
||||
/// Clean up this test.
|
||||
/// </summary>
|
||||
/// <param name="dalamud">Dalamud instance to act on.</param>
|
||||
public void CleanUp(Dalamud dalamud);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
using Dalamud.Game.ClientState.Keys;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the Key State.
|
||||
/// </summary>
|
||||
internal class KeyStateAgingStep : IAgingStep
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test KeyState";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.Text("Hold down D,A,L,M,U");
|
||||
|
||||
if (dalamud.ClientState.KeyState[VirtualKey.D]
|
||||
&& dalamud.ClientState.KeyState[VirtualKey.A]
|
||||
&& dalamud.ClientState.KeyState[VirtualKey.L]
|
||||
&& dalamud.ClientState.KeyState[VirtualKey.M]
|
||||
&& dalamud.ClientState.KeyState[VirtualKey.U])
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for the login events.
|
||||
/// </summary>
|
||||
internal class LoginEventAgingStep : IAgingStep
|
||||
{
|
||||
private bool isSubscribed = false;
|
||||
private bool hasPassed = false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Log-In";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
ImGui.Text("Log in now...");
|
||||
|
||||
if (!this.isSubscribed)
|
||||
{
|
||||
dalamud.ClientState.OnLogin += this.ClientStateOnOnLogin;
|
||||
this.isSubscribed = true;
|
||||
}
|
||||
|
||||
if (this.hasPassed)
|
||||
{
|
||||
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
|
||||
this.isSubscribed = false;
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
if (this.isSubscribed)
|
||||
{
|
||||
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
|
||||
this.isSubscribed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClientStateOnOnLogin(object sender, EventArgs e)
|
||||
{
|
||||
this.hasPassed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Dalamud.Utility;
|
||||
using Lumina.Excel;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for Lumina.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">ExcelRow to run test on.</typeparam>
|
||||
internal class LuminaAgingStep<T> : IAgingStep
|
||||
where T : ExcelRow
|
||||
{
|
||||
private int step = 0;
|
||||
private List<T> rows;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Lumina";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
this.rows ??= dalamud.Data.GetExcelSheet<T>().ToList();
|
||||
|
||||
Util.ShowObject(this.rows[this.step]);
|
||||
|
||||
this.step++;
|
||||
return this.step >= this.rows.Count ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
using Dalamud.Game.Gui.PartyFinder.Types;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for Party Finder events.
|
||||
/// </summary>
|
||||
internal class PartyFinderAgingStep : IAgingStep
|
||||
{
|
||||
private bool subscribed = false;
|
||||
private bool hasPassed = false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Party Finder";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
if (!this.subscribed)
|
||||
{
|
||||
dalamud.Framework.Gui.PartyFinder.ReceiveListing += this.PartyFinderOnReceiveListing;
|
||||
this.subscribed = true;
|
||||
}
|
||||
|
||||
if (this.hasPassed)
|
||||
{
|
||||
dalamud.Framework.Gui.PartyFinder.ReceiveListing -= this.PartyFinderOnReceiveListing;
|
||||
this.subscribed = false;
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
ImGui.Text("Open Party Finder");
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
if (this.subscribed)
|
||||
{
|
||||
dalamud.Framework.Gui.PartyFinder.ReceiveListing -= this.PartyFinderOnReceiveListing;
|
||||
this.subscribed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void PartyFinderOnReceiveListing(PartyFinderListing listing, PartyFinderListingEventArgs args)
|
||||
{
|
||||
this.hasPassed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for targets.
|
||||
/// </summary>
|
||||
internal class TargetAgingStep : IAgingStep
|
||||
{
|
||||
private int step = 0;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Target";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
switch (this.step)
|
||||
{
|
||||
case 0:
|
||||
dalamud.ClientState.Targets.ClearCurrentTarget();
|
||||
dalamud.ClientState.Targets.ClearFocusTarget();
|
||||
|
||||
this.step++;
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ImGui.Text("Target a player...");
|
||||
|
||||
var cTarget = dalamud.ClientState.Targets.CurrentTarget;
|
||||
if (cTarget is PlayerCharacter)
|
||||
{
|
||||
this.step++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ImGui.Text("Focus-Target a Battle NPC...");
|
||||
|
||||
var fTarget = dalamud.ClientState.Targets.FocusTarget;
|
||||
if (fTarget is BattleNpc)
|
||||
{
|
||||
this.step++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ImGui.Text("Soft-Target an EventObj...");
|
||||
|
||||
var sTarget = dalamud.ClientState.Targets.FocusTarget;
|
||||
if (sTarget is EventObj)
|
||||
{
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test setup for toasts.
|
||||
/// </summary>
|
||||
internal class ToastAgingStep : IAgingStep
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Name => "Test Toasts";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
dalamud.Framework.Gui.Toast.ShowNormal("Normal Toast");
|
||||
dalamud.Framework.Gui.Toast.ShowError("Error Toast");
|
||||
|
||||
return SelfTestStepResult.Pass;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
|
||||
{
|
||||
/// <summary>
|
||||
/// Test that waits N frames.
|
||||
/// </summary>
|
||||
internal class WaitFramesAgingStep : IAgingStep
|
||||
{
|
||||
private readonly int frames;
|
||||
private int cFrames;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WaitFramesAgingStep"/> class.
|
||||
/// </summary>
|
||||
/// <param name="frames">Amount of frames to wait.</param>
|
||||
public WaitFramesAgingStep(int frames)
|
||||
{
|
||||
this.frames = frames;
|
||||
this.cFrames = frames;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => $"Wait {this.cFrames} frames";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SelfTestStepResult RunStep(Dalamud dalamud)
|
||||
{
|
||||
this.cFrames--;
|
||||
|
||||
return this.cFrames <= 0 ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void CleanUp(Dalamud dalamud)
|
||||
{
|
||||
this.cFrames = this.frames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
namespace Dalamud.Interface.Internal.Windows.SelfTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum declaring result states of tests.
|
||||
/// </summary>
|
||||
internal enum SelfTestStepResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Test was not ran.
|
||||
/// </summary>
|
||||
NotRan,
|
||||
|
||||
/// <summary>
|
||||
/// Test is waiting for completion.
|
||||
/// </summary>
|
||||
Waiting,
|
||||
|
||||
/// <summary>
|
||||
/// Test has failed.
|
||||
/// </summary>
|
||||
Fail,
|
||||
|
||||
/// <summary>
|
||||
/// Test has passed.
|
||||
/// </summary>
|
||||
Pass,
|
||||
}
|
||||
}
|
||||
258
Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs
Normal file
258
Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging.Internal;
|
||||
using ImGuiNET;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.SelfTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Window for the Self-Test logic.
|
||||
/// </summary>
|
||||
internal class SelfTestWindow : Window
|
||||
{
|
||||
private static readonly ModuleLog Log = new("AGING");
|
||||
|
||||
private readonly Dalamud dalamud;
|
||||
|
||||
private readonly List<IAgingStep> steps =
|
||||
new()
|
||||
{
|
||||
new LoginEventAgingStep(),
|
||||
new WaitFramesAgingStep(1000),
|
||||
new EnterTerritoryAgingStep(148, "Central Shroud"),
|
||||
new ActorTableAgingStep(),
|
||||
new FateTableAgingStep(),
|
||||
new ConditionAgingStep(),
|
||||
new ToastAgingStep(),
|
||||
new TargetAgingStep(),
|
||||
new KeyStateAgingStep(),
|
||||
new GamepadStateAgingStep(),
|
||||
new ChatAgingStep(),
|
||||
new HoverAgingStep(),
|
||||
new LuminaAgingStep<TerritoryType>(),
|
||||
new PartyFinderAgingStep(),
|
||||
};
|
||||
|
||||
private readonly List<(SelfTestStepResult Result, TimeSpan? Duration)> stepResults = new();
|
||||
|
||||
private bool selfTestRunning = false;
|
||||
private int currentStep = 0;
|
||||
|
||||
private DateTimeOffset lastTestStart;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SelfTestWindow"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dalamud">The dalamud instance to act on.</param>
|
||||
public SelfTestWindow(Dalamud dalamud)
|
||||
: base("Dalamud Self-Test", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
|
||||
{
|
||||
this.dalamud = dalamud;
|
||||
|
||||
this.Size = new Vector2(800, 800);
|
||||
this.SizeCondition = ImGuiCond.FirstUseEver;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Draw()
|
||||
{
|
||||
if (this.selfTestRunning)
|
||||
{
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Stop))
|
||||
{
|
||||
this.StopTests();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
|
||||
{
|
||||
this.stepResults.Add((SelfTestStepResult.NotRan, null));
|
||||
this.currentStep++;
|
||||
this.lastTestStart = DateTimeOffset.Now;
|
||||
|
||||
if (this.currentStep >= this.steps.Count)
|
||||
{
|
||||
this.StopTests();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Play))
|
||||
{
|
||||
this.selfTestRunning = true;
|
||||
this.currentStep = 0;
|
||||
this.stepResults.Clear();
|
||||
this.lastTestStart = DateTimeOffset.Now;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
|
||||
|
||||
ImGuiHelpers.ScaledDummy(10);
|
||||
|
||||
this.DrawResultTable();
|
||||
|
||||
ImGuiHelpers.ScaledDummy(10);
|
||||
|
||||
if (this.currentStep >= this.steps.Count)
|
||||
{
|
||||
if (this.selfTestRunning)
|
||||
{
|
||||
this.StopTests();
|
||||
}
|
||||
|
||||
if (this.stepResults.Any(x => x.Result == SelfTestStepResult.Fail))
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "One or more checks failed!");
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.HealerGreen, "All checks passed!");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.selfTestRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
var step = this.steps[this.currentStep];
|
||||
ImGui.TextUnformatted($"Current: {step.Name}");
|
||||
|
||||
ImGuiHelpers.ScaledDummy(10);
|
||||
|
||||
SelfTestStepResult result;
|
||||
try
|
||||
{
|
||||
result = step.RunStep(this.dalamud);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Step failed: {step.Name}");
|
||||
result = SelfTestStepResult.Fail;
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (result != SelfTestStepResult.Waiting)
|
||||
{
|
||||
var duration = DateTimeOffset.Now - this.lastTestStart;
|
||||
this.currentStep++;
|
||||
this.stepResults.Add((result, duration));
|
||||
|
||||
this.lastTestStart = DateTimeOffset.Now;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawResultTable()
|
||||
{
|
||||
if (ImGui.BeginTable("agingResultTable", 4, ImGuiTableFlags.Borders))
|
||||
{
|
||||
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f);
|
||||
ImGui.TableSetupColumn("Name");
|
||||
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f);
|
||||
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f);
|
||||
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
for (var i = 0; i < this.steps.Count; i++)
|
||||
{
|
||||
var step = this.steps[i];
|
||||
ImGui.TableNextRow();
|
||||
|
||||
ImGui.TableSetColumnIndex(0);
|
||||
ImGui.Text(i.ToString());
|
||||
|
||||
ImGui.TableSetColumnIndex(1);
|
||||
ImGui.Text(step.Name);
|
||||
|
||||
ImGui.TableSetColumnIndex(2);
|
||||
ImGui.PushFont(Interface.Internal.InterfaceManager.MonoFont);
|
||||
if (this.stepResults.Count > i)
|
||||
{
|
||||
var result = this.stepResults[i];
|
||||
|
||||
switch (result.Result)
|
||||
{
|
||||
case SelfTestStepResult.Pass:
|
||||
ImGui.TextColored(ImGuiColors.HealerGreen, "PASS");
|
||||
break;
|
||||
case SelfTestStepResult.Fail:
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "FAIL");
|
||||
break;
|
||||
default:
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.selfTestRunning && this.currentStep == i)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "WAIT");
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopFont();
|
||||
|
||||
ImGui.TableSetColumnIndex(3);
|
||||
if (this.stepResults.Count > i)
|
||||
{
|
||||
var (_, duration) = this.stepResults[i];
|
||||
|
||||
if (duration.HasValue)
|
||||
{
|
||||
ImGui.TextUnformatted(duration.Value.ToString("g"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.selfTestRunning && this.currentStep == i)
|
||||
{
|
||||
ImGui.TextUnformatted((DateTimeOffset.Now - this.lastTestStart).ToString("g"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
private void StopTests()
|
||||
{
|
||||
this.selfTestRunning = false;
|
||||
|
||||
foreach (var agingStep in this.steps)
|
||||
{
|
||||
try
|
||||
{
|
||||
agingStep.CleanUp(this.dalamud);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Could not clean up AgingStep: {agingStep.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue