diff --git a/client/src/apiTypes.ts b/client/src/apiTypes.ts index 59ed71b86..0e42ca96c 100644 --- a/client/src/apiTypes.ts +++ b/client/src/apiTypes.ts @@ -115,6 +115,10 @@ export interface ApiAssetUpload { totalSlices: number; data: string; } +export interface ApiAudioMessage { + action: string; + fileName: string; +} export interface ApiBaseRectShape extends ApiCoreShape { width: number; height: number; diff --git a/client/src/game/api/events.ts b/client/src/game/api/events.ts index 1e90d37a0..f45405fe5 100644 --- a/client/src/game/api/events.ts +++ b/client/src/game/api/events.ts @@ -1,4 +1,5 @@ import "../systems/access/events"; +import "../systems/audio/events"; import "../systems/auras/events"; import "../systems/characters/events"; import "../systems/chat/events"; diff --git a/client/src/game/systems/audio/emits.ts b/client/src/game/systems/audio/emits.ts new file mode 100644 index 000000000..35e376e58 --- /dev/null +++ b/client/src/game/systems/audio/emits.ts @@ -0,0 +1,6 @@ +import type { ApiAudioMessage } from "../../../apiTypes"; +import { wrapSocket } from "../../api/helpers"; + +export const sendPlayCommand = wrapSocket("Audio.Play"); +export const sendStopCommand = wrapSocket("Audio.Stop"); +export const toggleLoopCommand = wrapSocket("Audio.ToggleLoop"); \ No newline at end of file diff --git a/client/src/game/systems/audio/events.ts b/client/src/game/systems/audio/events.ts new file mode 100644 index 000000000..ce56fb556 --- /dev/null +++ b/client/src/game/systems/audio/events.ts @@ -0,0 +1,14 @@ +import type { ApiAudioMessage } from "../../../apiTypes"; +import { socket } from "../../api/socket"; + +import { audioSystem } from "."; + +socket.on("Audio.Play", (data: ApiAudioMessage) => { + audioSystem.StartPlayback(data.action, data.fileName); +}); +socket.on("Audio.Stop", (data: ApiAudioMessage) => { + audioSystem.StopPlayback(data.action, data.fileName); +}); +socket.on("Audio.ToggleLoop", (data: ApiAudioMessage) => { + audioSystem.ToggleLoopPlayback(data.action, data.fileName); +}); \ No newline at end of file diff --git a/client/src/game/systems/audio/index.ts b/client/src/game/systems/audio/index.ts new file mode 100644 index 000000000..3a9fd5fc6 --- /dev/null +++ b/client/src/game/systems/audio/index.ts @@ -0,0 +1,39 @@ +import { type System, registerSystem } from ".."; +import type { SystemClearReason } from "../models"; + +import { sendPlayCommand } from "./emits"; +import { sendStopCommand } from "./emits"; +import { toggleLoopCommand } from "./emits"; + +// import MenuBar from "../../ui/menu/MenuBar.vue"; +import { audioService } from "../../ui/menu/audioService"; + +class AudioSystem implements System { + clear(reason: SystemClearReason): void { + } + + PlayAudioForRoom(action: string, fileName: string): void { + sendPlayCommand({ action, fileName}); + } + + StopAudioForRoom(action: string): void { + sendStopCommand({ action, fileName: ""}); + } + + ToggleLoopAudioForRoom(action: string): void { + toggleLoopCommand({ action, fileName: ""}); + } + + StartPlayback(action: string, fileName: string): void { + audioService.startPlayback(fileName); + } + StopPlayback(action: string, fileName: string): void { + audioService.stopPlayback(); + } + ToggleLoopPlayback(action: string, fileName: string): void { + audioService.toggleLoopPlayback(); + } +} + +export const audioSystem = new AudioSystem(); +registerSystem("audio", audioSystem, false); diff --git a/client/src/game/systems/audio/model.ts b/client/src/game/systems/audio/model.ts new file mode 100644 index 000000000..479bceca6 --- /dev/null +++ b/client/src/game/systems/audio/model.ts @@ -0,0 +1,4 @@ +export interface AudioMessage { + action: string; + fileName: string; +} \ No newline at end of file diff --git a/client/src/game/ui/menu/MenuBar.vue b/client/src/game/ui/menu/MenuBar.vue index d077386da..539dad1ee 100644 --- a/client/src/game/ui/menu/MenuBar.vue +++ b/client/src/game/ui/menu/MenuBar.vue @@ -1,5 +1,5 @@