diff --git a/src/model/Match.ts b/src/model/Match.ts index 6afd166..40d4fe7 100644 --- a/src/model/Match.ts +++ b/src/model/Match.ts @@ -10,6 +10,7 @@ import { IFormattedRoundInfo, IFormattedScore, IFormattedScoreboard, + IToastInfo, } from "./eventData"; import logging from "../util/Logging"; import { ReplayLogging } from "../util/ReplayLogging"; @@ -53,6 +54,14 @@ export class Match { private timeoutGracePeriodPassed: boolean = false; private toastEndTimeout: any = undefined; + private toastInfo: IToastInfo = { + active: false, + title: "", + message: "", + duration: null, + eventLogoEnabled: true, + selectedTeam: undefined, + }; private hasEnteredOvertime: boolean = false; @@ -360,7 +369,7 @@ export class Match { break; case DataTypes.TOAST: - this.handleToast(); + this.handleToast(data.data as IToastInfo); break; case DataTypes.SWAP_A_D: this.handleSwapAD(); @@ -503,23 +512,24 @@ export class Match { this.spikeDetonationTime = timestamp + 45 * 1000; // Add 45 seconds to the current time } - private handleToast() { - if (this.tools.toastInfo.active) { + private handleToast(data: IToastInfo) { + if (this.toastInfo.active) { // Toast is active — deactivate it immediately - this.tools.toastInfo.active = false; + this.toastInfo.active = false; clearTimeout(this.toastEndTimeout); this.toastEndTimeout = undefined; } else { - // Activate the toast - this.tools.toastInfo.active = true; + // Activate the toast with data from the event + this.toastInfo = data; + this.toastInfo.active = true; - if (this.tools.toastInfo.duration !== null) { + if (this.toastInfo.duration !== null) { // Auto-deactivate after the configured duration (ms) this.toastEndTimeout = setTimeout(() => { - this.tools.toastInfo.active = false; + this.toastInfo.active = false; this.toastEndTimeout = undefined; this.eventNumber++; - }, this.tools.toastInfo.duration); + }, this.toastInfo.duration); } // If duration is null, the toast stays until the hotkey is pressed again } diff --git a/src/model/ToolsData.ts b/src/model/ToolsData.ts index 9ee8452..347d252 100644 --- a/src/model/ToolsData.ts +++ b/src/model/ToolsData.ts @@ -46,13 +46,6 @@ export class ToolsData { type: "disabled", sponsors: [], }; - public toastInfo: IToastInfo = { - duration: null, - message: "", - eventLogoEnabled: true, - selectedTeam: undefined, - active: false, - }; public constructor(init?: Partial) { Object.assign(this, init); diff --git a/src/model/eventData.ts b/src/model/eventData.ts index 1f6623c..c18fe62 100644 --- a/src/model/eventData.ts +++ b/src/model/eventData.ts @@ -62,6 +62,7 @@ export interface IAuthedData { | IFormattedRoundInfo | IFormattedScore | IFormattedAuxiliary + | IToastInfo | boolean | string | number; @@ -200,6 +201,15 @@ export function isAuthedData(data: object): data is IAuthedData | IAuthedAuxData return false; } +export type IToastInfo = { + duration: number | null; + title: string; + message: string; + eventLogoEnabled: boolean; + selectedTeam?: "left" | "right" | "none"; + active: boolean; +}; + //#region Preview export interface IPreviewData { type: DataTypes.PREVIEW; diff --git a/src/replay/ReplayConnectorService.ts b/src/replay/ReplayConnectorService.ts index 9da9765..16eaee9 100644 --- a/src/replay/ReplayConnectorService.ts +++ b/src/replay/ReplayConnectorService.ts @@ -137,12 +137,6 @@ export class ReplayConnectorService { type: "tournamentInfo", sponsors: [], }, - toastInfo: { - duration: null, - message: "", - eventLogoEnabled: false, - active: false, - }, timeoutCounter: { max: 2, left: 2,