diff --git a/back/volume/src/pong/game/Game.ts b/back/volume/src/pong/game/Game.ts index 16db48c..46b3ed5 100644 --- a/back/volume/src/pong/game/Game.ts +++ b/back/volume/src/pong/game/Game.ts @@ -117,13 +117,26 @@ export class Game { } } - stop (): void { + stop (nameWhoLeft?: string): void { if (this.timer !== null) { clearInterval(this.timer) } + let nameWhoWon: string + if (this.players[0].score > this.players[1].score) { + nameWhoWon = this.players[0].name + } else { + nameWhoWon = this.players[1].name + } + if (nameWhoLeft !== undefined) { + this.players.forEach((p) => { + if (p.name !== nameWhoLeft) { + nameWhoWon = p.name + } + }) + } this.timer = null this.pongService - .saveResult(this.players, this.ranked, DEFAULT_WIN_SCORE) + .saveResult(this.players, this.ranked, nameWhoWon) .then(() => { this.gameStoppedCallback(this.players[0].name) this.players = [] diff --git a/back/volume/src/pong/pong.gateway.ts b/back/volume/src/pong/pong.gateway.ts index a215346..a02fee7 100644 --- a/back/volume/src/pong/pong.gateway.ts +++ b/back/volume/src/pong/pong.gateway.ts @@ -46,10 +46,10 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect { ): void { const name: string | undefined = this.socketToPlayerName.get(client) const game: Game | undefined = this.games.playerGame(name) - if (game !== undefined) { - game.stop() - } if (name !== undefined) { + if (game !== undefined) { + game.stop(name) + } console.log('Disconnected ', this.socketToPlayerName.get(client)) this.matchmakingQueue.removePlayer(name) this.socketToPlayerName.delete(client) @@ -66,7 +66,7 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect { ): Promise<{ event: string, data: boolean }> { let succeeded: boolean = false const user = await this.usersService.findUserByName(playerName.value) - console.log(socketKey.value, user?.socketKey) + // console.log(socketKey.value, user?.socketKey) if ( user !== null && user.socketKey === socketKey.value && diff --git a/back/volume/src/pong/pong.service.ts b/back/volume/src/pong/pong.service.ts index d64b78a..edadad5 100644 --- a/back/volume/src/pong/pong.service.ts +++ b/back/volume/src/pong/pong.service.ts @@ -17,12 +17,10 @@ export class PongService { async updateStats ( player: User, - i: number, - result: Result, - maxScore: number + nameWhoWon: string ): Promise { player.matchs++ - if (result.score[i] === maxScore) player.wins++ + if (player.username === nameWhoWon) player.wins++ else player.looses++ player.winrate = (100 * player.wins) / player.matchs } @@ -30,11 +28,11 @@ export class PongService { async updatePlayer ( i: number, result: Result, - maxScore: number + nameWhoWon: string ): Promise { const player: User | null = result.players[i] if (player == null) return - if (result.ranked) await this.updateStats(player, i, result, maxScore) + if (result.ranked) await this.updateStats(player, nameWhoWon) player.results.push(result) player.status = 'online' await this.usersService.save(player) @@ -49,7 +47,7 @@ export class PongService { async saveResult ( players: Player[], ranked: boolean, - maxScore: number + nameWhoWon: string ): Promise { const result = new Result() const ply = new Array() @@ -59,8 +57,8 @@ export class PongService { result.players = ply result.score = [players[0].score, players[1].score] await this.resultsRepository.save(result) - await this.updatePlayer(0, result, maxScore) - await this.updatePlayer(1, result, maxScore) + await this.updatePlayer(0, result, nameWhoWon) + await this.updatePlayer(1, result, nameWhoWon) } async getHistory ( diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 4324add..8ab0fa2 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -172,6 +172,7 @@ // GAME let pong: Pong; + let gamePlaying: boolean = false; // FAKE LOGIN let usernameFake = "test"; @@ -260,7 +261,7 @@ {/if} {#if appState === APPSTATE.PROFILE}
- setAppState(APPSTATE.HISTORY_ID)} /> + setAppState(APPSTATE.HISTORY_ID)} />
{/if} {#if appState === APPSTATE.PROFILE_ID} @@ -271,6 +272,7 @@ setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)} > setAppState(APPSTATE.HISTORY_ID)} /> @@ -282,7 +284,7 @@ {:else} - + {/if} {/if} diff --git a/front/volume/src/components/Alert/Alert.svelte b/front/volume/src/components/Alert/Alert.svelte index 96211b9..35f69a6 100644 --- a/front/volume/src/components/Alert/Alert.svelte +++ b/front/volume/src/components/Alert/Alert.svelte @@ -1,65 +1,58 @@ - +
+

{message}

+ {#if form === true} + e.which === 13 && _onOkay()} + /> + {/if} + +
+ + +
+
+ + font-size: 2rem; + text-align: center; + } -

{message}

-{#if form === true} - e.which === 13 && _onOkay()} /> -{/if} + input { + width: 100%; + } -
- - -
\ No newline at end of file + .buttons { + display: flex; + justify-content: space-between; + } + diff --git a/front/volume/src/components/Friends.svelte b/front/volume/src/components/Friends.svelte index 5568d87..65e0656 100644 --- a/front/volume/src/components/Friends.svelte +++ b/front/volume/src/components/Friends.svelte @@ -108,7 +108,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center; diff --git a/front/volume/src/components/Leaderboard.svelte b/front/volume/src/components/Leaderboard.svelte index b1bd652..eb4c0ea 100644 --- a/front/volume/src/components/Leaderboard.svelte +++ b/front/volume/src/components/Leaderboard.svelte @@ -60,7 +60,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center; diff --git a/front/volume/src/components/MatchHistory.svelte b/front/volume/src/components/MatchHistory.svelte index b7c9445..91832a8 100644 --- a/front/volume/src/components/MatchHistory.svelte +++ b/front/volume/src/components/MatchHistory.svelte @@ -110,7 +110,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center; diff --git a/front/volume/src/components/Pong/GameCreation.svelte b/front/volume/src/components/Pong/GameCreation.svelte index d977778..13c7600 100644 --- a/front/volume/src/components/Pong/GameCreation.svelte +++ b/front/volume/src/components/Pong/GameCreation.svelte @@ -67,7 +67,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center; diff --git a/front/volume/src/components/Pong/Matchmaking.svelte b/front/volume/src/components/Pong/Matchmaking.svelte index 66ce9be..a696a80 100644 --- a/front/volume/src/components/Pong/Matchmaking.svelte +++ b/front/volume/src/components/Pong/Matchmaking.svelte @@ -17,7 +17,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center; diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte index 5dd7d41..b7abeef 100644 --- a/front/volume/src/components/Pong/Pong.svelte +++ b/front/volume/src/components/Pong/Pong.svelte @@ -26,7 +26,7 @@ import.meta.env.VITE_BACK_PORT }`; - let gamePlaying: boolean = false; + export let gamePlaying: boolean; let connected: boolean = false; let loggedIn: boolean = false; let failedLogIn: boolean = false; diff --git a/front/volume/src/components/Profile.svelte b/front/volume/src/components/Profile.svelte index 5d77f2d..b41c458 100644 --- a/front/volume/src/components/Profile.svelte +++ b/front/volume/src/components/Profile.svelte @@ -7,14 +7,19 @@ winrate: number; rank: number; twoFA: boolean; + ftId: number; } @@ -136,7 +149,7 @@ width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); - z-index: 9998; + z-index: 50; display: flex; justify-content: center; align-items: center;