summaryrefslogtreecommitdiff
path: root/frontend/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/models')
-rw-r--r--frontend/src/models/games.js50
-rw-r--r--frontend/src/models/players.js33
2 files changed, 67 insertions, 16 deletions
diff --git a/frontend/src/models/games.js b/frontend/src/models/games.js
index 95bf8015..e48bf23f 100644
--- a/frontend/src/models/games.js
+++ b/frontend/src/models/games.js
@@ -1,6 +1,23 @@
import { Record, Map, List } from 'immutable';
-const SettingsRecord = Record({
+export type SettingsShape = {
+ initialGold: number,
+ lostPointsPerDefeat: number,
+ timeLimitInSeconds: number,
+ randomSeedForTests: number,
+ discardedCardGold: number,
+ defaultTradingCost: number,
+ wonPointsPerVictoryPerAge: {
+ '1': number,
+ '2': number,
+ '3': number
+ },
+ wonderSidePickMethod: 'EACH_RANDOM' | 'TODO',
+ pointsPer3Gold: number
+};
+export type SettingsType = Record<SettingsShape>;
+
+const SettingsRecord: SettingsType = Record({
initialGold: 3,
lostPointsPerDefeat: 1,
timeLimitInSeconds: 45,
@@ -17,7 +34,18 @@ const SettingsRecord = Record({
});
export class Settings extends SettingsRecord {}
-const GameRecord = Record({
+export type GameShape = {
+ id: number,
+ name: string | void,
+ players: List<string>,
+ settings: SettingsType,
+ state: 'LOBBY' | 'TODO'
+};
+export type GameType = Record<GameShape>;
+export type GameMapType = Map<string, GameShape>;
+export type GameNormalMapType = { [string]: GameShape };
+
+const GameRecord: GameType = Record({
id: -1,
name: null,
players: new List(),
@@ -26,16 +54,22 @@ const GameRecord = Record({
});
export class Game extends GameRecord {}
-const GamesRecord = Record({
+export type GamesShape = {
+ all: Map<Games>,
+ current: string
+};
+export type GamesType = Record<GamesShape>;
+
+const GamesRecord: GamesType = Record({
all: new Map(),
- current: '',
+ current: null,
});
export default class GamesState extends GamesRecord {
- addGame(g) {
- const game = new Game(g);
+ addGame(g: GameShape) {
+ const game: Game = new Game(g);
return this.mergeDeepIn(['all', game.id], game);
}
- addGames(games) {
- return this.mergeIn(['all'], games.map(game => new Game(game)));
+ addGames(games: GameNormalMapType) {
+ return this.mergeIn(['all'], games.map((game: GameShape): Game => new Game(game)));
}
}
diff --git a/frontend/src/models/players.js b/frontend/src/models/players.js
index 3df32c57..13d5ad51 100644
--- a/frontend/src/models/players.js
+++ b/frontend/src/models/players.js
@@ -1,26 +1,43 @@
+// @flow
import { Record, Map } from 'immutable';
-const PlayerRecord = Record({
+export type PlayerShape = {
+ username: string,
+ displayName: string,
+ index: number,
+ ready: boolean
+};
+export type PlayerType = Record<PlayerShape>;
+
+const PlayerRecord: PlayerType = Record({
username: null,
displayName: null,
index: 0,
ready: false,
});
+// $FlowFixMe
export class Player extends PlayerRecord {}
-const PlayersRecord = Record({
+export type PlayersShape = {
+ all: Map<string, PlayerType>,
+ current: string
+};
+export type PlayersType = Record<PlayersShape>;
+
+const PlayersRecord: PlayersType = Record({
all: new Map(),
current: '',
});
+// $FlowFixMe
export default class PlayerState extends PlayersRecord {
- addPlayer(p) {
- const player = new Player(p);
- const playerMap = new Map({ [player.username]: player });
+ addPlayer(p: PlayerShape) {
+ const player: Player = new Player(p);
+ const playerMap = new Map(({ [player.username]: player }: { [key: string]: 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)));
+ addPlayers(p: Map<string, PlayerShape>) {
+ const players: Map<string, PlayerShape> = new Map(p);
+ return this.mergeIn(['all'], players.map((player: PlayerShape): Player => new Player(player)));
}
}
bgstack15