perf(messages): restructure format-string call sites (#2437)
## Summary Phase 3 PR B of the message-interpolation cleanup. Handles the multi-line restructure sites flagged in `dev-docs/string-handling-message-interp-audit.md` (Phase 2). Phase 3.1 (PR #2436) handled trivial sweeps; this PR handles sites that needed an `if/else` hoist or switch restructure to eliminate `string.Format` while preserving exact message text. Each site previously allocated an intermediate `string.Format(...)` result before passing to the message handler, despite Phase 1 making the handler accept interpolated string handlers natively. ## Sites fixed - **`Projects/Server/Mobiles/Mobile.cs:7911`** - Title/guild header was using `string.Format` with a conditional template (`"[{1}]{2}"` vs `"[{0}, {1}]{2}"`). Split into `if (title.Length <= 0)` / `else` with direct `$"..."` interpolation. - **`Projects/UOContent/Engines/ConPVP/DuelContext.cs:1337`** - View-ladder rank text used `string.Format(text, from == pm ? "You" : "They")`. Split into `if (from == pm)` / `else` with direct `$"..."` interpolation in each branch. - **`Projects/UOContent/Engines/ConPVP/DuelContext.cs:1463`** - Showladder text reused a single format string for both `LocalOverheadMessage` ("You ... are ...") and `NonlocalOverheadMessage` ("`{pm.Name}` ... is ..."). Each call now uses an inline `$"..."` directly; no shared template. - **`Projects/UOContent/Engines/ConPVP/Gumps/ConfirmSignupGump.cs:518`** - The signup confirmation message used a `switch` expression assigning a literal format string to `fmt`, then `string.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil)`. Converted to a `switch` statement where each case calls `_registrar.PrivateOverheadMessage(...)` directly with an inline `$"..."`. Lady/Lord branching is hoisted to a `title` local. ## Exempted - **`Projects/UOContent/Engines/ConPVP/Participant.cs:138`** - The `nonLocalOverhead` format string is a parameter passed in by callers of `Participant.Broadcast`. Investigation found 5 call sites in `DuelContext.cs` (lines 782, 802, 1187, 1196, and three at 1535/1564/1608) that pass distinct literal format strings. Refactoring would require changing all 5 callers and the method signature - out of scope for this PR. Marked with a `// Phase 3 audit:` comment per the audit's exemption convention.
This commit is contained in:
parent
b2ccc7e4f3
commit
ca6064b775
5 changed files with 108 additions and 45 deletions
|
|
@ -1334,16 +1334,26 @@ public partial class DuelContext
|
|||
return; // sanity
|
||||
}
|
||||
|
||||
var text =
|
||||
$"{{0}} are ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}.";
|
||||
|
||||
pm.PrivateOverheadMessage(
|
||||
MessageType.Regular,
|
||||
pm.SpeechHue,
|
||||
true,
|
||||
string.Format(text, from == pm ? "You" : "They"),
|
||||
from.NetState
|
||||
);
|
||||
if (from == pm)
|
||||
{
|
||||
pm.PrivateOverheadMessage(
|
||||
MessageType.Regular,
|
||||
pm.SpeechHue,
|
||||
true,
|
||||
$"You are ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}.",
|
||||
from.NetState
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
pm.PrivateOverheadMessage(
|
||||
MessageType.Regular,
|
||||
pm.SpeechHue,
|
||||
true,
|
||||
$"They are ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}.",
|
||||
from.NetState
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (obj is Mobile mob)
|
||||
{
|
||||
|
|
@ -1460,15 +1470,17 @@ public partial class DuelContext
|
|||
return; // sanity
|
||||
}
|
||||
|
||||
var text =
|
||||
$"{{0}} {{1}} ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}.";
|
||||
|
||||
pm.LocalOverheadMessage(MessageType.Regular, pm.SpeechHue, true, string.Format(text, "You", "are"));
|
||||
pm.LocalOverheadMessage(
|
||||
MessageType.Regular,
|
||||
pm.SpeechHue,
|
||||
true,
|
||||
$"You are ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}."
|
||||
);
|
||||
pm.NonlocalOverheadMessage(
|
||||
MessageType.Regular,
|
||||
pm.SpeechHue,
|
||||
true,
|
||||
string.Format(text, pm.Name, "is")
|
||||
$"{pm.Name} is ranked {LadderGump.Rank(entry.Index + 1)} at level {Ladder.GetLevel(entry.Experience)}."
|
||||
);
|
||||
|
||||
// pm.PublicOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( "Level {0} with {1} win{2} and {3} loss{4}.", Ladder.GetLevel( entry.Experience ), entry.Wins, entry.Wins==1?"":"s", entry.Losses, entry.Losses==1?"":"es" ) );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue