add start of client rendering
This commit is contained in:
parent
9787a9d468
commit
ebcee954bf
13 changed files with 127 additions and 7 deletions
|
@ -1,8 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
class Connection {
|
||||
constructor() {
|
||||
|
||||
constructor(net, socket) {
|
||||
this.net = net;
|
||||
this.connections = net.connections;
|
||||
this.io = net.io;
|
||||
this.socket = socket;
|
||||
|
||||
this.player = false;
|
||||
this._room = false;
|
||||
this.name = '';
|
||||
this.chatCooldown = 0;
|
||||
|
||||
socket.on('chat', data => {
|
||||
this.chat(data);
|
||||
});
|
||||
|
||||
socket.on('setName', data => {
|
||||
this.player.name = data.name;
|
||||
});
|
||||
|
||||
this.room = 'egg';
|
||||
}
|
||||
|
||||
chat(data) {
|
||||
console.log(this.room);
|
||||
if(this.chatCooldown > 5 || !this.room) return;
|
||||
|
||||
this.chatCooldown++;
|
||||
this.io.to(this.room).emit('chat', {
|
||||
name: this.player.name,
|
||||
msg: data.msg.slice(0, 100)
|
||||
});
|
||||
}
|
||||
|
||||
tick() {
|
||||
this.chatCooldown -= 1;
|
||||
}
|
||||
|
||||
get room() {
|
||||
return this._room;
|
||||
}
|
||||
|
||||
set room(str) {
|
||||
this.socket.leave(this._room);
|
||||
this.socket.join(str);
|
||||
this._room = str;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue