diff --git a/src/connector/websocketOutgoing.ts b/src/connector/websocketOutgoing.ts index 9c3a522..979c28f 100644 --- a/src/connector/websocketOutgoing.ts +++ b/src/connector/websocketOutgoing.ts @@ -98,9 +98,11 @@ export class WebsocketOutgoing { timeoutEndTimeout, // eslint-disable-next-line @typescript-eslint/no-unused-vars timeoutRemainingLoop, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + toastEndTimeout, ...formattedData - } = data; + } = data; const deepMod: any = structuredClone(formattedData); if ( diff --git a/src/model/Match.ts b/src/model/Match.ts index c31e633..12e6daa 100644 --- a/src/model/Match.ts +++ b/src/model/Match.ts @@ -52,6 +52,8 @@ export class Match { private timeoutRemainingLoop: any = undefined; private timeoutGracePeriodPassed: boolean = false; + private toastEndTimeout: any = undefined; + private hasEnteredOvertime: boolean = false; private tools: ToolsData; @@ -346,6 +348,10 @@ export class Match { case DataTypes.SWITCH_KDA_CREDITS: this.showAliveKDA = !this.showAliveKDA; break; + + case DataTypes.TOAST: + this.handleToast(); + break; } this.eventNumber++; @@ -481,6 +487,28 @@ export class Match { this.spikeDetonationTime = timestamp + 45 * 1000; // Add 45 seconds to the current time } + private handleToast() { + if (this.tools.toastInfo.active) { + // Toast is active — deactivate it immediately + this.tools.toastInfo.active = false; + clearTimeout(this.toastEndTimeout); + this.toastEndTimeout = undefined; + } else { + // Activate the toast + this.tools.toastInfo.active = true; + + if (this.tools.toastInfo.duration !== null) { + // Auto-deactivate after the configured duration (ms) + this.toastEndTimeout = setTimeout(() => { + this.tools.toastInfo.active = false; + this.toastEndTimeout = undefined; + this.eventNumber++; + }, this.tools.toastInfo.duration); + } + // If duration is null, the toast stays until the hotkey is pressed again + } + } + private handleTeamTimeout(team: "left" | "right") { const isLeftTeam = team === "left"; const currentState = isLeftTeam ? this.timeoutState.leftTeam : this.timeoutState.rightTeam; diff --git a/src/model/ToolsData.ts b/src/model/ToolsData.ts index 045f079..60ded2b 100644 --- a/src/model/ToolsData.ts +++ b/src/model/ToolsData.ts @@ -46,6 +46,13 @@ 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); @@ -120,6 +127,14 @@ export type IOverridesPlayercamsData = { enabledPlayers: string[]; }; +export type IToastInfo = { + duration: number | null; + message: string; + eventLogoEnabled: boolean; + selectedTeam ?: "left" | "right"; + active: boolean; +}; + type BaseMapPoolInfo = { type: "past" | "present" | "future" | "disabled"; }; diff --git a/src/model/eventData.ts b/src/model/eventData.ts index 6e9c9ce..b7a37d1 100644 --- a/src/model/eventData.ts +++ b/src/model/eventData.ts @@ -180,6 +180,7 @@ export enum DataTypes { LEFT_TIMEOUT = "left_timeout", RIGHT_TIMEOUT = "right_timeout", SWITCH_KDA_CREDITS = "switch_kda_credits", + TOAST = "toast", // Preview data types PREVIEW = "preview", }