From 87d1a00e961667c687ccda09ff201994a5074d82 Mon Sep 17 00:00:00 2001 From: vvandenb Date: Mon, 13 Mar 2023 10:46:50 +0100 Subject: [PATCH] * Removed spectate feature --- back/volume/src/pong/game/Game.ts | 10 ----- back/volume/src/pong/game/Games.ts | 17 ------- back/volume/src/pong/game/Spectator.ts | 13 ------ back/volume/src/pong/game/constants.ts | 1 - back/volume/src/pong/pong.gateway.ts | 15 ------- back/volume/src/users/entity/user.entity.ts | 2 +- front/volume/src/App.svelte | 2 - front/volume/src/components/NavBar.svelte | 1 - front/volume/src/components/Pong/Pong.svelte | 15 ------- .../src/components/Pong/SpectateFriend.svelte | 44 ------------------- front/volume/src/components/Pong/constants.ts | 1 - 11 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 back/volume/src/pong/game/Spectator.ts delete mode 100644 front/volume/src/components/Pong/SpectateFriend.svelte diff --git a/back/volume/src/pong/game/Game.ts b/back/volume/src/pong/game/Game.ts index 3a43c65..5d07d95 100644 --- a/back/volume/src/pong/game/Game.ts +++ b/back/volume/src/pong/game/Game.ts @@ -11,7 +11,6 @@ import { GAME_TICKS } from './constants' import { randomUUID } from 'crypto' -import { Spectator } from './Spectator' import { type MapDtoValidated } from '../dtos/MapDtoValidated' import { type GameUpdate } from '../dtos/GameUpdate' import { type GameInfo } from '../dtos/GameInfo' @@ -23,7 +22,6 @@ export class Game { map: MapDtoValidated ball: Ball players: Player[] = [] - spectators: Spectator[] = [] playing: boolean ranked: boolean gameStoppedCallback: (name: string) => void @@ -64,11 +62,6 @@ export class Game { } } - addSpectator (socket: WebSocket, uuid: string, name: string): void { - this.spectators.push(new Spectator(socket, uuid, name)) - console.log(`Added spectator ${name}`) - } - private addPlayer (socket: WebSocket, uuid: string, name: string): void { let paddleCoords = new Point(DEFAULT_PLAYER_X_OFFSET, this.map.size.y / 2) if (this.players.length === 1) { @@ -136,9 +129,6 @@ export class Game { this.players.forEach((p) => { p.socket.send(data) }) - this.spectators.forEach((s) => { - s.socket.send(data) - }) } isPlaying (): boolean { diff --git a/back/volume/src/pong/game/Games.ts b/back/volume/src/pong/game/Games.ts index 3a8bd87..8636e09 100644 --- a/back/volume/src/pong/game/Games.ts +++ b/back/volume/src/pong/game/Games.ts @@ -106,23 +106,6 @@ export class Games { return game } - spectateGame ( - nameToSpectate: string, - socket: WebSocket, - uuid: string, - name: string - ): boolean { - let succeeded: boolean = false - const gameIndex: number | undefined = - this.playerNameToGameIndex.get(nameToSpectate) - if (gameIndex !== undefined) { - this.playerNameToGameIndex.set(name, gameIndex) - this.games[gameIndex].addSpectator(socket, uuid, name) - succeeded = true - } - return succeeded - } - async leaveGame (name: string): Promise { const game: Game | undefined = this.playerGame(name) if (game !== undefined && !game.ranked) { diff --git a/back/volume/src/pong/game/Spectator.ts b/back/volume/src/pong/game/Spectator.ts deleted file mode 100644 index fae2c5b..0000000 --- a/back/volume/src/pong/game/Spectator.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { type WebSocket } from 'ws' - -export class Spectator { - socket: WebSocket - uuid: string - name: string - - constructor (socket: WebSocket, uuid: string, name: string) { - this.socket = socket - this.uuid = uuid - this.name = name - } -} diff --git a/back/volume/src/pong/game/constants.ts b/back/volume/src/pong/game/constants.ts index 6c7daba..87b07a6 100644 --- a/back/volume/src/pong/game/constants.ts +++ b/back/volume/src/pong/game/constants.ts @@ -8,7 +8,6 @@ export const GAME_EVENTS = { GET_GAME_INFO: 'GET_GAME_INFO', CREATE_GAME: 'CREATE_GAME', REGISTER_PLAYER: 'REGISTER_PLAYER', - SPECTATE: 'SPECTATE', MATCHMAKING: 'MATCHMAKING', LEAVE_GAME: 'LEAVE_GAME' } diff --git a/back/volume/src/pong/pong.gateway.ts b/back/volume/src/pong/pong.gateway.ts index cf1c451..6e45567 100644 --- a/back/volume/src/pong/pong.gateway.ts +++ b/back/volume/src/pong/pong.gateway.ts @@ -180,21 +180,6 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect { return { event: GAME_EVENTS.READY, data: succeeded } } - @UsePipes(new ValidationPipe({ whitelist: true })) - @SubscribeMessage(GAME_EVENTS.SPECTATE) - spectate ( - @ConnectedSocket() - client: WebSocketWithId, - @MessageBody() playerToSpectate: StringDtoValidated - ): { event: string, data: boolean } { - let succeeded: boolean = false - const name: string | undefined = this.socketToPlayerName.get(client) - if (name !== undefined) { - succeeded = this.games.spectateGame(playerToSpectate.value, client, client.id, name) - } - return { event: GAME_EVENTS.SPECTATE, data: succeeded } - } - @UsePipes(new ValidationPipe({ whitelist: true })) @SubscribeMessage(GAME_EVENTS.MATCHMAKING) updateMatchmaking ( diff --git a/back/volume/src/users/entity/user.entity.ts b/back/volume/src/users/entity/user.entity.ts index 67163cf..b13939e 100644 --- a/back/volume/src/users/entity/user.entity.ts +++ b/back/volume/src/users/entity/user.entity.ts @@ -22,7 +22,7 @@ export class User { @Column({ unique: true }) ftId: number - @Column({ unique: true }) + @Column({ nullable: true, unique: true }) email: string @Column({ select: false, nullable: true }) diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 414df36..7ee70c2 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -5,10 +5,8 @@ HISTORY = "/history", HISTORY_ID = "/history_id", FRIENDS = "/friends", - SPECTATE = "/spectate", CHANNELS = "/channels", LEADERBOARD = "/leaderboard", - SPECTATE_GAME = "/spectate_game", CREATE_GAME = "/create-game", MATCHMAKING = "/matchmaking", PROFILE_ID = "/profile_id", diff --git a/front/volume/src/components/NavBar.svelte b/front/volume/src/components/NavBar.svelte index dceffc3..bd15f74 100644 --- a/front/volume/src/components/NavBar.svelte +++ b/front/volume/src/components/NavBar.svelte @@ -6,7 +6,6 @@ import.meta.env.VITE_BACK_PORT; export let links = [ { text: "Home" }, - { text: "Spectate" }, { text: "Channels" }, { text: "History" }, { text: "Friends" }, diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte index 4ea52fd..c4bbce0 100644 --- a/front/volume/src/components/Pong/Pong.svelte +++ b/front/volume/src/components/Pong/Pong.svelte @@ -5,7 +5,6 @@ import GameCreation from "./GameCreation.svelte"; import GameComponent from "./GameComponent.svelte"; import type { StringDto } from "./dtos/StringDto"; - import SpectateFriend from "./SpectateFriend.svelte"; import Matchmaking from "./Matchmaking.svelte"; import type { MatchmakingDto } from "./dtos/MatchmakingDto"; import { getUser, store } from "../../Auth"; @@ -92,10 +91,6 @@ } else if (!data.matchmaking && appState === APPSTATE.MATCHMAKING) { setAppState(APPSTATE.HOME); } - } else if (event == GAME_EVENTS.SPECTATE) { - if (data) { - gamePlaying = true; - } } else if (event == GAME_EVENTS.READY) { game.youAreReady = true; } else { @@ -173,9 +168,6 @@ - @@ -192,13 +184,6 @@ > - {:else if appState === APPSTATE.SPECTATE_GAME} -
setAppState(APPSTATE.HOME)} - on:keydown={() => setAppState(APPSTATE.HOME)} - > - -
{/if} {:else if !connected} Connecting to game server... diff --git a/front/volume/src/components/Pong/SpectateFriend.svelte b/front/volume/src/components/Pong/SpectateFriend.svelte deleted file mode 100644 index 54eaebb..0000000 --- a/front/volume/src/components/Pong/SpectateFriend.svelte +++ /dev/null @@ -1,44 +0,0 @@ - - -
-
- - -
-
- - diff --git a/front/volume/src/components/Pong/constants.ts b/front/volume/src/components/Pong/constants.ts index 62bc9f2..57c010f 100644 --- a/front/volume/src/components/Pong/constants.ts +++ b/front/volume/src/components/Pong/constants.ts @@ -8,7 +8,6 @@ export const GAME_EVENTS = { GET_GAME_INFO: "GET_GAME_INFO", CREATE_GAME: "CREATE_GAME", REGISTER_PLAYER: "REGISTER_PLAYER", - SPECTATE: "SPECTATE", MATCHMAKING: "MATCHMAKING", LEAVE_GAME: "LEAVE_GAME", };