mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Remove move-piece reducer
We're handling moves on the server side now.
This commit is contained in:
parent
7ff1b03f89
commit
31d08cdad1
@ -2,7 +2,6 @@ import Immutable from "immutable";
|
|||||||
import { Map } from "immutable";
|
import { Map } from "immutable";
|
||||||
|
|
||||||
import defaultState from "../store/default-state";
|
import defaultState from "../store/default-state";
|
||||||
import movePiece from "./move-piece";
|
|
||||||
|
|
||||||
const chessBoardReducer = (state = defaultState, action) => {
|
const chessBoardReducer = (state = defaultState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@ -17,12 +16,6 @@ const chessBoardReducer = (state = defaultState, action) => {
|
|||||||
.set("gameId", action.gameId)
|
.set("gameId", action.gameId)
|
||||||
.toJS();
|
.toJS();
|
||||||
|
|
||||||
case "MOVE_PIECE":
|
|
||||||
return Immutable.fromJS(state)
|
|
||||||
.set("board", movePiece(state.board))
|
|
||||||
.set("selectedSquare", null)
|
|
||||||
.toJS();
|
|
||||||
|
|
||||||
case "SELECT_PIECE":
|
case "SELECT_PIECE":
|
||||||
return Immutable.fromJS(state)
|
return Immutable.fromJS(state)
|
||||||
.set("selectedSquare", action.coords)
|
.set("selectedSquare", action.coords)
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
import Immutable from "immutable";
|
|
||||||
import { Map } from "immutable";
|
|
||||||
|
|
||||||
const movePiece = (board, from, to) => {
|
|
||||||
const newBoard = Immutable.fromJS(board);
|
|
||||||
const piece = board[from.rank][from.file];
|
|
||||||
|
|
||||||
const boardChange = Map([
|
|
||||||
[from.rank, Map([[from.file, null]])]
|
|
||||||
]).mergeDeep(Map([
|
|
||||||
[to.rank, Map([[to.file, piece]])]
|
|
||||||
]));
|
|
||||||
|
|
||||||
return newBoard.mergeDeep(boardChange).toJS();
|
|
||||||
}
|
|
||||||
|
|
||||||
export default movePiece;
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
const SET_BOARD = "SET_BOARD";
|
const SET_BOARD = "SET_BOARD";
|
||||||
const SET_GAME_ID = "SET_GAME_ID";
|
const SET_GAME_ID = "SET_GAME_ID";
|
||||||
const SELECT_PIECE = "SELECT_PIECE";
|
const SELECT_PIECE = "SELECT_PIECE";
|
||||||
const MOVE_PIECE = "MOVE_PIECE";
|
|
||||||
|
|
||||||
export const setBoard = (board) => {
|
export const setBoard = (board) => {
|
||||||
return {
|
return {
|
||||||
@ -23,11 +22,3 @@ export const selectPiece = (coords) => {
|
|||||||
coords: coords
|
coords: coords
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const movePiece = (from, to) => {
|
|
||||||
return {
|
|
||||||
type: MOVE_PIECE,
|
|
||||||
from: from,
|
|
||||||
to: to
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user