Skip to content

Commit

Permalink
feat(piece): give onDrop third param
Browse files Browse the repository at this point in the history
  • Loading branch information
willb335 committed Jul 18, 2018
1 parent 36a66f3 commit 5e46859
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Chessboard/Piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const pieceSource = {
if (onDrop.length) {
wasManuallyDropped(true);
// execute user's logic
return onDrop(props.currentSquare, dropResults.target);
return onDrop(props.currentSquare, dropResults.target, piece);
}
// set new position

Expand All @@ -174,8 +174,8 @@ function collect(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
connectDragPreview: connect.dragPreview(),
isDragging: monitor.isDragging(),
dropTarget: monitor.getDropResult()
isDragging: monitor.isDragging()
// dropTarget: monitor.getDropResult()
};
}

Expand Down
1 change: 0 additions & 1 deletion src/Chessboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ class Chessboard extends Component {
/* Called on drop if there is no onDrop prop. This is what executes when a position does not
change through the position prop, i.e., simple drag and drop operations on the pieces.*/
setPosition = (piece, sourceSquare, targetSquare = null) => {
console.log('sq', sourceSquare, 'ts', targetSquare);
const { currentPosition } = this.state;
const { getPosition, dropOffBoard } = this.props;
if (sourceSquare === targetSquare) return;
Expand Down
16 changes: 8 additions & 8 deletions src/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import React, { Component } from 'react';
import Chessboard from './Chessboard';
// import HumanVsRandom from './integrations/HumanVsRandom';
// import RandomVsRandom from './integrations/RandomVsRandom';
// import HumanVsHuman from './integrations/HumanVsHuman';
import HumanVsHuman from './integrations/HumanVsHuman';
// import RandomFEN from './integrations/RandomFEN';
// import Stockfish from './integrations/Stockfish';
// import { roughSquare } from './integrations/customRough';
import lebronJames from './img/kingJames.png';
import elvis from './img/elvis.png';
// import lebronJames from './img/kingJames.png';
// import elvis from './img/elvis.png';
// import defaultPieces from './Chessboard/svg/chesspieces/standard';

class Demo extends Component {
render() {
return (
<div style={boardsContainer}>
<div>
{/* <div>
<div style={board}>
<Chessboard
id="standard"
Expand All @@ -30,7 +30,6 @@ class Demo extends Component {
currentSquare,
sourceSquare
}) =>
console.log('cs', currentSquare, 'sq', sourceSquare) ||
currentSquare === 'f4' ||
(sourceSquare === 'f4' && !currentSquare) ||
(sourceSquare === 'a2' && currentSquare !== 'spare') ? (
Expand All @@ -46,9 +45,9 @@ class Demo extends Component {
sparePieces={true}
/>
</div>
</div>
</div> */}
<div>
{/* <div style={board}>
<div style={board}>
<HumanVsHuman>
{({
position,
Expand All @@ -72,10 +71,11 @@ class Demo extends Component {
getPosition={getPosition}
darkSquareStyle={darkSquareStyle}
lightSquareStyle={{ backgroundColor: 'white' }}
sparePieces={true}
/>
)}
</HumanVsHuman>
</div> */}
</div>
{/* <div>
<div style={board}>
<RandomFEN>
Expand Down
3 changes: 2 additions & 1 deletion src/integrations/HumanVsHuman.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class HumanVsHuman extends Component {

getPosition = position => this.setState({ myPosition: position });

onDrop = (source, target) => {
onDrop = (source, target, piece) => {
console.log('source', source, 'target', target, 'piece', piece);
this.removeHighlightSquare();

// see if the move is legal
Expand Down

0 comments on commit 5e46859

Please sign in to comment.