From 2c46201285dda819d28e84d21cd7e9345c43aeea Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 9 Apr 2022 22:31:36 +0300 Subject: [PATCH] party test --- src/client/game.ts | 68 ++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/src/client/game.ts b/src/client/game.ts index 8ff9616..1a3b9bc 100644 --- a/src/client/game.ts +++ b/src/client/game.ts @@ -19,6 +19,7 @@ export class Game { public thirdPersonCamera!: ThirdPersonCamera; public joystick!: Joystick; public chat!: Chat; + private party: string[] = []; public renderer = new Renderer(); @@ -39,32 +40,10 @@ export class Game { this.videoTest.initialize(); this.videoTest.mesh.position.set(0, 6, -20); this.renderer.scene.add(this.videoTest.mesh); + this.party = localStorage.getItem('party')?.split('|') || []; // end of this.chat.registerSendFunction((message) => { - // experimental - if (message.startsWith('!play')) { - const [cmd, src] = message.split(' '); - if (src) { - this.videoTest.setSource(src, true); - } else { - this.videoTest.play(); - } - return; - } - - if (message.startsWith('!stop') || message.startsWith('!pause')) { - this.videoTest.stop(); - return; - } - - if (message.startsWith('!volume')) { - const [cmd, vol] = message.split(' '); - this.videoTest.setVolume(parseInt(vol.replace('%', ''), 10)); - return; - } - // end of - this.socket.emit('chat-send', message); }); @@ -179,6 +158,49 @@ export class Game { } this.chat.addMessage(event.sender.display_name, event.message); + this.experimentalPlayerCmd(event.message, event.sender.display_name); }); } + + private experimentalPlayerCmd(message: string, sender: string) { + if (message.startsWith('!party')) { + const [cmd, task, name] = message.split(' ', 2); + if (task === 'join') { + this.party.push(name); + } + + if (task === 'leave') { + this.party.splice(this.party.indexOf(name), 1); + } + + if (task === 'clear') { + this.party.length = 0; + } + + localStorage.setItem('party', this.party.join('|')); + } + + if (!(sender === this.me.display_name || this.party.includes(sender))) { + return; + } + + if (message.startsWith('!play')) { + const [cmd, src] = message.split(' '); + if (src) { + this.videoTest.setSource(src, true); + } else { + this.videoTest.play(); + } + } + + if (message.startsWith('!stop') || message.startsWith('!pause')) { + this.videoTest.stop(); + } + + if (message.startsWith('!volume')) { + const [cmd, vol] = message.split(' '); + this.videoTest.setVolume(parseInt(vol.replace('%', ''), 10)); + } + // end of + } }