Skip to content

Commit

Permalink
feat: Add all packetes except full
Browse files Browse the repository at this point in the history
  • Loading branch information
Sup3rFire committed Feb 16, 2024
1 parent 244b577 commit 03558e3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/game/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export default class Player {
this.id = player.gameid;
this.user = user;
this.options = player.options;
this.board = new Array(
player.options.boardheight + player.options.boardbuffer
).fill(new Array(player.options.boardwidth).fill(null));
this.board = new Array(player.options.boardheight + player.options.boardbuffer).fill(
new Array(player.options.boardwidth).fill(null)
);
}

public id: string;
public user: User;
public options: any;
public board: any;
public replayFrames: any[] = [];
}
20 changes: 20 additions & 0 deletions src/ws/commands/game.advance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Player from "../../game/Player";
import WebSocketManager from "../WebSocketManager";

export default async function (ws: WebSocketManager, { data }: any) {
if (!ws.client.room?.game) return;

ws.client.room.game.replayData.push({
board: data.currentboard,
replays: (data.currentboard as any[]).map((x) => {
let player = [...(ws.client.room.game?.players as Map<string, Player>).values()].find(
(k) => k.user.id === x.id
) as Player;
return { frames: player.replayFrames.at(-1).frame, events: player.replayFrames };
}),
});
ws.client.room.game.players.forEach((v, k) => {
v.replayFrames = [];
ws.client.room.game?.players.set(k, v);
});
}
13 changes: 13 additions & 0 deletions src/ws/commands/game.end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ export default async function (ws: WebSocketManager, { data }: any) {

ws.client.room.game.ended = true;
ws.client.room.game.endData = data;
ws.client.room.game.replayData.push({
board: data.currentboard,
replays: (data.currentboard as any[]).map((x) => {
let player = [...(ws.client.room.game?.players as Map<string, Player>).values()].find(
(k) => k.user.id === x.id
) as Player;
return { frames: player.replayFrames.at(-1).frame, events: player.replayFrames };
}),
});
ws.client.room.game.players.forEach((v, k) => {
v.replayFrames = [];
ws.client.room.game?.players.set(k, v);
});
ws.client.room.game.me?.end();

ws.client.room.game.emit("score", leaderboard, victor);
Expand Down
7 changes: 7 additions & 0 deletions src/ws/commands/replay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import WebSocketManager from "../WebSocketManager";

export default async function (ws: WebSocketManager, { data }: any) {
if (!ws.client.room?.game) return;

ws.client.room.game.players.get(data.gameid)?.replayFrames.push(...data.frames);
}

0 comments on commit 03558e3

Please sign in to comment.