Skip to content

Commit

Permalink
last fixes and removing comments/console.logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto Andelin committed Aug 27, 2024
1 parent 8c97063 commit c597180
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Frontend/src/js/createModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function createModal(modalId, modalTitle, content) {
});

document.addEventListener('keydown', function (event) {
if (event.key === "Escape" || event.keyCode === 27) {
if (event.key === "Escape") {
modalElement.hide();
}
});
Expand Down
1 change: 0 additions & 1 deletion Frontend/src/js/modals/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function updateFriendsList() {
})
.then(response => {
if (!response.ok) {
console.log("friends.js: response not ok");
throw new Error('Network response was not ok');
}
return response.json();
Expand Down
18 changes: 13 additions & 5 deletions Frontend/src/js/modals/playonline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bootstrap from 'bootstrap';
import { startGame } from '../pong/pong';
import { handleTokenVerification } from '../tokenHandler';

import { showMessage } from './messages';
const pongModalElement = document.getElementById('pongModal');
const waitingLobbyModalElement = document.getElementById('waitingLobbyModal');
const waitingLobbyModalLabel = document.getElementById('waitingLobbyModalLabel');
Expand Down Expand Up @@ -72,7 +72,10 @@ function connectToWebSockets() {
};

onlineStatusSocket.onerror = function(error) {
waitingLobbyModal.hide();
showMessage("An error occured while connecting to matchmaking", waitingLobbyModal, error)
setTimeout(() => {
waitingLobbyModal.hide();
}, 2500);
};

function connectToGameRoom(roomName) {
Expand Down Expand Up @@ -117,7 +120,10 @@ function connectToWebSockets() {
};

gameRoomSocket.onerror = function(error) {
waitingLobbyModal.hide();
showMessage("An error occured while connecting to matchmaking", waitingLobbyModal, error)
setTimeout(() => {
waitingLobbyModal.hide();
}, 2500);
};
}
)}
Expand All @@ -132,8 +138,10 @@ function connectToWebSockets() {
});
})
.catch(error => {
console.error('Error verifying token:', error);
});
showMessage("Error verifying token", waitingLobbyModal, error)
setTimeout(() => {
waitingLobbyModal.hide();
}, 2500);});

}

Expand Down
1 change: 0 additions & 1 deletion Frontend/src/js/modals/quitConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function initializeConfirmationModal(modalId, title, message) {
// function to bypass the confirmation modal
return function bypassConfirmationModal() {
bypassConfirmation = true;
console.log("bypassconfirmationmodal changed to true")
const modal = bootstrap.Modal.getInstance(document.getElementById(modalId));
modal.hide();
};
Expand Down
8 changes: 3 additions & 5 deletions Frontend/src/js/modals/tournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ document.addEventListener('DOMContentLoaded', async () => {
}

// tournamentStages || 0 = reset || 1 = before first game || 2 = all other games except final || 3 = final
if(parseInt(sessionStorage.getItem('tournamentStages'))) // TESTI
if(parseInt(sessionStorage.getItem('tournamentStages')))
tournamentLogic();
// else
// sessionStorage.setItem('tournamentStages', '0');

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

document.getElementById('tournamentModal').addEventListener('keydown', function(event){
if (event.key === "Escape" || event.keyCode === 27) {
if (event.key === "Escape") {
sessionStorage.setItem('gameQuit', 'true');
}
});

document.getElementById('gameInfoModal').addEventListener('keydown', function(event){
if (event.key === "Escape" || event.keyCode === 27) {
if (event.key === "Escape") {
sessionStorage.setItem('gameQuit', 'true');
}
});
Expand Down
35 changes: 4 additions & 31 deletions Frontend/src/js/pong/eventhandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const initializeEventHandlers = (gameSession) => {
// Event handler for the socket connection
socket.on('connect', () => {
isConnected = true;
console.log('Connected to server');
});

// Event handler for the socket disconnection
Expand All @@ -28,11 +27,7 @@ export const initializeEventHandlers = (gameSession) => {
if (data && data.gameId) {
if (data.gameId === gameSession.gameId) {
gameSession.handleGameStart();
} else {
console.warn(`Received game start for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed game_start data:', data);
}
}
} catch (error) {
console.error('Error handling game_start:', error);
Expand All @@ -50,11 +45,7 @@ export const initializeEventHandlers = (gameSession) => {
if (data && data.gameId) {
if (data.gameId === gameSession.gameId) {
gameSession.handleGameStateUpdate(data);
} else {
console.warn(`Received game state for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed send_game_state data:', data);
}
} catch (error) {
console.error('Error handling send_game_state:', error);
Expand All @@ -67,11 +58,7 @@ export const initializeEventHandlers = (gameSession) => {
if (data && data.gameId) {
if (data.gameId === gameSession.gameId) {
gameSession.handleScoreUpdate(data);
} else {
console.warn(`Received score update for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed score data:', data);
}
} catch (error) {
console.error('Error handling score update:', error);
Expand All @@ -85,11 +72,7 @@ export const initializeEventHandlers = (gameSession) => {
if (data.gameId === gameSession.gameId && gameSession.inProgress) {
console.info(`Player ${data.quittingPlayerId} has quit the game.`);
gameSession.handleOpponentQuit(data);
} else {
console.warn(`Received quit game for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed quit_game data:', data);
}
}
} catch (error) {
console.error('Error handling quit_game:', error);
Expand All @@ -102,16 +85,11 @@ export const initializeEventHandlers = (gameSession) => {
if (data && data.gameId) {
if (data.gameId === gameSession.gameId) {
gameSession.inProgress = false;
console.info(`Game ${data.gameId} has been cancelled.`);
gameSession.handleCancelGame(data);
setTimeout(() => {
endGame();
}, 2000);
} else {
console.warn(`Received cancel game for different game, was ${data.gameId}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed cancel_game data:', data);
}
}
} catch (error) {
console.error('Error handling cancel_game:', error);
Expand All @@ -124,11 +102,7 @@ export const initializeEventHandlers = (gameSession) => {
if (data && data.game_id) {
if (data.gameId === gameSession.game_id) {
gameSession.handleGameOver(data);
} else {
console.warn(`Received game over for different game, was ${data.game_id}, expected ${gameSession.gameId}`);
}
} else {
console.error('Received malformed game_over data:', data);
}
}
} catch (error) {
console.error('Error handling game_over:', error);
Expand Down Expand Up @@ -179,7 +153,6 @@ export const cleanupEventHandlers = () => {
socket.off('cancel_game');
socket.off('error');
socket.off('invalid_token');
socket.off('game_defaults')
if (beforeUnloadHandler) {
window.removeEventListener('beforeunload', beforeUnloadHandler);
beforeUnloadHandler = null; // Clear the handler reference
Expand Down
3 changes: 0 additions & 3 deletions Frontend/src/js/pong/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function init(canvas) {
// Create composer for postprocessing
const composer = new EffectComposer( renderer );
// composer.addPass(new OutputPass());
console.log(scene)
// Initialize the scene
initializeScene(renderer, scene, camera, composer);

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

const outputPass = new OutputPass();
composer.addPass( outputPass );
Expand Down
17 changes: 10 additions & 7 deletions Game_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ async def send_game_state_to_client(self):
# The game over message is sent to the clients with the game stats
async def end_game(self):
self.game_state.in_progress = False
if self.game_loop_task and not self.game_loop_task.done():
self.game_loop_task.cancel()
try:
await self.game_loop_task # Await to handle cancellation gracefully
except asyncio.CancelledError:
logging.info(f"Game loop for game {self.game_state.game_id} was cancelled.")

if self.game_loop_task is not None:
if not self.game_loop_task.done():
self.game_loop_task.cancel()
try:
await self.game_loop_task # Await to handle cancellation gracefully
except asyncio.CancelledError:
logging.info(f"Game loop for game {self.game_state.game_id} was cancelled.")
else:
logging.warning("Game loop task is None; cannot await a non-existent task.")

if self.game_state.player1.score > self.game_state.player2.score:
winner = self.game_state.player1.id
else:
Expand Down

0 comments on commit c597180

Please sign in to comment.