fix coloring bug on double click

This commit is contained in:
Janet-Doe
2025-05-14 16:46:12 +02:00
parent 264391ba81
commit 39c7ebefe6

View File

@@ -52,6 +52,16 @@ public class DDDView extends GameAdaptator implements GameListener {
// Invoked when a cell is clicked // Invoked when a cell is clicked
private void onCellClick(Coordinate coordinate) { private void onCellClick(Coordinate coordinate) {
if (this.click == null){ // case: first click if (this.click == null){ // case: first click
GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(coordinate);
if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move
System.out.println("Nothing to do here.");
return;
}
List<Coordinate> allowedMoves = movesCommand.getDestinations();
if (allowedMoves.isEmpty()) { // case: no movement possible for piece
System.out.println("This piece cannot be moved at the moment.");
return;
}
setClick(coordinate); setClick(coordinate);
previewMoves(coordinate); previewMoves(coordinate);
System.out.println("First click on " + coordinate); System.out.println("First click on " + coordinate);
@@ -60,12 +70,14 @@ public class DDDView extends GameAdaptator implements GameListener {
// case: second click // case: second click
GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(this.click); GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(this.click);
if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move
cancelPreview(this.click);
System.out.println("Nothing to do here."); System.out.println("Nothing to do here.");
cancelClick(); cancelClick();
return; return;
} }
List<Coordinate> allowedMoves = movesCommand.getDestinations(); List<Coordinate> allowedMoves = movesCommand.getDestinations();
if (allowedMoves.isEmpty()) { // case: no movement possible for piece if (allowedMoves.isEmpty()) { // case: no movement possible for piece
cancelPreview(this.click);
System.out.println("This piece cannot be moved at the moment."); System.out.println("This piece cannot be moved at the moment.");
cancelClick(); cancelClick();
return; return;
@@ -85,19 +97,20 @@ public class DDDView extends GameAdaptator implements GameListener {
return; return;
} }
System.out.println("Cancelling click."); // case: cancelling previous click System.out.println("Cancelling click."); // case: cancelling previous click
cancelPreview(this.click);
cancelClick(); cancelClick();
} }
private void previewMoves(Coordinate coordinate){ private void previewMoves(Coordinate coordinate){
this.boardEntity.setCellColor(coordinate, new Vector3f(1, 0, 0));
Piece p = pieceAt(coordinate); Piece p = pieceAt(coordinate);
if (p == null) if (p == null) {
return; return;
this.world.getPiece(coordinate).setColor(new Vector3f(1, 0, 0)); }
GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(coordinate); GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(coordinate);
if (sendCommand(movesCommand) == CommandResult.NotAllowed) if (sendCommand(movesCommand) == CommandResult.NotAllowed) {
return; return;
}
this.boardEntity.setCellColor(coordinate, new Vector3f(1, 0, 0));
this.world.getPiece(coordinate).setColor(new Vector3f(1, 0, 0));
List<Coordinate> allowedMoves = movesCommand.getDestinations(); List<Coordinate> allowedMoves = movesCommand.getDestinations();
if (allowedMoves.isEmpty()) if (allowedMoves.isEmpty())
return; return;