Skip to content

Commit c597180

Browse files
author
Otto Andelin
committed
last fixes and removing comments/console.logs
1 parent 8c97063 commit c597180

File tree

8 files changed

+31
-54
lines changed

8 files changed

+31
-54
lines changed

Frontend/src/js/createModal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function createModal(modalId, modalTitle, content) {
6464
});
6565

6666
document.addEventListener('keydown', function (event) {
67-
if (event.key === "Escape" || event.keyCode === 27) {
67+
if (event.key === "Escape") {
6868
modalElement.hide();
6969
}
7070
});

Frontend/src/js/modals/friends.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export function updateFriendsList() {
2525
})
2626
.then(response => {
2727
if (!response.ok) {
28-
console.log("friends.js: response not ok");
2928
throw new Error('Network response was not ok');
3029
}
3130
return response.json();

Frontend/src/js/modals/playonline.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as bootstrap from 'bootstrap';
22
import { startGame } from '../pong/pong';
33
import { handleTokenVerification } from '../tokenHandler';
4-
4+
import { showMessage } from './messages';
55
const pongModalElement = document.getElementById('pongModal');
66
const waitingLobbyModalElement = document.getElementById('waitingLobbyModal');
77
const waitingLobbyModalLabel = document.getElementById('waitingLobbyModalLabel');
@@ -72,7 +72,10 @@ function connectToWebSockets() {
7272
};
7373

7474
onlineStatusSocket.onerror = function(error) {
75-
waitingLobbyModal.hide();
75+
showMessage("An error occured while connecting to matchmaking", waitingLobbyModal, error)
76+
setTimeout(() => {
77+
waitingLobbyModal.hide();
78+
}, 2500);
7679
};
7780

7881
function connectToGameRoom(roomName) {
@@ -117,7 +120,10 @@ function connectToWebSockets() {
117120
};
118121

119122
gameRoomSocket.onerror = function(error) {
120-
waitingLobbyModal.hide();
123+
showMessage("An error occured while connecting to matchmaking", waitingLobbyModal, error)
124+
setTimeout(() => {
125+
waitingLobbyModal.hide();
126+
}, 2500);
121127
};
122128
}
123129
)}
@@ -132,8 +138,10 @@ function connectToWebSockets() {
132138
});
133139
})
134140
.catch(error => {
135-
console.error('Error verifying token:', error);
136-
});
141+
showMessage("Error verifying token", waitingLobbyModal, error)
142+
setTimeout(() => {
143+
waitingLobbyModal.hide();
144+
}, 2500);});
137145

138146
}
139147

Frontend/src/js/modals/quitConfirmation.js

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export function initializeConfirmationModal(modalId, title, message) {
4444
// function to bypass the confirmation modal
4545
return function bypassConfirmationModal() {
4646
bypassConfirmation = true;
47-
console.log("bypassconfirmationmodal changed to true")
4847
const modal = bootstrap.Modal.getInstance(document.getElementById(modalId));
4948
modal.hide();
5049
};

Frontend/src/js/modals/tournament.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ document.addEventListener('DOMContentLoaded', async () => {
3535
}
3636

3737
// tournamentStages || 0 = reset || 1 = before first game || 2 = all other games except final || 3 = final
38-
if(parseInt(sessionStorage.getItem('tournamentStages'))) // TESTI
38+
if(parseInt(sessionStorage.getItem('tournamentStages')))
3939
tournamentLogic();
40-
// else
41-
// sessionStorage.setItem('tournamentStages', '0');
4240

4341
function resetTournament() {
4442
sessionStorage.setItem('isGameOver', 'true');
@@ -72,13 +70,13 @@ document.addEventListener('DOMContentLoaded', async () => {
7270
startTournamentButton.style.display = 'none';
7371

7472
document.getElementById('tournamentModal').addEventListener('keydown', function(event){
75-
if (event.key === "Escape" || event.keyCode === 27) {
73+
if (event.key === "Escape") {
7674
sessionStorage.setItem('gameQuit', 'true');
7775
}
7876
});
7977

8078
document.getElementById('gameInfoModal').addEventListener('keydown', function(event){
81-
if (event.key === "Escape" || event.keyCode === 27) {
79+
if (event.key === "Escape") {
8280
sessionStorage.setItem('gameQuit', 'true');
8381
}
8482
});

Frontend/src/js/pong/eventhandlers.js

+4-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const initializeEventHandlers = (gameSession) => {
1111
// Event handler for the socket connection
1212
socket.on('connect', () => {
1313
isConnected = true;
14-
console.log('Connected to server');
1514
});
1615

1716
// Event handler for the socket disconnection
@@ -28,11 +27,7 @@ export const initializeEventHandlers = (gameSession) => {
2827
if (data && data.gameId) {
2928
if (data.gameId === gameSession.gameId) {
3029
gameSession.handleGameStart();
31-
} else {
32-
console.warn(`Received game start for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
33-
}
34-
} else {
35-
console.error('Received malformed game_start data:', data);
30+
}
3631
}
3732
} catch (error) {
3833
console.error('Error handling game_start:', error);
@@ -50,11 +45,7 @@ export const initializeEventHandlers = (gameSession) => {
5045
if (data && data.gameId) {
5146
if (data.gameId === gameSession.gameId) {
5247
gameSession.handleGameStateUpdate(data);
53-
} else {
54-
console.warn(`Received game state for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
5548
}
56-
} else {
57-
console.error('Received malformed send_game_state data:', data);
5849
}
5950
} catch (error) {
6051
console.error('Error handling send_game_state:', error);
@@ -67,11 +58,7 @@ export const initializeEventHandlers = (gameSession) => {
6758
if (data && data.gameId) {
6859
if (data.gameId === gameSession.gameId) {
6960
gameSession.handleScoreUpdate(data);
70-
} else {
71-
console.warn(`Received score update for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
7261
}
73-
} else {
74-
console.error('Received malformed score data:', data);
7562
}
7663
} catch (error) {
7764
console.error('Error handling score update:', error);
@@ -85,11 +72,7 @@ export const initializeEventHandlers = (gameSession) => {
8572
if (data.gameId === gameSession.gameId && gameSession.inProgress) {
8673
console.info(`Player ${data.quittingPlayerId} has quit the game.`);
8774
gameSession.handleOpponentQuit(data);
88-
} else {
89-
console.warn(`Received quit game for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
90-
}
91-
} else {
92-
console.error('Received malformed quit_game data:', data);
75+
}
9376
}
9477
} catch (error) {
9578
console.error('Error handling quit_game:', error);
@@ -102,16 +85,11 @@ export const initializeEventHandlers = (gameSession) => {
10285
if (data && data.gameId) {
10386
if (data.gameId === gameSession.gameId) {
10487
gameSession.inProgress = false;
105-
console.info(`Game ${data.gameId} has been cancelled.`);
10688
gameSession.handleCancelGame(data);
10789
setTimeout(() => {
10890
endGame();
10991
}, 2000);
110-
} else {
111-
console.warn(`Received cancel game for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
112-
}
113-
} else {
114-
console.error('Received malformed cancel_game data:', data);
92+
}
11593
}
11694
} catch (error) {
11795
console.error('Error handling cancel_game:', error);
@@ -124,11 +102,7 @@ export const initializeEventHandlers = (gameSession) => {
124102
if (data && data.game_id) {
125103
if (data.gameId === gameSession.game_id) {
126104
gameSession.handleGameOver(data);
127-
} else {
128-
console.warn(`Received game over for different game, was ${data.game_id}, expected ${gameSession.gameId}`);
129-
}
130-
} else {
131-
console.error('Received malformed game_over data:', data);
105+
}
132106
}
133107
} catch (error) {
134108
console.error('Error handling game_over:', error);
@@ -179,7 +153,6 @@ export const cleanupEventHandlers = () => {
179153
socket.off('cancel_game');
180154
socket.off('error');
181155
socket.off('invalid_token');
182-
socket.off('game_defaults')
183156
if (beforeUnloadHandler) {
184157
window.removeEventListener('beforeunload', beforeUnloadHandler);
185158
beforeUnloadHandler = null; // Clear the handler reference

Frontend/src/js/pong/init.js

-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export function init(canvas) {
4040
// Create composer for postprocessing
4141
const composer = new EffectComposer( renderer );
4242
// composer.addPass(new OutputPass());
43-
console.log(scene)
4443
// Initialize the scene
4544
initializeScene(renderer, scene, camera, composer);
4645

@@ -64,8 +63,6 @@ function initComposer (renderer, composer, scene, camera) {
6463
const scanlinePass = new ShaderPass(scanlineShader);
6564
scanlinePass.enabled = true;
6665
composer.addPass(scanlinePass);
67-
// const filmPass = new FilmPass( 0.9, .2, 900, false );
68-
// composer.addPass( filmPass );
6966

7067
const outputPass = new OutputPass();
7168
composer.addPass( outputPass );

Game_server/server.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,16 @@ async def send_game_state_to_client(self):
159159
# The game over message is sent to the clients with the game stats
160160
async def end_game(self):
161161
self.game_state.in_progress = False
162-
if self.game_loop_task and not self.game_loop_task.done():
163-
self.game_loop_task.cancel()
164-
try:
165-
await self.game_loop_task # Await to handle cancellation gracefully
166-
except asyncio.CancelledError:
167-
logging.info(f"Game loop for game {self.game_state.game_id} was cancelled.")
168-
162+
if self.game_loop_task is not None:
163+
if not self.game_loop_task.done():
164+
self.game_loop_task.cancel()
165+
try:
166+
await self.game_loop_task # Await to handle cancellation gracefully
167+
except asyncio.CancelledError:
168+
logging.info(f"Game loop for game {self.game_state.game_id} was cancelled.")
169+
else:
170+
logging.warning("Game loop task is None; cannot await a non-existent task.")
171+
169172
if self.game_state.player1.score > self.game_state.player2.score:
170173
winner = self.game_state.player1.id
171174
else:

0 commit comments

Comments
 (0)