refactor grid control and grid field
This commit is contained in:
@@ -11,7 +11,7 @@ class GridControl extends React.Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
grid: grid.state.grid,
|
grid: grid.state.grid,
|
||||||
updated: [],
|
updatedFieldCache: [],
|
||||||
lastClicked: {
|
lastClicked: {
|
||||||
red: null,
|
red: null,
|
||||||
blue: null
|
blue: null
|
||||||
@@ -38,27 +38,21 @@ class GridControl extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO ez azért kell, mert amíg nem fut le a showAppropriateFields(), addig nem updatelődik a GridField.state
|
* It must be cached because the GridField.state not updated until
|
||||||
|
* all showAppropriateFields() method runned out!!
|
||||||
*/
|
*/
|
||||||
if (
|
if (this.state.updatedFieldCache.indexOf(this.refString(row, col)) < 0 && !currentField.state.active) {
|
||||||
this.state.grid[row][col] !== 0 &&
|
this.state.updatedFieldCache.push(this.refString(row, col));
|
||||||
this.state.updated.indexOf(this.refString(row, col)) < 0 && !currentField.state.active
|
|
||||||
) {
|
|
||||||
this.state.updated.push(this.refString(row, col));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (this.state.grid[row][col] === 0) {
|
||||||
this.state.grid[row][col] === 0 &&
|
return {
|
||||||
this.state.updated.indexOf(this.refString(row, col)) < 0 && !currentField.state.active
|
row: row,
|
||||||
) {
|
col: col
|
||||||
this.state.updated.push(this.refString(row, col));
|
};
|
||||||
|
}
|
||||||
return {
|
|
||||||
row: row,
|
|
||||||
col: col
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +77,8 @@ class GridControl extends React.Component {
|
|||||||
active: true
|
active: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.state.updated.indexOf(this.refString(row, col)) < 0) {
|
if (this.state.updatedFieldCache.indexOf(this.refString(row, col)) < 0) {
|
||||||
this.state.updated.push(this.refString(row, col));
|
this.state.updatedFieldCache.push(this.refString(row, col));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.grid[row][col] === 0) {
|
if (this.state.grid[row][col] === 0) {
|
||||||
@@ -167,7 +161,7 @@ class GridControl extends React.Component {
|
|||||||
this.handleGridField(this.state.grid[coords[0]][coords[1]], coords[0], coords[1]);
|
this.handleGridField(this.state.grid[coords[0]][coords[1]], coords[0], coords[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderGrid() {
|
renderGridFields() {
|
||||||
var grid = [];
|
var grid = [];
|
||||||
|
|
||||||
for (var i = 0, j = this.state.grid.length; i < j; i++) {
|
for (var i = 0, j = this.state.grid.length; i < j; i++) {
|
||||||
@@ -193,7 +187,7 @@ class GridControl extends React.Component {
|
|||||||
<UserControl ref="userControl" blue="Olcsó János" red="Eszet Lenke"/>
|
<UserControl ref="userControl" blue="Olcsó János" red="Eszet Lenke"/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid">
|
<div className="grid">
|
||||||
{this.renderGrid()}
|
{this.renderGridFields()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,24 +48,42 @@ class GridField extends React.Component {
|
|||||||
|
|
||||||
currentImage() {
|
currentImage() {
|
||||||
return isNaN(this.state.currentImage)
|
return isNaN(this.state.currentImage)
|
||||||
? <div className="flag-mine"><img src={this.state.currentImage}/><div className="flag-mine-base"></div></div>
|
?
|
||||||
|
<div className="flag-mine">
|
||||||
|
<img src={this.state.currentImage}/>
|
||||||
|
<div className="flag-mine-base"></div>
|
||||||
|
</div>
|
||||||
: this.state.currentImage ? <div className="flag-number">{this.state.currentImage}</div> : '';
|
: this.state.currentImage ? <div className="flag-number">{this.state.currentImage}</div> : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
lastClickedRed() {
|
lastClickedClass() {
|
||||||
return 'field-red-last' + (this.state.lastClickedRed ? ' last-clicked' : '');
|
return 'field-'
|
||||||
|
+ (this.state.lastClickedRed ? 'red' : '')
|
||||||
|
+ (this.state.lastClickedBlue ? 'blue' : '') + '-last last-clicked';
|
||||||
}
|
}
|
||||||
|
|
||||||
lastClickedBlue() {
|
lastClickedSrc() {
|
||||||
return 'field-blue-last' + (this.state.lastClickedBlue ? ' last-clicked' : '');
|
return this.state.lastClickedRed
|
||||||
|
? "/bundles/mineseeker/images/bg-last-red-outbg.png"
|
||||||
|
: "/bundles/mineseeker/images/bg-last-blue-outbg.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLastClicked() {
|
||||||
|
return this.state.lastClickedRed || this.state.lastClickedBlue
|
||||||
|
? <img className={this.lastClickedClass()}
|
||||||
|
src={this.lastClickedSrc()}
|
||||||
|
alt="blue last"/>
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="field-wrapper">
|
<div className="field-wrapper">
|
||||||
<img className="field-target" src="/bundles/mineseeker/images/bg-target-outbg.png" alt="target" onClick={this.props.onClick}/>
|
<img className="field-target"
|
||||||
<img className={this.lastClickedRed()} src="/bundles/mineseeker/images/bg-last-red-outbg.png" alt="red last"/>
|
src="/bundles/mineseeker/images/bg-target-outbg.png"
|
||||||
<img className={this.lastClickedBlue()} src="/bundles/mineseeker/images/bg-last-blue-outbg.png" alt="blue last"/>
|
alt="target"
|
||||||
|
onClick={this.props.onClick}/>
|
||||||
|
{this.currentLastClicked()}
|
||||||
<div className={this.classNameWhenActive()}>
|
<div className={this.classNameWhenActive()}>
|
||||||
<div className="field-corner">
|
<div className="field-corner">
|
||||||
{this.currentImage()}
|
{this.currentImage()}
|
||||||
|
|||||||
Reference in New Issue
Block a user