GameBoard: move
This commit is contained in:
parent
ae6ba413a2
commit
579f52ed04
@ -9,11 +9,14 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.CordaClient;
|
import djmil.cordacheckers.cordaclient.CordaClient;
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameView;
|
import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||||
|
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove;
|
||||||
|
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
import djmil.cordacheckers.user.User;
|
import djmil.cordacheckers.user.User;
|
||||||
|
|
||||||
@ -92,4 +95,21 @@ public class GameController {
|
|||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.ok(drawRejGame);
|
.ok(drawRejGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{uuid}/move")
|
||||||
|
public ResponseEntity<GameView> move(
|
||||||
|
@AuthenticationPrincipal User issuer,
|
||||||
|
@PathVariable UUID uuid,
|
||||||
|
@RequestBody ReqGameBoardMove request
|
||||||
|
) {
|
||||||
|
final GameView movedGame = cordaClient.gameBoardMove(
|
||||||
|
issuer.getHoldingIdentity(),
|
||||||
|
uuid,
|
||||||
|
request.move(),
|
||||||
|
request.message()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity
|
||||||
|
.ok(movedGame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ export default function useGamesApi(gamesReducer, config) {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
pushGameMove: ({ uuid, move, message }) => ifNot(games.isPushingGameMove) &&
|
pushGameMove: ({ uuid, move, message }) => ifNot(games.isPushingGameMove) &&
|
||||||
doPushing(`/api/game/${uuid}/move`, 'PUT', null, {
|
doPushing(`/api/game/${uuid}/move`, 'PUT', { move, message }, {
|
||||||
onPushing: (isPushingGameMove) => dispatchGames({ type: 'next', isPushingGameMove }),
|
onPushing: (isPushingGameMove) => dispatchGames({ type: 'next', isPushingGameMove }),
|
||||||
onSuccess: (game) => dispatchGames({ type: 'next', gamesList: games.nextGame(game), active: gamesInitialState.active })
|
onSuccess: (game) => dispatchGames({ type: 'next', gamesList: games.nextGame(game), active: gamesInitialState.active })
|
||||||
}),
|
}),
|
||||||
|
@ -119,7 +119,7 @@ function GameBoardRoutes({ gamesReducer, gamesApi, username }) {
|
|||||||
dispatchGames({ type: 'nextNewGame', board });
|
dispatchGames({ type: 'nextNewGame', board });
|
||||||
}
|
}
|
||||||
|
|
||||||
const onStoneMove = (uuid, move) => console.log(uuid, 'move', move);
|
const onStoneMove = (uuid, move) => gamesApi.pushGameMove({uuid, move, message: games.active.message});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
|
@ -33,6 +33,7 @@ export default function GameBoard({ username, onStoneClick, onStoneMove }) {
|
|||||||
<Player color={opponentColor || Color.black} name={opponentName} />
|
<Player color={opponentColor || Color.black} name={opponentName} />
|
||||||
<Board game={game} onStoneClick={onStoneClick} onStoneMove={onStoneMove} />
|
<Board game={game} onStoneClick={onStoneClick} onStoneMove={onStoneMove} />
|
||||||
<Player color={game?.myColor || Color.white} name={myName} />
|
<Player color={game?.myColor || Color.white} name={myName} />
|
||||||
|
{ games.isPushingGameMove ? <span>Moving...</span> : null}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user