Skip to content

Commit

Permalink
removed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
halil-kalyoncu committed Oct 13, 2023
1 parent 0086d4d commit e860b54
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 191 deletions.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
build:
dockerfile: Dockerfile
context: ./nestjs
# Only build development stage from Dockerfile
target: development
# Mount our host dir to the docker container
# Mount api directory (./api) to (:) docker container (/pong_game/src/app)
Expand All @@ -15,6 +14,7 @@ services:
- /pong_game/src/app/node_modules/
# RUN in debug mode: npm run start:debug -> Also start your vscode debugger
# RUN in dev mode: npm run start:dev
# RUN in production mode: npm run start:prod
command: npm run start:debug
depends_on:
- postgres
Expand All @@ -34,6 +34,8 @@ services:
volumes:
- ./vue/conf:/pong_game/frontend/src/app
- /pong_game/frontend/src/app/node_modules/
# RUN in dev mode: npm run start:dev
# RUN in preview mode: npm run start:preview
command: npm run dev
env_file:
- .env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ export class DirectMessageController {
}
}

// @Get('allUnreadByUserId')
// async getAllUnreadDirectMessages(@Query('userId', ParseIntPipe) userId: number): Promise<DirectMessage[]> {
// return this.directMessageService.getAllUnreadMessages(userId);
// }

//Get all the unread messages from the db based on the userId given as a URL from the frontend
@UseGuards(JwtAuthGuard)
@ApiOperation({
Expand Down
1 change: 0 additions & 1 deletion nestjs/conf/src/chat/dto/channel.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export class ChannelMessageDto {
@ApiProperty()
@IsBoolean()
blockGroupMessage: boolean;
//ChannelMessageReadStatus: ChannelMessageReadStatus;
}

export class ChannelMemberDto {
Expand Down
28 changes: 14 additions & 14 deletions nestjs/conf/src/chat/gateway/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ChatGateway
socket.disconnect();
}

/*****************
/******************
*** Friendlist ***
******************/

Expand Down Expand Up @@ -265,7 +265,7 @@ export class ChatGateway
}
}

/*********************
/**********************
*** DirectMessages ***
**********************/

Expand Down Expand Up @@ -294,7 +294,7 @@ export class ChatGateway
}
}

/**************
/***************
*** Channel ***
***************/

Expand Down Expand Up @@ -790,7 +790,7 @@ export class ChatGateway
return { error: error.message as string };
}
}
/**********************
/***********************
*** ChannelMessages ***
***********************/

Expand Down Expand Up @@ -826,9 +826,9 @@ export class ChatGateway
return { error: error.message as string };
}
}
/**********************
/**************************
*** ChannelInvitations ***
***********************/
**************************/

@SubscribeMessage('acceptChannelInvitation')
async handleAcceptChannelInvitation(
Expand Down Expand Up @@ -942,9 +942,9 @@ export class ChatGateway
return { error: error.message as string };
}
}
/******************
/********************
*** MatchInvites ***
*******************/
********************/

@SubscribeMessage('sendMatchInvite')
async sendGameInvite(
Expand Down Expand Up @@ -1121,7 +1121,7 @@ export class ChatGateway
}
}

/************
/*************
*** Match ***
*************/
@SubscribeMessage('hostLeaveMatch')
Expand Down Expand Up @@ -1184,9 +1184,9 @@ export class ChatGateway
this.updateFriendsOf(socket.data.user.id);
}

/******************
/*******************
*** Matchmaking ***
******************/
*******************/

@SubscribeMessage('queueUpForLadder')
async queueUpForLadder(
Expand Down Expand Up @@ -1312,9 +1312,9 @@ export class ChatGateway
}
}

/******************
/*******************
*** Block users ***
******************/
*******************/

@SubscribeMessage('blockUser')
async blockUser(
Expand Down Expand Up @@ -1386,7 +1386,7 @@ export class ChatGateway
}
}

/**********************
/***********************
*** Helperfunctions ***
***********************/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class ChannelInvitationsService {
return invitations;
}

//ERROR HANDLING API BACKEND
async inviteUserToChannel(
channelId: number,
inviteeId: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class ChannelMessageReadStatusService {
});
return unreadMessages;
} catch (error) {
// Handle errors appropriately
throw new Error('Error fetching unread messages: ' + error.message);
}
}
Expand Down
71 changes: 1 addition & 70 deletions nestjs/conf/src/game/gateway/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ export class EventsGateway {
constructor(
private userService: UserService,
private matchService: MatchService,
) {
// this.rooms.set("test", new Room("test"));
// this.startGame();
}
) {}

@WebSocketServer()
server: Server;

// gameIsRunning = false; -> individual game has to know if is running
rooms = new Map<number, Room>();
// players = new Map<string, string>(); -> individual socket holds information if it is the left or right player

startGame(room: Room) {
const gameInterval = setInterval(async () => {
Expand Down Expand Up @@ -94,33 +89,8 @@ export class EventsGateway {
}, 15);
}

// afterInit(server: Server) {
// this.server = server;
// console.log('Server is ready');
// }

// handleConnection(client: any, ...args: any[]) {
// if (!this.players.has(client.id))
// {
// if (this.players.size < 1)
// {
// this.players.set(client.id, "left");
// client.emit('direction', 'left');
// }
// else
// {
// this.players.set(client.id, "right");
// client.emit('direction', 'right');
// client.broadcast.emit('startGame');
// client.emit('startGame');
// }
// }
// console.log(`Client connected: ${client.id}`);
// }

async handleConnection(socket: Socket, ...args: any[]) {
if (!socket.handshake.query.userId || !socket.handshake.query.matchId) {
//error handling?
console.log("query doesn't have the properties userId and matchId");
return;
}
Expand Down Expand Up @@ -162,14 +132,12 @@ export class EventsGateway {
room.socketIds[1] = socket.id;
}

//both players are connected to the games if both socket ids are set, better solution?
if (room.socketIds[0] != '' && room.socketIds[1] != '') {
this.startCountdown(room);
}
}

async handleDisconnect(socket: Socket) {
//this.players.delete(client.id);
const room = this.rooms.get(socket.data.match.id);

if (!room) {
Expand Down Expand Up @@ -197,16 +165,9 @@ export class EventsGateway {
}
socket.disconnect();
}
// resetGame() {
// this.gameIsRunning = false;
// console.log("HERE");
// this.rooms.get("test").ball.resetBall();
// this.server.emit('ballPosition', this.rooms.get("test").ball.getBallPosition());
// }

@SubscribeMessage('fire')
handleMagnetFire(@ConnectedSocket() socket: Socket): void {
console.log('FIRE');
const room = this.rooms.get(socket.data.match.id);
if (socket.id === room.socketIds[0] && room.ball.magnet === 1) {
room.ball.ballSticking = 0;
Expand Down Expand Up @@ -245,9 +206,6 @@ export class EventsGateway {
'paddleMove',
{ playerId: 'left', newPos: paddleAPos.y },
);

//this.server.emit('paddleMove', { playerId: 'left', newPos: paddleAPos.y }); -> this would send to all clients currently on the server,
// we only want to send to the two users that are playing the match
} else {
let paddleBPos = { x: 0, y: 0, wid: 0, hgt: 0 };

Expand All @@ -268,31 +226,10 @@ export class EventsGateway {
'paddleMove',
{ playerId: 'right', newPos: paddleBPos.y },
);
//this.server.emit('paddleMove', { playerId: 'right', newPos: paddleBPos.y });
}
return;
}

// @SubscribeMessage('ballX')
// updateBallX(socket: Socket, ballX: number): void {
// ballPos.x = ballX;
// this.sendToOpponent(socket, this.rooms.get(socket.data.match.id).socketIds, 'ballX', ballPos.x);
// //client.broadcast.emit('ballX', ballPos.x);
// }

// @SubscribeMessage('ballY')
// updateBallY(socket: Socket, ballY: number): void {
// ballPos.y = ballY;
// this.sendToOpponent(socket, this.rooms.get(socket.data.match.id).socketIds, 'ballY', ballPos.y);
// //client.broadcast.emit('ballY', ballPos.y);
// }

// @SubscribeMessage('start')
// sendStartMessage(client: any): void {
// client.broadcast.emit('startGame');
// console.log("start");
// }

@SubscribeMessage('spawnPowerUp')
createPowerUp(
@ConnectedSocket() socket: Socket,
Expand All @@ -310,7 +247,6 @@ export class EventsGateway {
): void {
const room = this.rooms.get(socket.data.match.id);
data.speed = 0.2;
// data.color = "blue";
const newPowerUp = new PowerUp(
data.id,
data.x,
Expand All @@ -322,10 +258,6 @@ export class EventsGateway {
data.color,
);
room.powerups.push(newPowerUp);
// socket.emit('newPowerUp', data);
// this.sendToOpponent(socket, room.socketIds, 'newPowerUp', data);
// this.server.to(room.socketIds[1]).emit('newPowerUp', data);
// console.log("powerup spawned at x: ", data.x)
}

@SubscribeMessage('executePowerUp')
Expand Down Expand Up @@ -402,7 +334,6 @@ export class EventsGateway {
!socketIds[1] ||
socketIds[1] === ''
) {
//handle error
return;
}

Expand Down
6 changes: 1 addition & 5 deletions nestjs/conf/src/game/service/ball.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Room } from './room.service';
import { Server } from 'socket.io';
import { PowerUp } from './powerup.service';

//500, 200, 15, 15, 5, 4, 3, 800, 600
@Injectable()
export class Ball {
constructor(
Expand Down Expand Up @@ -37,7 +36,6 @@ export class Ball {
this.dy = 3 * (Math.random() < 0.5 ? 1 : -1);
this.speed = 4;
this.pause = true;
// this.magnet = 0;
}

moveBallDir(paddleBY: number, paddleHeight: number, paddle: string): void {
Expand All @@ -47,7 +45,6 @@ export class Ball {
let bounceAngle = (paddleHitLocation * 45 * Math.PI) / 180;

this.speed++;
// console.log("Speed", this.speed);

if (paddle == 'A') this.dx = -this.speed * Math.cos(bounceAngle);
else this.dx = this.speed * Math.cos(bounceAngle);
Expand Down Expand Up @@ -122,7 +119,7 @@ export class Ball {
room.rightPlayerGoals++;
server.to(room.socketIds[0]).emit('scoreGoal', 'playerB');
server.to(room.socketIds[1]).emit('scoreGoal', 'playerB');
// this.magdiff = this.y - padd

scoredGoal = true;
if (room.rightPlayerGoals == 1 && room.leftPlayerGoals == 0)
room.firstGoal = 'RIGHT';
Expand Down Expand Up @@ -174,7 +171,6 @@ export class Ball {
else if (this.handleBallCollision(nextBallX, nextBallY, room, 'A')) {
if (this.magnet == 1) {
this.ballSticking = 1;
// console.log("DIFFERENCE: ", this.y)
return;
}
this.moveBallDir(room.paddleA.y, room.paddleA.hgt, 'A');
Expand Down
4 changes: 0 additions & 4 deletions nestjs/conf/src/game/service/paddle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export class Paddle {
this.y = y;
}

// setHeight(hgt: number) {
// this.hgt = hgt;
// }

increaseHeight() {
if (this.hgt < 400) {
this.hgt += 20;
Expand Down
4 changes: 2 additions & 2 deletions nestjs/conf/src/game/service/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Room {
ball: Ball;
paddleA: Paddle;
paddleB: Paddle;
//players: Map<string, string>;

powerups: PowerUp[];
gameIsRunning: boolean;

Expand Down Expand Up @@ -42,7 +42,7 @@ export class Room {
this.ball = new Ball(500, 200, 15, 15, 5, 4, 3, 800, 600);
this.paddleA = new Paddle(1, 100, 15, 100, 7, 800, 600);
this.paddleB = new Paddle(785, 100, 15, 100, 7, 800, 600);
//this.players = new Map();

this.leftPlayerId = leftPlayerId;
this.rightPlayerId = rightPlayerId;
this.powerups = [];
Expand Down
Loading

0 comments on commit e860b54

Please sign in to comment.