Skip to content

Commit

Permalink
feat: sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Veradictus committed Sep 18, 2023
1 parent fea6010 commit 45e6797
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/client/src/network/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ export default class Connection {
}

case Opcodes.Notification.Popup: {
if (info.soundEffect) this.audio.playSound(info.soundEffect);

return this.menu
.getNotification()
.show(
Expand Down Expand Up @@ -883,6 +885,9 @@ export default class Connection {
this.info.create(Modules.Hits.Heal, info.amount, character.x, character.y);

character.addEffect(Modules.Effects.Healing);

if (this.game.player.instance === character.instance) this.audio.playSound('heal');

break;
}

Expand Down Expand Up @@ -943,6 +948,8 @@ export default class Connection {
*/

private handleDeath(): void {
this.audio.playSound('death');

// Stop player movement
this.game.player.stop(true);

Expand Down Expand Up @@ -1038,6 +1045,8 @@ export default class Connection {
*/

private handleRespawn(info: RespawnPacketData): void {
this.game.audio.playSound('revive');

this.game.player.setGridPosition(info.x, info.y);

this.camera.centreOn(this.game.player);
Expand Down
1 change: 1 addition & 0 deletions packages/common/network/impl/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface NotificationPacketData {
message: string; // String message to display.
colour?: string; // Colour of the message.
source?: string;
soundEffect?: string;
}

export type NotificationPacketCallback = (
Expand Down
1 change: 1 addition & 0 deletions packages/common/types/popup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface PopupData {
title: string;
text: string;
colour: string;
soundEffect?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ export default class Achievement {
return {
title: 'Achievement Completed!',
text,
colour: '#33cc33'
colour: '#33cc33',
soundEffect: 'achievement'
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class Achievements {
*/

private handlePopup(popup: PopupData): void {
this.player.popup(popup.title, popup.text, popup.colour);
this.player.popup(popup.title, popup.text, popup.colour, popup.soundEffect);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/game/entity/character/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2268,16 +2268,18 @@ export default class Player extends Character {
* @param title The header text for the popup.
* @param message The text contents of the popup.
* @param colour The colour of the popup's text.
* @param soundEffect The sound effect to play when the popup is displayed.
*/

public popup(title: string, message: string, colour = '#00000'): void {
public popup(title: string, message: string, colour = '#00000', soundEffect = ''): void {
if (!title) return;

this.send(
new NotificationPacket(Opcodes.Notification.Popup, {
title,
message,
colour
colour,
soundEffect
})
);
}
Expand Down

0 comments on commit 45e6797

Please sign in to comment.