Skip to content

Commit

Permalink
Commented spectator fixes
Browse files Browse the repository at this point in the history
Added comments to the new merge for spectator fixes
  • Loading branch information
ymmot239 committed Nov 5, 2024
1 parent 49ecba4 commit afaf9b9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/chessboard/chessboard-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ChessboardWrapper(props: ChessboardWrapperProps): JSX.Element {
setLastClickedSquare(undefined);
};

//set the side to their respective colors
//set the side to their respective colors and orientations
switch (props.side) {
case Side.WHITE:
if (orientation !== "white") setOrientation("white");
Expand Down
1 change: 1 addition & 0 deletions src/client/setup/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function Setup(): JSX.Element {
);
}

//if the client is a host, let them choose a game type
if (data.clientType === ClientType.HOST) {
return (
<SetupBase>
Expand Down
7 changes: 7 additions & 0 deletions src/common/message/game-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class GameInterruptedMessage extends Message {
}
}

/**
* A message that contains why the game has finished
*
*/
export class GameFinishedMessage extends Message {
constructor(public readonly reason: GameFinishedReason) {
super();
Expand All @@ -83,6 +87,9 @@ export class GameFinishedMessage extends Message {
}
}

/**
* A message that contains why the game was temporarily held
*/
export class GameHoldMessage extends Message {
constructor(public readonly reason: GameHoldReason) {
super();
Expand Down
5 changes: 5 additions & 0 deletions src/server/api/client-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export class ClientManager {
return socket !== undefined;
}

/**
* send an update message to all spectators
* @param message - the message to send
* @returns if it completed successfully
*/
public sendToSpectators(message: Message): boolean {
if (this.spectatorIds.size !== 0) {
for (const item of this.spectatorIds) {
Expand Down
4 changes: 4 additions & 0 deletions src/server/api/game-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class HumanGameManager extends GameManager {
this.clientManager,
);
}

//bind all spectators
const sendToSpectators = this.clientManager.sendToSpectators.bind(
this.clientManager,
);
Expand Down Expand Up @@ -156,6 +158,8 @@ export class HumanGameManager extends GameManager {
sendToPlayer(message);
sendToOpponent(message);
sendToSpectators(message);

//end the game in save manager
if (ids) {
if (currentSave?.host === ids[0])
SaveManager.endGame(ids[0], ids[1]);
Expand Down

0 comments on commit afaf9b9

Please sign in to comment.