Skip to content

Commit 0379397

Browse files
itsnobiiDarkViewsommersdev
authored
Move toast to function as event data rather than tools data (#20)
* implement timeout counters for each team * Change timeout to only deduct at the end of the timer, update to check `timeoutState.timeRemaining` rather than creating new timeouts * remove redundant new timeout creation from connector * add timeouts back to websocketOutgoing and properly account for manually ending timeouts * Add live toast data * Move toast to function as an event rather than tools data * fix Types, re add swap sites * add toastInfo.title like in the Spectra client * Move TOAST to mid-match data again --------- Co-authored-by: Dunkel <7890309+DarkView@users.noreply.github.com> Co-authored-by: Paul Sommer <paul@sommers.dev>
1 parent 0441979 commit 0379397

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

src/model/Match.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
IFormattedRoundInfo,
1111
IFormattedScore,
1212
IFormattedScoreboard,
13+
IToastInfo,
1314
} from "./eventData";
1415
import logging from "../util/Logging";
1516
import { ReplayLogging } from "../util/ReplayLogging";
@@ -53,6 +54,14 @@ export class Match {
5354
private timeoutGracePeriodPassed: boolean = false;
5455

5556
private toastEndTimeout: any = undefined;
57+
private toastInfo: IToastInfo = {
58+
active: false,
59+
title: "",
60+
message: "",
61+
duration: null,
62+
eventLogoEnabled: true,
63+
selectedTeam: undefined,
64+
};
5665

5766
private hasEnteredOvertime: boolean = false;
5867

@@ -360,7 +369,7 @@ export class Match {
360369
break;
361370

362371
case DataTypes.TOAST:
363-
this.handleToast();
372+
this.handleToast(data.data as IToastInfo);
364373
break;
365374
case DataTypes.SWAP_A_D:
366375
this.handleSwapAD();
@@ -503,23 +512,24 @@ export class Match {
503512
this.spikeDetonationTime = timestamp + 45 * 1000; // Add 45 seconds to the current time
504513
}
505514

506-
private handleToast() {
507-
if (this.tools.toastInfo.active) {
515+
private handleToast(data: IToastInfo) {
516+
if (this.toastInfo.active) {
508517
// Toast is active — deactivate it immediately
509-
this.tools.toastInfo.active = false;
518+
this.toastInfo.active = false;
510519
clearTimeout(this.toastEndTimeout);
511520
this.toastEndTimeout = undefined;
512521
} else {
513-
// Activate the toast
514-
this.tools.toastInfo.active = true;
522+
// Activate the toast with data from the event
523+
this.toastInfo = data;
524+
this.toastInfo.active = true;
515525

516-
if (this.tools.toastInfo.duration !== null) {
526+
if (this.toastInfo.duration !== null) {
517527
// Auto-deactivate after the configured duration (ms)
518528
this.toastEndTimeout = setTimeout(() => {
519-
this.tools.toastInfo.active = false;
529+
this.toastInfo.active = false;
520530
this.toastEndTimeout = undefined;
521531
this.eventNumber++;
522-
}, this.tools.toastInfo.duration);
532+
}, this.toastInfo.duration);
523533
}
524534
// If duration is null, the toast stays until the hotkey is pressed again
525535
}

src/model/ToolsData.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ export class ToolsData {
4646
type: "disabled",
4747
sponsors: [],
4848
};
49-
public toastInfo: IToastInfo = {
50-
duration: null,
51-
message: "",
52-
eventLogoEnabled: true,
53-
selectedTeam: undefined,
54-
active: false,
55-
};
5649

5750
public constructor(init?: Partial<ToolsData>) {
5851
Object.assign(this, init);

src/model/eventData.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface IAuthedData {
6262
| IFormattedRoundInfo
6363
| IFormattedScore
6464
| IFormattedAuxiliary
65+
| IToastInfo
6566
| boolean
6667
| string
6768
| number;
@@ -200,6 +201,15 @@ export function isAuthedData(data: object): data is IAuthedData | IAuthedAuxData
200201
return false;
201202
}
202203

204+
export type IToastInfo = {
205+
duration: number | null;
206+
title: string;
207+
message: string;
208+
eventLogoEnabled: boolean;
209+
selectedTeam?: "left" | "right" | "none";
210+
active: boolean;
211+
};
212+
203213
//#region Preview
204214
export interface IPreviewData {
205215
type: DataTypes.PREVIEW;

src/replay/ReplayConnectorService.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ export class ReplayConnectorService {
137137
type: "tournamentInfo",
138138
sponsors: [],
139139
},
140-
toastInfo: {
141-
duration: null,
142-
message: "",
143-
eventLogoEnabled: false,
144-
active: false,
145-
},
146140
timeoutCounter: {
147141
max: 2,
148142
left: 2,

0 commit comments

Comments
 (0)