mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 14:14:38 +00:00
07916d46bf
## Description: Changed from consolex to console ## 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 - [x] 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: @qqkedsi
84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
|
|
|
export class QuickChatExecution implements Execution {
|
|
private sender: Player;
|
|
private recipient: Player;
|
|
private mg: Game;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private senderID: PlayerID,
|
|
private recipientID: PlayerID,
|
|
private quickChatKey: string,
|
|
private variables: Record<string, string>,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
if (!mg.hasPlayer(this.senderID)) {
|
|
console.warn(`QuickChatExecution: sender ${this.senderID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (!mg.hasPlayer(this.recipientID)) {
|
|
console.warn(
|
|
`QuickChatExecution: recipient ${this.recipientID} not found`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.sender = mg.player(this.senderID);
|
|
this.recipient = mg.player(this.recipientID);
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
const message = this.getMessageFromKey(this.quickChatKey, this.variables);
|
|
|
|
this.mg.displayChat(
|
|
message[1],
|
|
message[0],
|
|
this.variables,
|
|
this.recipient.id(),
|
|
true,
|
|
this.sender.name(),
|
|
);
|
|
|
|
this.mg.displayChat(
|
|
message[1],
|
|
message[0],
|
|
this.variables,
|
|
this.sender.id(),
|
|
false,
|
|
this.recipient.name(),
|
|
);
|
|
|
|
console.log(
|
|
`[QuickChat] ${this.sender.name} → ${this.recipient.name}: ${message}`,
|
|
);
|
|
|
|
this.active = false;
|
|
}
|
|
|
|
owner(): Player {
|
|
return this.sender;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
|
|
private getMessageFromKey(
|
|
fullKey: string,
|
|
vars: Record<string, string>,
|
|
): string[] {
|
|
const translated = fullKey.split(".");
|
|
return translated;
|
|
}
|
|
}
|