ds4/src/chat-message.ts

31 lines
879 B
TypeScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { getGame } from "./helpers";
declare global {
interface FlagConfig {
ChatMessage: {
ds4?: {
flavorData?: Record<string, string | number | null>;
};
};
}
}
export class DS4ChatMessage extends ChatMessage {
override prepareData(): void {
super.prepareData();
if (this.data.flavor) {
const game = getGame();
const flavorData = Object.fromEntries(
Object.entries(this.data.flags.ds4?.flavorData ?? {}).map(([key, value]) => [
key,
typeof value === "string" ? game.i18n.localize(value) : value,
]),
);
this.data.flavor = game.i18n.format(this.data.flavor, flavorData);
}
}
}