Compare commits

..

2 commits

Author SHA1 Message Date
d7ba4f911b
Add Jest-generated coverage files to gitignore 2019-09-06 14:11:52 +02:00
93558b0304
Handle player leaving on clients 2019-09-06 14:11:38 +02:00
2 changed files with 11 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
coverage
# local env files
.env.local

View file

@ -38,6 +38,16 @@ export abstract class Client extends EventEmitter {
this.players.push(data.name);
this.emit("player-joined", data.name);
break;
case "player-left":
let idx = this.players.indexOf(data.name);
if (idx < 0) {
// Weird
console.warn(
`Someone (${data.name}) left but wasn't on the player list`
);
break;
}
this.players.splice(idx, 1);
default:
// For most cases, we can just use the kind as event type
this.emit(data.kind, data);