party test

This commit is contained in:
Evert Prants 2022-04-09 22:31:36 +03:00
parent 53ce49257b
commit 2c46201285
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -19,6 +19,7 @@ export class Game {
public thirdPersonCamera!: ThirdPersonCamera; public thirdPersonCamera!: ThirdPersonCamera;
public joystick!: Joystick; public joystick!: Joystick;
public chat!: Chat; public chat!: Chat;
private party: string[] = [];
public renderer = new Renderer(); public renderer = new Renderer();
@ -39,32 +40,10 @@ export class Game {
this.videoTest.initialize(); this.videoTest.initialize();
this.videoTest.mesh.position.set(0, 6, -20); this.videoTest.mesh.position.set(0, 6, -20);
this.renderer.scene.add(this.videoTest.mesh); this.renderer.scene.add(this.videoTest.mesh);
this.party = localStorage.getItem('party')?.split('|') || [];
// end of // end of
this.chat.registerSendFunction((message) => { 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); this.socket.emit('chat-send', message);
}); });
@ -179,6 +158,49 @@ export class Game {
} }
this.chat.addMessage(event.sender.display_name, event.message); 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
}
} }