Skip to content

Commit 8f196fc

Browse files
authored
Merge pull request #28 from SaltieRL/pa-perf-cleanup
Fix performance issues and bugs
2 parents e3cf204 + 717692c commit 8f196fc

24 files changed

+424
-143
lines changed

docs/package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Examples for the web replay viewer",
55
"main": "src/index.tsx",
66
"scripts": {
7-
"start": "./node_modules/.bin/webpack-dev-server --mode development"
7+
"start": "npx webpack-dev-server --mode development"
88
},
99
"keywords": [
1010
"Examples",

docs/src/App.tsx

+22-63
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,45 @@
1+
import Tab from "@material-ui/core/Tab"
2+
import Tabs from "@material-ui/core/Tabs"
13
import React, { Component } from "react"
2-
import {
3-
ReplayViewer,
4-
GameManager,
5-
loadBuilderFromReplay,
6-
PlayControls,
7-
PlayerCameraControls,
8-
Slider,
9-
FieldCameraControls,
10-
} from "../../src"
11-
import { Grid, withStyles, WithStyles } from "@material-ui/core"
4+
5+
import Main from "./components/Main"
6+
7+
type ActiveTab = "viewer" | "other"
128

139
interface State {
14-
gameManager?: GameManager
10+
tab: ActiveTab
1511
}
1612

17-
class App extends Component<WithStyles, State> {
13+
class App extends Component<any, State> {
1814
constructor(props: any) {
1915
super(props)
20-
this.state = {}
16+
this.state = {
17+
tab: "viewer",
18+
}
2119
}
2220

23-
componentDidMount() {
24-
const REPLAY_ID = "BDC240CE11E96C735CEBCE8190E3C53A"
25-
26-
loadBuilderFromReplay(REPLAY_ID).then(gameManager => {
27-
this.setState({ gameManager })
21+
handleChange = (_: any, newTab: ActiveTab) => {
22+
this.setState({
23+
tab: newTab,
2824
})
2925
}
3026

3127
render() {
32-
const { gameManager } = this.state
33-
const { root } = this.props.classes
28+
const { tab } = this.state
3429
return (
3530
<div style={{ maxWidth: 900, width: "100%", margin: "0 auto" }}>
3631
<div>
3732
<h2>Welcome to React</h2>
3833
</div>
39-
{gameManager ? (
40-
<Grid
41-
container
42-
className={root}
43-
direction="column"
44-
justify="center"
45-
spacing={24}
46-
>
47-
<Grid item style={{ minHeight: 0, maxWidth: 900, width: "100%" }}>
48-
<ReplayViewer gameManager={gameManager} />
49-
</Grid>
50-
<Grid item>
51-
<Grid
52-
container
53-
justify="space-between"
54-
alignItems="center"
55-
spacing={24}
56-
>
57-
<Grid item>
58-
<PlayControls />
59-
</Grid>
60-
<Grid item>
61-
<FieldCameraControls />
62-
</Grid>
63-
</Grid>
64-
</Grid>
65-
<Grid item>
66-
<PlayerCameraControls />
67-
</Grid>
68-
<Grid item>
69-
<Slider />
70-
</Grid>
71-
</Grid>
72-
) : (
73-
"Loading..."
74-
)}
34+
<Tabs value={tab} onChange={this.handleChange}>
35+
<Tab label="Viewer" value="viewer" />
36+
<Tab label="Other" value="other" />
37+
</Tabs>
38+
{tab === "viewer" && <Main />}
39+
{tab === "other" && <div>Other</div>}
7540
</div>
7641
)
7742
}
7843
}
7944

80-
export default withStyles({
81-
root: {
82-
"&& > div:nth-child(even)": {
83-
backgroundColor: "rgba(0, 0, 0, 0.05)",
84-
},
85-
},
86-
})(App)
45+
export default App

docs/src/components/Empty.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from "react"
2+
3+
const Empty = () => {
4+
return <div>Empty component</div>
5+
}
6+
7+
export default Empty

docs/src/components/Main.tsx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { Component } from "react"
2+
3+
import { FPSClock, GameBuilderOptions, loadReplay } from "../../../src"
4+
import Viewer from "./Viewer"
5+
6+
interface State {
7+
options?: GameBuilderOptions
8+
}
9+
10+
class Main extends Component<any, State> {
11+
constructor(props: any) {
12+
super(props)
13+
this.state = {}
14+
}
15+
16+
componentDidMount() {
17+
const REPLAY_ID = "9944A36A11E987D3E286C1B524E68ECC"
18+
19+
loadReplay(REPLAY_ID).then(([replayData, replayMetadata]) => {
20+
this.setState({
21+
options: {
22+
replayData,
23+
replayMetadata,
24+
clock: FPSClock.convertReplayToClock(replayData),
25+
},
26+
})
27+
})
28+
}
29+
30+
render() {
31+
const { options } = this.state
32+
33+
if (!options) {
34+
return "Loading..."
35+
}
36+
37+
return <Viewer options={options} />
38+
}
39+
}
40+
41+
export default Main

0 commit comments

Comments
 (0)