ds4/src/documents/chat-message.js

32 lines
956 B
JavaScript
Raw Normal View History

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
2022-11-04 21:47:18 +01:00
import { getGame } from "../utils/utils";
/**
* @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
*/
export class DS4ChatMessage extends ChatMessage {
prepareData() {
super.prepareData();
2022-11-21 03:00:46 +01:00
if (this.flavor) {
const game = getGame();
const flavorData = Object.fromEntries(
2022-11-21 03:00:46 +01:00
Object.entries(this.flags.ds4?.flavorData ?? {}).map(([key, value]) => [
key,
typeof value === "string" ? game.i18n.localize(value) : value,
]),
);
2022-11-21 03:00:46 +01:00
this.flavor = game.i18n.format(this.flavor, flavorData);
}
}
}