2021-09-19 12:23:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-11-04 21:47:18 +01:00
|
|
|
import { getGame } from "../utils/utils";
|
2021-09-19 12:23:52 +02:00
|
|
|
|
2022-11-17 00:12:29 +01:00
|
|
|
/**
|
|
|
|
* @typedef {object} DS4ChatMessageFlags
|
|
|
|
* @property {Record<string, string | number | null>} [flavorData] Data to use for localizing the flavor of the chat message
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Record<string, unknown>} ChatMessageFlags
|
|
|
|
* @property {DS4ChatMessageFlags} [ds4] Flags for DS4
|
|
|
|
*/
|
2021-09-19 12:23:52 +02:00
|
|
|
|
|
|
|
export class DS4ChatMessage extends ChatMessage {
|
2023-07-10 22:23:13 +02:00
|
|
|
prepareData() {
|
|
|
|
super.prepareData();
|
|
|
|
if (this.flavor) {
|
|
|
|
const game = getGame();
|
|
|
|
const flavorData = Object.fromEntries(
|
|
|
|
Object.entries(this.flags.ds4?.flavorData ?? {}).map(([key, value]) => [
|
|
|
|
key,
|
|
|
|
typeof value === "string" ? game.i18n.localize(value) : value,
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
this.flavor = game.i18n.format(this.flavor, flavorData);
|
2021-09-19 12:23:52 +02:00
|
|
|
}
|
2023-07-10 22:23:13 +02:00
|
|
|
}
|
2021-09-19 12:23:52 +02:00
|
|
|
}
|