Add Self Test

This commit is contained in:
RedworkDE 2025-12-22 20:21:07 +01:00
parent 282fa87571
commit b2397efb25

View file

@ -1,4 +1,5 @@
using Dalamud.Bindings.ImGui; using Dalamud.Bindings.ImGui;
using Dalamud.Game.Chat;
using Dalamud.Game.Gui; using Dalamud.Game.Gui;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
@ -12,8 +13,12 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.Steps;
internal class ChatSelfTestStep : ISelfTestStep internal class ChatSelfTestStep : ISelfTestStep
{ {
private int step = 0; private int step = 0;
private bool subscribed = false; private bool subscribedChatMessage = false;
private bool subscribedLogMessage = false;
private bool hasPassed = false; private bool hasPassed = false;
private bool hasTeleportGil = false;
private bool hasTeleportTicket = false;
private int teleportCount = 0;
/// <inheritdoc/> /// <inheritdoc/>
public string Name => "Test Chat"; public string Name => "Test Chat";
@ -34,20 +39,63 @@ internal class ChatSelfTestStep : ISelfTestStep
case 1: case 1:
ImGui.Text("Type \"/e DALAMUD\" in chat..."); ImGui.Text("Type \"/e DALAMUD\" in chat...");
if (!this.subscribed) if (!this.subscribedChatMessage)
{ {
this.subscribed = true; this.subscribedChatMessage = true;
chatGui.ChatMessage += this.ChatOnOnChatMessage; chatGui.ChatMessage += this.ChatOnOnChatMessage;
} }
if (this.hasPassed) if (this.hasPassed)
{ {
chatGui.ChatMessage -= this.ChatOnOnChatMessage; chatGui.ChatMessage -= this.ChatOnOnChatMessage;
this.subscribed = false; this.subscribedChatMessage = false;
return SelfTestStepResult.Pass; this.step++;
} }
break; break;
case 2:
ImGui.Text("Teleport somewhere...");
if (!this.subscribedLogMessage)
{
this.subscribedLogMessage = true;
chatGui.LogMessage += this.ChatOnLogMessage;
}
if (this.hasTeleportGil)
{
ImGui.Text($"You spent {this.teleportCount} gil to teleport.");
}
if (this.hasTeleportTicket)
{
ImGui.Text($"You used a ticket to teleport and have {this.teleportCount} remaining.");
}
if (this.hasTeleportGil || this.hasTeleportTicket)
{
ImGui.Text("Is this correct?");
if (ImGui.Button("Yes"))
{
chatGui.LogMessage -= this.ChatOnLogMessage;
this.subscribedLogMessage = false;
this.step++;
}
ImGui.SameLine();
if (ImGui.Button("No"))
{
chatGui.LogMessage -= this.ChatOnLogMessage;
this.subscribedLogMessage = false;
return SelfTestStepResult.Fail;
}
}
break;
default:
return SelfTestStepResult.Pass;
} }
return SelfTestStepResult.Waiting; return SelfTestStepResult.Waiting;
@ -59,7 +107,9 @@ internal class ChatSelfTestStep : ISelfTestStep
var chatGui = Service<ChatGui>.Get(); var chatGui = Service<ChatGui>.Get();
chatGui.ChatMessage -= this.ChatOnOnChatMessage; chatGui.ChatMessage -= this.ChatOnOnChatMessage;
this.subscribed = false; chatGui.LogMessage -= this.ChatOnLogMessage;
this.subscribedChatMessage = false;
this.subscribedLogMessage = false;
} }
private void ChatOnOnChatMessage( private void ChatOnOnChatMessage(
@ -70,4 +120,20 @@ internal class ChatSelfTestStep : ISelfTestStep
this.hasPassed = true; this.hasPassed = true;
} }
} }
private void ChatOnLogMessage(ILogMessage message)
{
if (message.LogMessageId == 4590 && message.TryGetIntParameter(0, out var value))
{
this.hasTeleportGil = true;
this.hasTeleportTicket = false;
this.teleportCount = value;
}
if (message.LogMessageId == 4591 && message.TryGetIntParameter(0, out var item) && item == 7569 && message.TryGetIntParameter(1, out var remaining))
{
this.hasTeleportGil = false;
this.hasTeleportTicket = true;
this.teleportCount = remaining;
}
}
} }