Skip to content

Commit 0dd95a4

Browse files
CopilotFoorack
andcommitted
Rename leaveLobby to gameStop and remove non-essential comments
- Renamed property from leaveLobby to gameStop to minimize diff from original - Removed verbose comments to keep only essential ones - Maintains same functionality with cleaner code Co-authored-by: Foorack <5008081+Foorack@users.noreply.github.com>
1 parent 3b5fc24 commit 0dd95a4

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/client/ClientGameRunner.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export function joinLobby(
7878

7979
const transport = new Transport(lobbyConfig, eventBus);
8080

81-
// Track the current game runner locally within this closure
8281
let currentGameRunner: ClientGameRunner | null = null;
8382

8483
const onconnect = () => {
@@ -134,14 +133,13 @@ export function joinLobby(
134133
};
135134
transport.connect(onconnect, onmessage);
136135
return () => {
137-
// Check if we should prevent closing (player is still alive in game)
138136
if (currentGameRunner && currentGameRunner.shouldPreventWindowClose()) {
139-
return false; // Don't close, return false to indicate prevented
137+
return false;
140138
}
141139
console.log("leaving game");
142140
currentGameRunner = null;
143141
transport.leaveGame();
144-
return true; // Successfully closed, return true
142+
return true;
145143
};
146144
}
147145

src/client/Main.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface JoinLobbyEvent {
8080
}
8181

8282
class Client {
83-
private leaveLobby: (() => boolean) | null = null;
83+
private gameStop: (() => boolean) | null = null;
8484
private eventBus: EventBus = new EventBus();
8585

8686
private usernameInput: UsernameInput | null = null;
@@ -154,13 +154,10 @@ class Client {
154154
this.publicLobby = document.querySelector("public-lobby") as PublicLobby;
155155

156156
window.addEventListener("beforeunload", (e) => {
157-
// Try to leave the lobby/game
158-
if (this.leaveLobby && !this.leaveLobby()) {
159-
// If leaveLobby returns false, it means we should prevent unload
157+
if (this.gameStop && !this.gameStop()) {
160158
e.preventDefault();
161159
return "";
162160
}
163-
// Successfully closed or no game running
164161
console.log("Browser is closing");
165162
});
166163

@@ -381,7 +378,7 @@ class Client {
381378
const onHashUpdate = () => {
382379
// Reset the UI to its initial state
383380
this.joinModal.close();
384-
if (this.leaveLobby !== null) {
381+
if (this.gameStop !== null) {
385382
this.handleLeaveLobby();
386383
}
387384

@@ -502,13 +499,13 @@ class Client {
502499
private async handleJoinLobby(event: CustomEvent<JoinLobbyEvent>) {
503500
const lobby = event.detail;
504501
console.log(`joining lobby ${lobby.gameID}`);
505-
if (this.leaveLobby !== null) {
502+
if (this.gameStop !== null) {
506503
console.log("joining lobby, stopping existing game");
507-
this.leaveLobby();
504+
this.gameStop();
508505
}
509506
const config = await getServerConfigFromClient();
510507

511-
this.leaveLobby = joinLobby(
508+
this.gameStop = joinLobby(
512509
this.eventBus,
513510
{
514511
gameID: lobby.gameID,
@@ -594,12 +591,12 @@ class Client {
594591
}
595592

596593
private async handleLeaveLobby(/* event: CustomEvent */) {
597-
if (this.leaveLobby === null) {
594+
if (this.gameStop === null) {
598595
return;
599596
}
600597
console.log("leaving lobby, cancelling game");
601-
this.leaveLobby();
602-
this.leaveLobby = null;
598+
this.gameStop();
599+
this.gameStop = null;
603600
this.publicLobby.leaveLobby();
604601
}
605602

0 commit comments

Comments
 (0)