Files
HellionChat/HellionChat/_Helpers/SenderNameFormatter.cs
T
JonKazama-Hellion 1d3b429f1b
Security / scan (push) Successful in 23s
Build / Build (Release) (push) Successful in 31s
Forge Announce / Post changelog to Hellion Forge (push) Successful in 6s
Release / Build and attach release ZIP (push) Successful in 41s
style(format): apply csharpier and markdownlint reflow
2026-05-23 09:07:01 +02:00

53 lines
1.7 KiB
C#

using System;
namespace HellionChat._Helpers;
// UI-7 pure decision helper: builds the display string for a sender's name +
// world per the user's NameFormMode / WorldSuffixMode. Dalamud-free so the
// Build Suite can cover every combination; SenderNameDisplay feeds it the name
// and world it pulled from the PlayerPayload.
// TEST-MIRROR: ../../../Hellion Build test/Ui/SenderNameFormatterTests.cs
public static class SenderNameFormatter
{
public static string Format(
string fullName,
string worldName,
bool isHomeWorld,
NameFormMode formMode,
WorldSuffixMode suffixMode
)
{
var name = FormatName(fullName, formMode);
var showWorld = suffixMode switch
{
WorldSuffixMode.Never => false,
WorldSuffixMode.Always => true,
WorldSuffixMode.OtherWorldOnly => !isHomeWorld,
_ => !isHomeWorld,
};
return showWorld && !string.IsNullOrEmpty(worldName) ? $"{name}@{worldName}" : name;
}
private static string FormatName(string fullName, NameFormMode mode)
{
if (mode == NameFormMode.Full)
return fullName;
// FFXIV character names are two words. Anything else (one word, odd
// spacing) falls back to the full name rather than risking an empty or
// misleading render.
var parts = fullName.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
return fullName;
return mode switch
{
NameFormMode.FirstNameOnly => parts[0],
NameFormMode.Initials => $"{parts[0][0]}. {parts[^1][0]}.",
_ => fullName,
};
}
}