summaryrefslogtreecommitdiff
path: root/frontend/src/redux/actions
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/redux/actions')
-rw-r--r--frontend/src/redux/actions/all.js5
-rw-r--r--frontend/src/redux/actions/game.js25
-rw-r--r--frontend/src/redux/actions/lobby.js35
-rw-r--r--frontend/src/redux/actions/players.js29
4 files changed, 94 insertions, 0 deletions
diff --git a/frontend/src/redux/actions/all.js b/frontend/src/redux/actions/all.js
new file mode 100644
index 00000000..45d3ab7a
--- /dev/null
+++ b/frontend/src/redux/actions/all.js
@@ -0,0 +1,5 @@
+import type { GameAction } from './game';
+import type { LobbyAction } from './lobby';
+import type { PlayerAction } from './players';
+
+export type Action = PlayerAction | LobbyAction | GameAction
diff --git a/frontend/src/redux/actions/game.js b/frontend/src/redux/actions/game.js
new file mode 100644
index 00000000..1fe49dfb
--- /dev/null
+++ b/frontend/src/redux/actions/game.js
@@ -0,0 +1,25 @@
+import type { ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../../api/model';
+
+export const types = {
+ REQUEST_SAY_READY: 'GAME/REQUEST_SAY_READY',
+ PLAYER_READY_RECEIVED: 'GAME/PLAYER_READY_RECEIVED',
+ TABLE_UPDATE_RECEIVED: 'GAME/TABLE_UPDATE_RECEIVED',
+ PREPARED_CARD_RECEIVED: 'GAME/PREPARED_CARD_RECEIVED',
+ TURN_INFO_RECEIVED: 'GAME/TURN_INFO_RECEIVED',
+};
+
+export type SayReadyAction = { type: 'GAME/REQUEST_SAY_READY' };
+export type PlayerReadyEvent = { type: 'GAME/PLAYER_READY_RECEIVED', username: string };
+export type TableUpdateEvent = { type: 'GAME/TABLE_UPDATE_RECEIVED', table: ApiTable };
+export type PreparedCardEvent = { type: 'GAME/PREPARED_CARD_RECEIVED', card: ApiPreparedCard };
+export type TurnInfoEvent = { type: 'GAME/TURN_INFO_RECEIVED', turnInfo: ApiPlayerTurnInfo };
+
+export type GameAction = SayReadyAction | PlayerReadyEvent | TableUpdateEvent | PreparedCardEvent | TurnInfoEvent;
+
+export const actions = {
+ sayReady: () => ({ type: types.REQUEST_SAY_READY }),
+ receivePlayerReady: (username: string) => ({ type: types.PLAYER_READY_RECEIVED, username }),
+ receiveTableUpdate: (table: ApiTable) => ({ type: types.TABLE_UPDATE_RECEIVED, table }),
+ receivePreparedCard: (card: ApiPreparedCard) => ({ type: types.PREPARED_CARD_RECEIVED, card }),
+ receiveTurnInfo: (turnInfo: ApiPlayerTurnInfo) => ({ type: types.TURN_INFO_RECEIVED, turnInfo }),
+};
diff --git a/frontend/src/redux/actions/lobby.js b/frontend/src/redux/actions/lobby.js
new file mode 100644
index 00000000..b3151a23
--- /dev/null
+++ b/frontend/src/redux/actions/lobby.js
@@ -0,0 +1,35 @@
+import { fromJS } from 'immutable';
+import type { GameMapType, GameNormalMapType } from '../../models/games';
+
+export const types = {
+ UPDATE_GAMES: 'GAMES/UPDATE_GAMES',
+ REQUEST_CREATE_GAME: 'GAMES/REQUEST_CREATE_GAME',
+ REQUEST_JOIN_GAME: 'GAMES/REQUEST_JOIN_GAME',
+ REQUEST_START_GAME: 'GAMES/REQUEST_START_GAME',
+ ENTER_LOBBY: 'GAMES/ENTER_LOBBY',
+ ENTER_GAME: 'GAMES/ENTER_GAME',
+};
+
+export type UpdateGamesAction = { type: 'GAMES/UPDATE_GAMES', games: GameMapType };
+export type RequestCreateGameAction = { type: 'GAMES/REQUEST_CREATE_GAME', gameName: string };
+export type RequestJoinGameAction = { type: 'GAMES/REQUEST_JOIN_GAME', gameId: number };
+export type RequestStartGameAction = { type: 'GAMES/REQUEST_START_GAME' };
+export type EnterLobbyAction = { type: 'GAMES/ENTER_LOBBY', gameId: number };
+export type EnterGameAction = { type: 'GAMES/ENTER_GAME', gameId: number };
+
+export type LobbyAction =
+ | UpdateGamesAction
+ | RequestCreateGameAction
+ | RequestJoinGameAction
+ | RequestStartGameAction
+ | EnterLobbyAction
+ | EnterGameAction;
+
+export const actions = {
+ updateGames: (games: GameNormalMapType): UpdateGamesAction => ({ type: types.UPDATE_GAMES, games: fromJS(games) }),
+ requestJoinGame: (gameId: number): RequestJoinGameAction => ({ type: types.REQUEST_JOIN_GAME, gameId }),
+ requestCreateGame: (gameName: string): RequestCreateGameAction => ({ type: types.REQUEST_CREATE_GAME, gameName }),
+ requestStartGame: (): RequestStartGameAction => ({ type: types.REQUEST_START_GAME }),
+ enterLobby: (gameId: number): EnterLobbyAction => ({ type: types.ENTER_LOBBY, gameId }),
+ enterGame: (gameId: number): EnterGameAction => ({ type: types.ENTER_GAME, gameId }),
+};
diff --git a/frontend/src/redux/actions/players.js b/frontend/src/redux/actions/players.js
new file mode 100644
index 00000000..7df174c4
--- /dev/null
+++ b/frontend/src/redux/actions/players.js
@@ -0,0 +1,29 @@
+import { Map } from 'immutable';
+import { PlayerShape } from '../../models/players';
+
+export const types = {
+ REQUEST_CHOOSE_USERNAME: 'USER/REQUEST_CHOOSE_USERNAME',
+ SET_CURRENT_PLAYER: 'USER/SET_CURRENT_PLAYER',
+ UPDATE_PLAYERS: 'USER/UPDATE_PLAYERS',
+};
+
+export type RequestChooseUsernameAction = { type: types.REQUEST_CHOOSE_USERNAME, username: string };
+export type SetCurrentPlayerAction = { type: types.SET_CURRENT_PLAYER, player: PlayerShape };
+export type UpdatePlayersAction = { type: types.UPDATE_PLAYERS, players: Map<string, PlayerShape> };
+
+export type PlayerAction = RequestChooseUsernameAction | SetCurrentPlayerAction | UpdatePlayersAction;
+
+export const actions = {
+ chooseUsername: (username: string): RequestChooseUsernameAction => ({
+ type: types.REQUEST_CHOOSE_USERNAME,
+ username,
+ }),
+ setCurrentPlayer: (player: PlayerShape): SetCurrentPlayerAction => ({
+ type: types.SET_CURRENT_PLAYER,
+ player,
+ }),
+ updatePlayers: (players: Map<string, PlayerShape>): UpdatePlayersAction => ({
+ type: types.UPDATE_PLAYERS,
+ players,
+ }),
+};
bgstack15