Basic networking #9

Merged
hamcha merged 17 commits from feature/basic-networking into master 2019-09-06 12:36:11 +00:00
Showing only changes of commit 93558b0304 - Show all commits

View file

@ -38,6 +38,16 @@ export abstract class Client extends EventEmitter {
this.players.push(data.name); this.players.push(data.name);
this.emit("player-joined", data.name); this.emit("player-joined", data.name);
break; 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: default:
// For most cases, we can just use the kind as event type // For most cases, we can just use the kind as event type
this.emit(data.kind, data); this.emit(data.kind, data);