Files
OpenFrontIO/src/core/execution/QuickChatExecution.ts
T
VariableVince af3dcb77bd Fix: anonymized name isn't used in chat message (#1265)
## Description:

Bugfix:
- Anonymized name isn't used in Event Panel message, instead actual
player name is displayed even if "Hidden names" is enabled. Neither for
the 'P1' name in the chat message, nor for the name in "From name:
message" and "Sent name: message". Fix: in QuickChatExecution, instead
of sender.name() and recipient.name(), send their id(). In
EventsDisplay, from that PlayerID get their displayName.

- There was more in this PR to try to improve readibility and remove
some unused/uncommented code. This was moved later to #1275, which may
be re-opened and brought up-to-date after this PR is merged.

Example screenshot of the bug before the fix, send chat to anonymized
name 'Norwegian Sisterhood' but in Event Panel real name 'Mister Goo'
was displayed:
![Sent Mister Goo instead of anonymous Norwegian
Brotherhood](https://github.com/user-attachments/assets/197e2808-aa85-4271-9c96-c53fe10f6546)

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [ ] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors
2025-07-15 19:43:31 -04:00

74 lines
1.5 KiB
TypeScript

import { Execution, Game, Player, PlayerID } from "../game/Game";
export class QuickChatExecution implements Execution {
private recipient: Player;
private mg: Game;
private active = true;
constructor(
private sender: Player,
private recipientID: PlayerID,
private quickChatKey: string,
private target: PlayerID | undefined,
) {}
init(mg: Game, ticks: number): void {
this.mg = mg;
if (!mg.hasPlayer(this.recipientID)) {
console.warn(
`QuickChatExecution: recipient ${this.recipientID} not found`,
);
this.active = false;
return;
}
this.recipient = mg.player(this.recipientID);
}
tick(ticks: number): void {
const message = this.getMessageFromKey(this.quickChatKey);
this.mg.displayChat(
message[1],
message[0],
this.target,
this.recipient.id(),
true,
this.sender.id(),
);
this.mg.displayChat(
message[1],
message[0],
this.target,
this.sender.id(),
false,
this.recipient.id(),
);
console.log(
`[QuickChat] ${this.sender.name}${this.recipient.displayName}: ${message}`,
);
this.active = false;
}
owner(): Player {
return this.sender;
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
private getMessageFromKey(fullKey: string): string[] {
const translated = fullKey.split(".");
return translated;
}
}