blob: 3df32c571d3d834968052855b6acc40dfb61c358 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { Record, Map } from 'immutable';
const PlayerRecord = Record({
username: null,
displayName: null,
index: 0,
ready: false,
});
export class Player extends PlayerRecord {}
const PlayersRecord = Record({
all: new Map(),
current: '',
});
export default class PlayerState extends PlayersRecord {
addPlayer(p) {
const player = new Player(p);
const playerMap = new Map({ [player.username]: player });
return this.addPlayers(playerMap).set('current', player.username);
}
addPlayers(p) {
const players = new Map(p);
return this.mergeIn(['all'], players.map(player => new Player(player)));
}
}
|