Skip to content

Commit

Permalink
feat: initial work on clicking on players to spectate them; fix: remo…
Browse files Browse the repository at this point in the history
…ve debug message
  • Loading branch information
hsanger committed Aug 7, 2023
1 parent 83f5685 commit 1e69334
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion client/src/scripts/packets/receiving/updatePacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export class UpdatePacket extends ReceivingPacket {
if (!game.objects.has(id)) {
switch (type.category) {
case ObjectCategory.Player: {
console.log(`new player created with id ${id}, active player id = ${game.activePlayer.id}`);
object = new Player(game, scene, type as ObjectType<ObjectCategory.Player>, id);
break;
}
Expand Down
5 changes: 4 additions & 1 deletion client/src/scripts/packets/sending/spectatePacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ export class SpectatePacket extends SendingPacket {
override readonly allocBytes = 2;
override readonly type = PacketType.Spectate;
readonly spectateAction: SpectateActions;
readonly playerID?: number;

constructor(player: PlayerManager, spectateAction: SpectateActions) {
constructor(player: PlayerManager, spectateAction: SpectateActions, playerID?: number) {
super(player);
this.spectateAction = spectateAction;
this.playerID = playerID;
}

override serialize(stream: SuroiBitStream): void {
super.serialize(stream);
stream.writeBits(this.spectateAction, SPECTATE_ACTIONS_BITS);
if (this.playerID !== undefined) stream.writeObjectID(this.playerID);
}
}
3 changes: 1 addition & 2 deletions client/src/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ $((): void => {
$("#spectating-msg").show();

// Gas message
$("#gas-msg-info").text("Toxic gas is advancing! Move to the safe zone");
$("#gas-msg-info").css("color", "cyan");
$("#gas-msg-info").text("Toxic gas is advancing! Move to the safe zone").css("color", "cyan");
$("#gas-msg").show();

$("#weapon-ammo-container").show();
Expand Down
1 change: 1 addition & 0 deletions common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export enum SpectateActions {
BeginSpectating,
SpectatePrevious,
SpectateNext,
SpectateSpecific,
Report
}

Expand Down
7 changes: 7 additions & 0 deletions server/src/packets/receiving/spectatePacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export class SpectatePacket extends ReceivingPacket {
player.spectate(game.spectatablePlayers[index]);
}
break;
case SpectateActions.SpectateSpecific: {
const playerID = stream.readObjectID();
if (playerID > 0 && playerID < game.spectatablePlayers.length) {
player.spectate(game.spectatablePlayers[playerID]);
}
break;
}
case SpectateActions.Report: {
if (!fs.existsSync("reports")) fs.mkdirSync("reports");
const reportID = randomUUID();
Expand Down

0 comments on commit 1e69334

Please sign in to comment.