From 391b5569a42484a3b4cdaf5769e54edbc8fe2bd3 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Fri, 4 Nov 2022 13:04:32 +0100 Subject: [PATCH] Code cleanup --- PongGame/Hubs/PongGameState.cs | 5 ++--- PongGame/Hubs/PongHub.cs | 2 +- PongGame/Hubs/PongLobbyCollection.cs | 3 +-- PongGame/Hubs/PongRoom.cs | 6 +++--- PongGame/Pages/Pong.cshtml.cs | 3 +-- PongGame/Pages/Privacy.cshtml.cs | 3 +-- PongGame/Program.cs | 1 - 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/PongGame/Hubs/PongGameState.cs b/PongGame/Hubs/PongGameState.cs index 34d6ce4..8929926 100644 --- a/PongGame/Hubs/PongGameState.cs +++ b/PongGame/Hubs/PongGameState.cs @@ -123,9 +123,8 @@ public struct PongGameState { public PongPaddleDirection Direction; public int Score; - public static void Update(ref PongPaddleState state) { - state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH); - } + public static void Update(ref PongPaddleState state) + => state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH); public RectangleF GetCollider(float x) => new(x - PADDLE_WIDTH / 2, Height - PADDLE_HALF_LENGTH, PADDLE_WIDTH, PADDLE_LENGTH); diff --git a/PongGame/Hubs/PongHub.cs b/PongGame/Hubs/PongHub.cs index f9fc32d..d5d77da 100644 --- a/PongGame/Hubs/PongHub.cs +++ b/PongGame/Hubs/PongHub.cs @@ -64,7 +64,7 @@ public class PongHub : Hub { public Task RequestUsernameChange(string username) { // TOOD: check this - Logger.LogInformation($"Player {Player} requested username change to [{username}]"); + Logger.LogInformation("Player {Player} requested username change to [{username}]", Player, username); Player.Username = username; return Task.CompletedTask; } diff --git a/PongGame/Hubs/PongLobbyCollection.cs b/PongGame/Hubs/PongLobbyCollection.cs index 96e3b0c..73e601e 100644 --- a/PongGame/Hubs/PongLobbyCollection.cs +++ b/PongGame/Hubs/PongLobbyCollection.cs @@ -1,5 +1,4 @@ -using System.Collections.Concurrent; -using Microsoft.AspNetCore.SignalR; +using Microsoft.AspNetCore.SignalR; namespace PongGame.Hubs; diff --git a/PongGame/Hubs/PongRoom.cs b/PongGame/Hubs/PongRoom.cs index da85f33..ac8932d 100644 --- a/PongGame/Hubs/PongRoom.cs +++ b/PongGame/Hubs/PongRoom.cs @@ -46,7 +46,7 @@ public class PongRoom { _ = Task.Run(PlayersChanged); } - private BackgroundWorker gameWorker = new() { + private readonly BackgroundWorker gameWorker = new() { WorkerSupportsCancellation = true }; @@ -87,11 +87,11 @@ public class PongRoom { public void MovePaddle(PongPlayer player, PongPaddleDirection direction) { if (Player1 == player) { State.Paddle1.Direction = direction; - Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction); + Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction); return; } else if (Player2 == player) { State.Paddle2.Direction = direction; - Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction); + Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction); return; } throw new InvalidOperationException("Player is not in this room, but moved! Assumably players room wasn't deleted."); diff --git a/PongGame/Pages/Pong.cshtml.cs b/PongGame/Pages/Pong.cshtml.cs index a0abdf6..b3f871a 100644 --- a/PongGame/Pages/Pong.cshtml.cs +++ b/PongGame/Pages/Pong.cshtml.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace PongGame.Pages; public class PongModel : PageModel { diff --git a/PongGame/Pages/Privacy.cshtml.cs b/PongGame/Pages/Privacy.cshtml.cs index a52630c..7d2426c 100644 --- a/PongGame/Pages/Privacy.cshtml.cs +++ b/PongGame/Pages/Privacy.cshtml.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace PongGame.Pages; public class PrivacyModel : PageModel { diff --git a/PongGame/Program.cs b/PongGame/Program.cs index bb59de0..2ff1acb 100644 --- a/PongGame/Program.cs +++ b/PongGame/Program.cs @@ -1,4 +1,3 @@ -using MessagePack; using PongGame.Hubs; var builder = WebApplication.CreateBuilder(args);