mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 21:44:49 +00:00
af3dcb77bd
## 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:  ## 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
74 lines
1.5 KiB
TypeScript
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;
|
|
}
|
|
}
|