|
@@ -1,6 +1,5 @@
|
|
import React from "react";
|
|
import React from "react";
|
|
import {
|
|
import {
|
|
- LOADING,
|
|
|
|
PRE_GAME,
|
|
PRE_GAME,
|
|
PRE_ROUND,
|
|
PRE_ROUND,
|
|
IN_ROUND,
|
|
IN_ROUND,
|
|
@@ -13,49 +12,18 @@ import PreRound from '../pre-round.component';
|
|
import GamePanelContainer from "../game-panel.component";
|
|
import GamePanelContainer from "../game-panel.component";
|
|
import RoundSummary from '../round-summary.component';
|
|
import RoundSummary from '../round-summary.component';
|
|
import PlayerScoresContainer from "../player-scores.component";
|
|
import PlayerScoresContainer from "../player-scores.component";
|
|
-import Loading from "../loading.component";
|
|
|
|
|
|
|
|
class Game extends React.Component {
|
|
class Game extends React.Component {
|
|
constructor(props) {
|
|
constructor(props) {
|
|
super(props);
|
|
super(props);
|
|
this.state = {
|
|
this.state = {
|
|
- googleApiKey: null,
|
|
|
|
gameState: PRE_GAME,
|
|
gameState: PRE_GAME,
|
|
- playerName: null,
|
|
|
|
gameId: null,
|
|
gameId: null,
|
|
|
|
+ playerName: null,
|
|
lastRound: null,
|
|
lastRound: null,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- renderLoading() {
|
|
|
|
- return <Loading/>
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- renderPreGame() {
|
|
|
|
- return <PreGameContainer
|
|
|
|
- onGameJoined={({ gameId, playerName }) => this.setState({ gameState: PRE_ROUND, gameId, playerName })}
|
|
|
|
- />
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- renderPreRound() {
|
|
|
|
- const { gameId, playerName } = this.state;
|
|
|
|
- return <PreRound
|
|
|
|
- gameId={gameId}
|
|
|
|
- playerName={playerName}
|
|
|
|
- onStart={() => this.setState({ gameState: IN_ROUND })}
|
|
|
|
- />
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- renderInRound() {
|
|
|
|
- const { gameId, playerName } = this.state;
|
|
|
|
- return <GamePanelContainer
|
|
|
|
- gameId={gameId}
|
|
|
|
- playerName={playerName}
|
|
|
|
- onRoundEnd={lastRound => this.setState({ gameState: POST_ROUND, lastRound })}
|
|
|
|
- onGameEnd={() => this.setState({ gameState: POST_GAME })}
|
|
|
|
- />
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
renderPostRound() {
|
|
renderPostRound() {
|
|
const { lastRound } = this.state;
|
|
const { lastRound } = this.state;
|
|
const {
|
|
const {
|
|
@@ -75,40 +43,41 @@ class Game extends React.Component {
|
|
selectedPoint={selectedPoint}
|
|
selectedPoint={selectedPoint}
|
|
/>
|
|
/>
|
|
}
|
|
}
|
|
-
|
|
|
|
- renderPostGame() {
|
|
|
|
- const { gameId } = this.state;
|
|
|
|
- return <PlayerScoresContainer
|
|
|
|
- gameId={gameId}
|
|
|
|
- onReturnToStart={() => this.setState({ gameState: PRE_GAME })}
|
|
|
|
- />
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- renderError() {
|
|
|
|
- return <p>Application encountered unrecoverable error, please refresh the page.</p>
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
render() {
|
|
render() {
|
|
- const { gameState } = this.state;
|
|
|
|
|
|
+ const { gameState, gameId, playerName } = this.state;
|
|
|
|
|
|
switch (gameState) {
|
|
switch (gameState) {
|
|
- case LOADING:
|
|
|
|
- return this.renderLoading();
|
|
|
|
case PRE_GAME:
|
|
case PRE_GAME:
|
|
- return this.renderPreGame();
|
|
|
|
|
|
+ return <PreGameContainer
|
|
|
|
+ onGameJoined={({ gameId, playerName }) => this.setState({ gameState: PRE_ROUND, gameId, playerName })}
|
|
|
|
+ />
|
|
case PRE_ROUND:
|
|
case PRE_ROUND:
|
|
- return this.renderPreRound();
|
|
|
|
|
|
+ return <PreRound
|
|
|
|
+ gameId={gameId}
|
|
|
|
+ playerName={playerName}
|
|
|
|
+ onStart={() => this.setState({ gameState: IN_ROUND })}
|
|
|
|
+ />
|
|
case IN_ROUND:
|
|
case IN_ROUND:
|
|
- return this.renderInRound();
|
|
|
|
|
|
+ return <GamePanelContainer
|
|
|
|
+ gameId={gameId}
|
|
|
|
+ playerName={playerName}
|
|
|
|
+ onRoundEnd={lastRound => this.setState({ gameState: POST_ROUND, lastRound })}
|
|
|
|
+ onGameEnd={() => this.setState({ gameState: POST_GAME })}
|
|
|
|
+ />
|
|
case POST_ROUND:
|
|
case POST_ROUND:
|
|
- return this.renderPostRound();
|
|
|
|
|
|
+ return this.renderPostRound();
|
|
case POST_GAME:
|
|
case POST_GAME:
|
|
- return this.renderPostGame();
|
|
|
|
|
|
+ return <PlayerScoresContainer
|
|
|
|
+ gameId={gameId}
|
|
|
|
+ onReturnToStart={() => this.setState({ gameState: PRE_GAME })}
|
|
|
|
+ />
|
|
case ERROR:
|
|
case ERROR:
|
|
- return this.renderError();
|
|
|
|
|
|
+ // TODO - would be nice to hook this into the sub-components, maybe with a HOC?
|
|
|
|
+ return <p>Application encountered unrecoverable error, please refresh the page.</p>
|
|
default:
|
|
default:
|
|
- this.setState({ gameState: ERROR });
|
|
|
|
- return <p>Application state is inconsistent, please refresh and rejoin your previous game.</p>
|
|
|
|
|
|
+ this.setState({ gameState: ERROR });
|
|
|
|
+ return <p>Application state is inconsistent, please refresh and rejoin your previous game.</p>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|