mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Render captured pieces in the graveyard 👻
This commit is contained in:
parent
316ee3aa8c
commit
3cea4c0540
@ -47,6 +47,7 @@
|
|||||||
@import "components/game-list";
|
@import "components/game-list";
|
||||||
@import "components/game-grid";
|
@import "components/game-grid";
|
||||||
@import "components/game-info";
|
@import "components/game-info";
|
||||||
|
@import "components/graveyard";
|
||||||
@import "components/move-list";
|
@import "components/move-list";
|
||||||
@import "components/game-state";
|
@import "components/game-state";
|
||||||
@import "components/player-finder";
|
@import "components/player-finder";
|
||||||
|
|||||||
5
assets/css/components/_graveyard.scss
Normal file
5
assets/css/components/_graveyard.scss
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
.graveyard__stones {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
@ -14,6 +14,7 @@ import Listeners from "../store/listeners";
|
|||||||
import ChessBoard from "./chess-board";
|
import ChessBoard from "./chess-board";
|
||||||
import MoveList from "./move-list";
|
import MoveList from "./move-list";
|
||||||
import GameInfo from "./game-info";
|
import GameInfo from "./game-info";
|
||||||
|
import Graveyard from "./graveyard";
|
||||||
|
|
||||||
const notifications = new Notifications();
|
const notifications = new Notifications();
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ class Game extends React.Component {
|
|||||||
<GameInfo store={store} />
|
<GameInfo store={store} />
|
||||||
|
|
||||||
<MoveList store={store} />
|
<MoveList store={store} />
|
||||||
|
<Graveyard store={store} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
35
assets/js/components/graveyard.js
Normal file
35
assets/js/components/graveyard.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
|
const Graveyard = props => {
|
||||||
|
return (
|
||||||
|
<div className="graveyard">
|
||||||
|
<GraveStones colour="white" pieces={props.graveyard.white} />
|
||||||
|
<GraveStones colour="black" pieces={props.graveyard.black} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
graveyard: state.graveyard
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(Graveyard);
|
||||||
|
|
||||||
|
const GraveStones = ({ colour, pieces}) => {
|
||||||
|
return (
|
||||||
|
<ul className="graveyard__stones">
|
||||||
|
{pieces.map(({colour, type}, index) => {
|
||||||
|
return <GraveStone key={`${colour}${type}${index}`} colour={colour} type={type} />
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const GraveStone = ({ colour, type }) => {
|
||||||
|
return <li class="graveyard__stone">
|
||||||
|
<img src={`/images/${type}_${colour}.svg`} />
|
||||||
|
</li>
|
||||||
|
}
|
||||||
@ -25,6 +25,7 @@ const chessBoardReducer = (state = defaultState, action) => {
|
|||||||
.set("selectedSquare", null)
|
.set("selectedSquare", null)
|
||||||
.set("availableMoves", [])
|
.set("availableMoves", [])
|
||||||
.set("moves", action.moves)
|
.set("moves", action.moves)
|
||||||
|
.set("graveyard", action.graveyard)
|
||||||
.toJS();
|
.toJS();
|
||||||
|
|
||||||
case "SET_AVAILABLE_MOVES":
|
case "SET_AVAILABLE_MOVES":
|
||||||
|
|||||||
@ -5,6 +5,7 @@ const SET_AVAILABLE_MOVES = "SET_AVAILABLE_MOVES";
|
|||||||
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 SET_OPPONENT_STATUS = "SET_OPPONENT_STATUS";
|
const SET_OPPONENT_STATUS = "SET_OPPONENT_STATUS";
|
||||||
|
const SET_GRAVEYARD = "SET_GRAVEYARD";
|
||||||
|
|
||||||
export const setUserId = (user_id) => {
|
export const setUserId = (user_id) => {
|
||||||
return {
|
return {
|
||||||
@ -29,6 +30,7 @@ export const setGame = (data) => {
|
|||||||
board: data.board,
|
board: data.board,
|
||||||
turn: data.turn,
|
turn: data.turn,
|
||||||
moves: data.moves,
|
moves: data.moves,
|
||||||
|
graveyard: data.graveyard,
|
||||||
state: data.state,
|
state: data.state,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -60,3 +62,10 @@ export const setOpponentStatus = (opponentStatus) => {
|
|||||||
opponentStatus,
|
opponentStatus,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setGraveyard = (graveyard) => {
|
||||||
|
return {
|
||||||
|
type: SET_GRAVEYARD,
|
||||||
|
graveyard,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@ -25,6 +25,7 @@ const defaultState = {
|
|||||||
2: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
2: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
||||||
1: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
1: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
||||||
},
|
},
|
||||||
|
graveyard: { "white": [], "black": [] }
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defaultState;
|
export default defaultState;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ defmodule Chess.Store.Move do
|
|||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
alias Chess.Store.Game
|
alias Chess.Store.Game
|
||||||
|
alias Chess.Store.Move
|
||||||
|
|
||||||
schema "moves" do
|
schema "moves" do
|
||||||
field :from, :map
|
field :from, :map
|
||||||
@ -39,6 +40,7 @@ defmodule Chess.Store.Move do
|
|||||||
|
|
||||||
def captures_for_colour(query, colour) do
|
def captures_for_colour(query, colour) do
|
||||||
from move in query,
|
from move in query,
|
||||||
|
select: move.piece_captured,
|
||||||
where: fragment("(piece_captured -> 'colour')::jsonb = ?", ^colour)
|
where: fragment("(piece_captured -> 'colour')::jsonb = ?", ^colour)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user