-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compact player controls and support for custom wrapped components (…
…#57) * Add play/pause icons * Support rendering children inside replay viewer * Update assets commit hash * Cache replay position requests * Allow prop passthrough for slider * Include compact controls * Show compact viewer in separate docs tab * Add Camera icon * Show camera dialog * Revert change to default App tab * Fixed bug where animated objects would spawn at the center of the scene * Added autoplay property to ReplayViewer * Statisfy unused parameter name linting error * Force play/pause dispatch from replay viewer * Bump patch version
- Loading branch information
1 parent
9cfb7fb
commit ae660b9
Showing
16 changed files
with
317 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Grid from "@material-ui/core/Grid" | ||
import React, { Component } from "react" | ||
|
||
import { | ||
CompactPlayControls, | ||
GameBuilderOptions, | ||
GameManager, | ||
GameManagerLoader, | ||
ReplayViewer, | ||
} from "../../../src" | ||
|
||
interface Props { | ||
options: GameBuilderOptions | ||
} | ||
|
||
interface State { | ||
gameManager?: GameManager | ||
} | ||
|
||
class CompactViewer extends Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
renderContent() { | ||
const { gameManager } = this.state | ||
|
||
if (!gameManager) { | ||
return "Food machine broke..." | ||
} | ||
|
||
return ( | ||
<Grid container direction="column" justify="center" spacing={24}> | ||
<Grid item style={{ minHeight: 0, maxWidth: 900, width: "100%" }}> | ||
<ReplayViewer gameManager={gameManager}> | ||
<CompactPlayControls /> | ||
</ReplayViewer> | ||
</Grid> | ||
</Grid> | ||
) | ||
} | ||
|
||
render() { | ||
const { options } = this.props | ||
const onLoad = (gm: GameManager) => this.setState({ gameManager: gm }) | ||
return ( | ||
<GameManagerLoader options={options} onLoad={onLoad}> | ||
{this.renderContent()} | ||
</GameManagerLoader> | ||
) | ||
} | ||
} | ||
|
||
export default CompactViewer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule assets
updated
5 files
+ − | models/draco/Ball.glb | |
+ − | models/draco/Field.glb | |
+ − | models/draco/Octane_ZXR_Blue.glb | |
+ − | models/draco/Octane_ZXR_Orange.glb | |
+ − | models/draco/Wheel.glb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import Button from "@material-ui/core/Button" | ||
import Dialog from "@material-ui/core/Dialog" | ||
import DialogContent from "@material-ui/core/DialogContent" | ||
import DialogTitle from "@material-ui/core/DialogTitle" | ||
import Grid from "@material-ui/core/Grid" | ||
import withStyles, { WithStyles } from "@material-ui/core/styles/withStyles" | ||
import Typography from "@material-ui/core/Typography" | ||
import React, { Component } from "react" | ||
import styled from "styled-components" | ||
|
||
import { | ||
addCameraChangeListener, | ||
removeCameraChangeListener, | ||
} from "../../eventbus/events/cameraChange" | ||
import { | ||
addPlayPauseListener, | ||
dispatchPlayPauseEvent, | ||
PlayPauseEvent, | ||
removePlayPauseListener, | ||
} from "../../eventbus/events/playPause" | ||
import FieldCameraControls from "./FieldCameraControls" | ||
import Camera from "./icons/Camera" | ||
import PausedIcon from "./icons/PausedIcon" | ||
import PlayIcon from "./icons/PlayIcon" | ||
import PlayerCameraControls from "./PlayerCameraControls" | ||
import Slider from "./Slider" | ||
|
||
interface Props extends WithStyles {} | ||
|
||
interface State { | ||
paused: boolean | ||
cameraControlsShowing: boolean | ||
} | ||
|
||
class CompactPlayControls extends Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props) | ||
this.state = { | ||
paused: false, | ||
cameraControlsShowing: false, | ||
} | ||
|
||
addPlayPauseListener(this.onPlayPause) | ||
addCameraChangeListener(this.hideCameraControls) | ||
} | ||
|
||
componentWillUnmount() { | ||
removePlayPauseListener(this.onPlayPause) | ||
removeCameraChangeListener(this.hideCameraControls) | ||
} | ||
|
||
setPlayPause = () => { | ||
const isPaused = this.state.paused | ||
dispatchPlayPauseEvent({ | ||
paused: !isPaused, | ||
}) | ||
} | ||
|
||
onPlayPause = ({ paused }: PlayPauseEvent) => { | ||
this.setState({ | ||
paused, | ||
}) | ||
} | ||
|
||
showCameraControls = () => { | ||
this.setState({ | ||
cameraControlsShowing: true, | ||
}) | ||
} | ||
|
||
hideCameraControls = () => { | ||
this.setState({ | ||
cameraControlsShowing: false, | ||
}) | ||
} | ||
|
||
render() { | ||
const { paused, cameraControlsShowing } = this.state | ||
const { focused, thumb, track } = this.props.classes | ||
return ( | ||
<ControlsWrapper> | ||
<Grid container spacing={24} alignItems="center"> | ||
<Grid item> | ||
<Button onClick={this.setPlayPause}> | ||
{paused ? <PlayIcon /> : <PausedIcon />} | ||
</Button> | ||
</Grid> | ||
<Grid item zeroMinWidth xs> | ||
<Slider | ||
classes={{ | ||
thumb, | ||
track, | ||
focused, | ||
}} | ||
/> | ||
</Grid> | ||
<Grid item> | ||
<Button onClick={this.showCameraControls}> | ||
<Camera /> | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
<Dialog open={cameraControlsShowing} onClose={this.hideCameraControls}> | ||
<DialogTitle>Camera Controls</DialogTitle> | ||
<DialogContent> | ||
<Typography>Field Cameras</Typography> | ||
<FieldCameraControls /> | ||
<Typography>Player Cameras</Typography> | ||
<PlayerCameraControls /> | ||
</DialogContent> | ||
</Dialog> | ||
</ControlsWrapper> | ||
) | ||
} | ||
} | ||
|
||
const ControlsWrapper = styled.div` | ||
position: absolute; | ||
bottom: 6px; | ||
left: 12px; | ||
right: 60px; | ||
` | ||
|
||
export default withStyles({ | ||
focused: {}, | ||
track: { | ||
backgroundColor: "#fff", | ||
}, | ||
thumb: { | ||
backgroundColor: "#fff", | ||
"&:focus,&:hover,&$active": { | ||
boxShadow: "inherit", | ||
}, | ||
}, | ||
})(CompactPlayControls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.