Skip to content

Commit

Permalink
Remove unncesary info
Browse files Browse the repository at this point in the history
  • Loading branch information
takumihara committed Mar 4, 2024
1 parent 774e7e5 commit 5d4eb52
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 63 deletions.
28 changes: 6 additions & 22 deletions frontend/app/pong/[id]/PongBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ const getLogFromStatus = (status: Status) => {
};

function PongBoard({ id }: PongBoardProps) {
const [fps, setFps] = useState<number>(0);
const [speed, setSpeed] = useState<number>(0);
const [player1Position, setPlayer1Position] = useState<number>(0);
const [player2Position, setPlayer2Position] = useState<number>(0);
const [logs, setLogs] = useState<string[]>([]);
const [userMode, setUserMode] = useUserMode();

Expand All @@ -88,8 +84,8 @@ function PongBoard({ id }: PongBoardProps) {
return userMode == "player"
? setRightPlayer
: playerNumber == 1
? setLeftPlayer
: setRightPlayer;
? setLeftPlayer
: setRightPlayer;
},
[userMode],
);
Expand All @@ -100,21 +96,12 @@ function PongBoard({ id }: PongBoardProps) {
throw new Error("canvas not ready");
}
if (!gameRef.current) {
const game = new PongGame(
ctx,
setFps,
setSpeed,
setPlayer1Position,
setPlayer2Position,
defaultColor,
defaultColor,
userMode,
);
const game = new PongGame(ctx, defaultColor, defaultColor, userMode);
gameRef.current = game;
return game;
}
return gameRef.current;
}, [setFps, setSpeed, setPlayer1Position, setPlayer2Position, userMode]);
}, [userMode]);

const start = useCallback(() => {
if (!userMode) return;
Expand Down Expand Up @@ -341,18 +328,15 @@ function PongBoard({ id }: PongBoardProps) {
ref={canvasRef}
width={CANVAS_WIDTH}
height={CANVAS_HEIGHT}
className="border flex-grow"></canvas>
className="border flex-grow"
></canvas>
<div className="flex flex-col gap-4">
<div className="flex flex-wrap gap-2">
<Button onClick={start} disabled={startDisabled}>
Start
</Button>
</div>
<PongInformationBoard
fps={fps}
speed={speed}
player1Position={player1Position}
player2Position={player2Position}
logs={logs}
userMode={userMode}
leftPlayer={leftPlayer}
Expand Down
25 changes: 0 additions & 25 deletions frontend/app/pong/[id]/PongGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ export class PongGame {
private is_playing: boolean;
private movingDirection: movingDirectionType = "none";

setFps: setFunction<number>;
setSpeed: setFunction<number>;
setPlayer1Position: setFunction<number>;
setPlayer2Position: setFunction<number>;
onAction: onActionType | undefined;
private userMode: userModeType;

constructor(
ctx: CanvasRenderingContext2D,
setFps: setFunction<number>,
setSpeed: setFunction<number>,
setPlayer1Position: setFunction<number>,
setPlayer2Position: setFunction<number>,
paddleColor: string,
ballColor: string,
userMode: userModeType,
Expand Down Expand Up @@ -71,10 +63,6 @@ export class PongGame {
this.elapsed = 0;
this.frame_count = 0;
this.is_playing = false;
this.setFps = setFps;
this.setSpeed = setSpeed;
this.setPlayer1Position = setPlayer1Position;
this.setPlayer2Position = setPlayer2Position;
this.userMode = userMode;
}

Expand All @@ -88,21 +76,11 @@ export class PongGame {
const fps = Math.round(
this.frame_count / (elapsed_since_last_update / 1000),
);
this.setFps(fps);
this.frame_count = 0;
this.fps_updated_at = this.updated_at;
}
};

update_speed(speed: number) {
this.setSpeed(speed);
}

update_players() {
this.setPlayer1Position(this.player1.x);
this.setPlayer2Position(this.player2.x);
}

draw_canvas = () => {
// Clear objects
this.ctx.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
Expand Down Expand Up @@ -142,9 +120,6 @@ export class PongGame {
const now = Date.now();
this.elapsed = this.updated_at === undefined ? 0 : now - this.updated_at;
this.updated_at = now;
this.update_fps();
this.update_speed(this.ball.speed());
this.update_players();
if (this.userMode === "player") {
if (this.movingDirection === "left") {
this.player1.clear(this.ctx);
Expand Down
16 changes: 0 additions & 16 deletions frontend/app/pong/[id]/PongInformationBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ import { PublicUserEntity } from "@/app/lib/dtos";
import { GameCard } from "@/app/ui/pong/GameCard";

interface PongInformationBoardProps {
fps: number;
speed: number;
player1Position: number;
player2Position: number;
logs: string[];
userMode: "viewer" | "player";
leftPlayer?: PublicUserEntity;
rightPlayer?: PublicUserEntity;
}

export default function PongInformationBoard({
fps,
speed,
player1Position,
player2Position,
logs,
userMode,
leftPlayer,
Expand All @@ -28,14 +20,6 @@ export default function PongInformationBoard({
<div className="overflow-hidden flex-grow flex flex-col gap-1">
<GameCard leftPlayer={leftPlayer} rightPlayer={rightPlayer}></GameCard>
<div>You are a {userMode}</div>
<div id="fps">FPS: {fps}</div>
<div id="speed">Speed: {speed}</div>
<div>
player1: <span id="player1">{player1Position}</span>
</div>
<div>
player2: <span id="player2">{player2Position}</span>
</div>
<div
id="logs"
className="flex-grow overflow-y-auto flex flex-col gap-0 border border-spacing-1 p-1"
Expand Down

0 comments on commit 5d4eb52

Please sign in to comment.