mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 22:04:38 +00:00
MLS for Quick Chat (#686)
## Description: <img width="842" alt="スクリーンショット 2025-05-09 17 51 27" src="https://github.com/user-attachments/assets/b9a2cb5b-74d2-4c07-aed2-01d719de6eb4" /> MLS ## Please complete the following: - [x] I have added screenshots for all UI updates - [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
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import quickChatData from "../../../resources/QuickChat.json";
|
||||
import { consolex } from "../Consolex";
|
||||
import { Execution, Game, MessageType, Player, PlayerID } from "../game/Game";
|
||||
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
||||
|
||||
export class QuickChatExecution implements Execution {
|
||||
private sender: Player;
|
||||
@@ -38,16 +37,22 @@ export class QuickChatExecution implements Execution {
|
||||
tick(ticks: number): void {
|
||||
const message = this.getMessageFromKey(this.quickChatKey, this.variables);
|
||||
|
||||
this.mg.displayMessage(
|
||||
`${this.sender.name()}: ${message}`,
|
||||
MessageType.CHAT,
|
||||
this.mg.displayChat(
|
||||
message[1],
|
||||
message[0],
|
||||
this.variables,
|
||||
this.recipient.id(),
|
||||
true,
|
||||
this.recipient.name(),
|
||||
);
|
||||
|
||||
this.mg.displayMessage(
|
||||
`You sent to ${this.recipient.name()}: ${message}`,
|
||||
MessageType.CHAT,
|
||||
this.mg.displayChat(
|
||||
message[1],
|
||||
message[0],
|
||||
this.variables,
|
||||
this.sender.id(),
|
||||
false,
|
||||
this.recipient.name(),
|
||||
);
|
||||
|
||||
consolex.log(
|
||||
@@ -72,27 +77,8 @@ export class QuickChatExecution implements Execution {
|
||||
private getMessageFromKey(
|
||||
fullKey: string,
|
||||
vars: Record<string, string>,
|
||||
): string {
|
||||
// Key for translation
|
||||
const [category, key] = fullKey.split(".");
|
||||
const phrases = quickChatData[category];
|
||||
|
||||
if (!phrases) {
|
||||
consolex.warn(`QuickChat: Unknown category '${category}'`);
|
||||
return `[${fullKey}]`;
|
||||
}
|
||||
|
||||
const phraseObj = phrases.find((p) => p.key === key);
|
||||
if (!phraseObj) {
|
||||
consolex.warn(
|
||||
`QuickChat: Key '${key}' not found in category '${category}'`,
|
||||
);
|
||||
return `[${fullKey}]`;
|
||||
}
|
||||
|
||||
return phraseObj.text.replace(
|
||||
/\[(\w+)\]/g,
|
||||
(_, p1) => vars[p1] || `[${p1}]`,
|
||||
);
|
||||
): string[] {
|
||||
const translated = fullKey.split(".");
|
||||
return translated;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user