Skip to content

Commit

Permalink
start game button
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhao committed Jan 29, 2022
1 parent aa928f0 commit 618a9b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
41 changes: 20 additions & 21 deletions src/components/Fencing/Fencing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,28 @@ export const Fencing: React.FC<{gid: string}> = (props) => {
<Flex style={{flex: 1, overflow: 'auto'}}>
<div className={classes.container}>
<Helmet title={`Fencing ${gid}`} />
{gameState.loaded && gameState.started && (
<div style={{flex: 1}}>
<FencingCountdown gameState={gameState} gameEventsHook={eventsHook}>
<FencingToolbar toolbarActions={toolbarActions} />
<Player
// eslint-disable-next-line react/jsx-props-no-spreading
{...transformGameToPlayerProps(
gameState.game!,
_.values(gameState.users),
playerActions,
id,
teamId
)}
/>
</FencingCountdown>
</div>
)}
<div style={{flex: 1}}>
<FencingCountdown playerActions={playerActions} gameState={gameState} gameEventsHook={eventsHook}>
{gameState.loaded && gameState.started && (
<>
{' '}
<FencingToolbar toolbarActions={toolbarActions} />
<Player
// eslint-disable-next-line react/jsx-props-no-spreading
{...transformGameToPlayerProps(
gameState.game!,
_.values(gameState.users),
playerActions,
id,
teamId
)}
/>
</>
)}
</FencingCountdown>
</div>
</div>
<Flex column style={{flexBasis: 500}}>
{!gameState.started && (
<button onClick={playerActions.startGame}>Start Game (wait for everyone to join!)</button>
)}

{!gameState.loaded && <div>Loading your game...</div>}
{gameState.game && (
<Chat
Expand Down
35 changes: 28 additions & 7 deletions src/components/Fencing/FencingCountdown.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
import classes from '*.module.css';
import {makeStyles} from '@material-ui/core';
import {CircularProgress, makeStyles} from '@material-ui/core';
import React, {useEffect, useState} from 'react';
import {GameState} from '../../shared/gameEvents/types/GameState';
import {GameEventsHook} from './useGameEvents';
import {PlayerActions} from './usePlayerActions';

export const FencingCountdown: React.FC<{gameState: GameState; gameEventsHook: GameEventsHook}> = (props) => {
export const FencingCountdown: React.FC<{
playerActions: PlayerActions;
gameState: GameState;
gameEventsHook: GameEventsHook;
}> = (props) => {
const [renderCount, setRenderCount] = useState(0);
const classes = useStyles();
const serverTime = props.gameEventsHook.getServerTime();
const GAME_START_DELAY_MS = 1000 * 10;
const loading =
const notLoaded = !props.gameState.loaded;
const notStarted = !props.gameState.loaded || !props.gameState.started;
const countingDown =
!props.gameState.started ||
(props.gameState.startedAt && serverTime < props.gameState.startedAt + GAME_START_DELAY_MS);

useEffect(() => {
if (loading) {
if (countingDown) {
requestAnimationFrame(() => {
setRenderCount((x) => x + 1);
});
}
}, [renderCount]);
if (loading) {
}, [renderCount, countingDown]);

if (notLoaded) {
return (
<div className={classes.countdown}>
<CircularProgress />
</div>
);
}
if (notStarted) {
return (
<div className={classes.countdown}>
<button onClick={props.playerActions.startGame}>Start Game (wait for everyone to join!)</button>
</div>
);
}
if (countingDown) {
return (
<div className={classes.countdown}>
Starting In
Expand Down

1 comment on commit 618a9b8

@vercel
Copy link

@vercel vercel bot commented on 618a9b8 Jan 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.