Dalamud/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/SeStringEvaluatorAgingStep.cs
Haselnussbomber fdbfdbb2cd
Add SeStringEvaluator service (#2188)
* Add SeStringEvaluator service

* Move DrawCopyableText into WidgetUtil

* Use Icon2RemapTable in SeStringRenderer

* Beautify some code

* Make sure to use the correct language

* Add SeString Creator widget

* Fix getting local parameters

* Update expressionNames

* misc changes

* Use InvariantCulture in TryResolveSheet

* Add SeStringEvaluatorAgingStep

* Fix item id comparisons

* Add SheetRedirectResolverAgingStep

* Add NounProcessorAgingStep

* Update SeString.CreateItemLink

This also adds the internal ItemUtil class.

* Fix name of SeStringCreator widget

* Add Global Parameters tab to SeStringCreatorWidget

* Load widgets on demand

* Update SeStringCreatorWidget

* Resizable SeStringCreatorWidget panels

* Update GamepadStateAgingStep

* Experimental status was removed in #2144

* Update SheetRedirectResolver, rewrite Noun params

* Fixes for 4 am code

* Remove incorrect column offset

I have no idea how that happened.

* Draw names of linked things

---------

Co-authored-by: Soreepeong <3614868+Soreepeong@users.noreply.github.com>
Co-authored-by: KazWolfe <KazWolfe@users.noreply.github.com>
2025-03-24 09:00:27 -07:00

92 lines
3.1 KiB
C#

using Dalamud.Game.ClientState;
using Dalamud.Game.Text.Evaluator;
using ImGuiNET;
using Lumina.Text.ReadOnly;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps;
/// <summary>
/// Test setup for SeStringEvaluator.
/// </summary>
internal class SeStringEvaluatorAgingStep : IAgingStep
{
private int step = 0;
/// <inheritdoc/>
public string Name => "Test SeStringEvaluator";
/// <inheritdoc/>
public SelfTestStepResult RunStep()
{
var seStringEvaluator = Service<SeStringEvaluator>.Get();
switch (this.step)
{
case 0:
ImGui.TextUnformatted("Is this the current time, and is it ticking?");
// This checks that EvaluateFromAddon fetches the correct Addon row,
// that MacroDecoder.GetMacroTime()->SetTime() has been called
// and that local and global parameters have been read correctly.
ImGui.TextUnformatted(seStringEvaluator.EvaluateFromAddon(31, [(uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds()]).ExtractText());
if (ImGui.Button("Yes"))
this.step++;
ImGui.SameLine();
if (ImGui.Button("No"))
return SelfTestStepResult.Fail;
break;
case 1:
ImGui.TextUnformatted("Checking pcname macro using the local player name...");
// This makes sure that NameCache.Instance()->TryGetCharacterInfoByEntityId() has been called,
// that it returned the local players name by using its EntityId,
// and that it didn't include the world name by checking the HomeWorldId against AgentLobby.Instance()->LobbyData.HomeWorldId.
var clientState = Service<ClientState>.Get();
var localPlayer = clientState.LocalPlayer;
if (localPlayer is null)
{
ImGui.TextUnformatted("You need to be logged in for this step.");
if (ImGui.Button("Skip"))
return SelfTestStepResult.NotRan;
return SelfTestStepResult.Waiting;
}
var evaluatedPlayerName = seStringEvaluator.Evaluate(ReadOnlySeString.FromMacroString("<pcname(lnum1)>"), [localPlayer.EntityId]).ExtractText();
var localPlayerName = localPlayer.Name.TextValue;
if (evaluatedPlayerName != localPlayerName)
{
ImGui.TextUnformatted("The player name doesn't match:");
ImGui.TextUnformatted($"Evaluated Player Name (got): {evaluatedPlayerName}");
ImGui.TextUnformatted($"Local Player Name (expected): {localPlayerName}");
if (ImGui.Button("Continue"))
return SelfTestStepResult.Fail;
return SelfTestStepResult.Waiting;
}
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp()
{
// ignored
this.step = 0;
}
}