From 541e2e605ca8bd359e066404a035f8d2d30e78ed Mon Sep 17 00:00:00 2001 From: Lang Date: Fri, 18 Nov 2016 20:03:54 +0100 Subject: [PATCH] bugfix grid field render #12 --- .../Resources/public/css/style.mineseeker.css | 2 +- .../Resources/public/js/mine-seeker/app.js | 14 +++++++++----- .../public/js/mine-seeker/grid/grid-control.js | 16 +++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css index 1389091..b0da53f 100644 --- a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css +++ b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css @@ -87,7 +87,7 @@ main { font-family: 'Open Sans', sans-serif; text-align: center; color: #354d6a; - width: 300px; + width: 500px; padding: 10px; -webkit-border-radius: 10px; diff --git a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js index d79baa4..8dc7bda 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js @@ -30,8 +30,8 @@ class MineSeeker extends React.Component { /** game end control */ makeGameEndIfItEnds(bluePoints, redPoints) { - var redWins = redPoints > 3, - blueWins = bluePoints > 3; + var redWins = redPoints > 2, + blueWins = bluePoints > 2; if (redWins || blueWins) { this.refs.gridControl.setState({ @@ -74,6 +74,7 @@ class MineSeeker extends React.Component { this.state.session = session; /** save session to GridControl */ + /** render grid fields - #12 */ this.refs.gridControl.setState({ grid: this.state.gameInherited ? JSON.parse(Base64.decode(gridServer)) : gridClient, session: this.state.session, @@ -82,7 +83,8 @@ class MineSeeker extends React.Component { overlayTitle: "We are waiting for your opponent...", overlaySubTitle: this.state.gameAssoc ? Play w/ me! - : '' + : '', + renderGridFields: this.state.gameAssoc }); /** setup the web player */ @@ -111,7 +113,7 @@ class MineSeeker extends React.Component { this.refs.gridControl.refs.userControl.state.bombSelected = payload.data.bomb; this.refs.gridControl.stepEvent(payload.data.coords); - + /** End-game control */ this.makeGameEndIfItEnds( this.refs.gridControl.refs.userControl.refs.blue.state.mines, @@ -126,8 +128,10 @@ class MineSeeker extends React.Component { (typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!" ); + var activePlayer = this.refs.gridControl.refs.userControl.state.activePlayer ? 'blue' : 'red'; + /** remove overlay when every user has been came */ - this.refs.gridControl.setState({overlay: payload.userCnt < 2}); + this.refs.gridControl.setState({ overlay: payload.userCnt < 2}); /** Set up player names w/ server data */ this.refs.gridControl.refs.userControl.refs.red.setState({ diff --git a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js index 29733dc..de478c3 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js @@ -16,6 +16,8 @@ class GridControl extends React.Component { env: props.env, webPlayer: null, grid: null, + renderGridFields: false, + gridFields: [], updatedFieldCache: [], bombFieldCache: [], foundUserMineCache: 0, @@ -382,13 +384,11 @@ class GridControl extends React.Component { return 'game-overlay' + ( this.state.overlay ? '' : ' hide' ); } - render() { - var grid = []; - + renderGridFields() { if (this.state.grid) { for (let i = 0, j = this.state.grid.length; i < j; i++) { for (let k = 0, l = this.state.grid[i].length; k < l; k++) { - grid.push( + this.state.gridFields.push( @@ -411,7 +417,7 @@ class GridControl extends React.Component {
-
{grid}
+
{this.state.gridFields}
);