feat: working castling
All checks were successful
Linux arm64 / Build (push) Successful in 47s

This commit is contained in:
2025-05-17 18:51:23 +02:00
parent 01f0caf672
commit 646eb6492e
11 changed files with 63 additions and 44 deletions

View File

@@ -1,12 +1,12 @@
package chess.view.DDDrender;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import chess.controller.commands.*;
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
import imgui.ImGui;
import imgui.type.ImBoolean;
import org.joml.Vector2f;
@@ -48,8 +48,6 @@ public class DDDView extends GameAdapter implements CommandSender {
private String waitingPopup = null;
private final ImBoolean popupOpened = new ImBoolean(false);
public final Signal0 OnReady = new Signal0();
public DDDView(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.world = new World();
@@ -225,14 +223,13 @@ public class DDDView extends GameAdapter implements CommandSender {
}
private void onFooterRender() {
CastlingResult allowedCastlings = getAllowedCastlings();
ImGui.beginDisabled(allowedCastlings == CastlingResult.None || allowedCastlings == CastlingResult.Big);
ImGui.beginDisabled(!canDoCastling());
if (ImGui.button("Roque")) {
sendCastling();
}
ImGui.endDisabled();
ImGui.sameLine();
ImGui.beginDisabled(allowedCastlings == CastlingResult.None || allowedCastlings == CastlingResult.Small);
ImGui.beginDisabled(!canDoBigCastling());
if (ImGui.button("Grand Roque")) {
sendBigCastling();
}
@@ -303,39 +300,52 @@ public class DDDView extends GameAdapter implements CommandSender {
piece.setPosition(bezierCurve(start, top, end, progress));
}
private void move3DPiece(Move move) {
Vector2f pieceDestBoardPos = DDDPlacement.coordinatesToVector(move.getFinish());
Vector3f pieceDestWorldPos = new Vector3f(pieceDestBoardPos.x(), 0, pieceDestBoardPos.y());
final PieceEntity pEntity = this.world.getPiece(move.getStart());
final Move pMove = move;
private void move3DPieces(List<Move> moves) {
final List<PieceEntity> pEntities = new ArrayList<>(moves.size());
final List<Consumer<Float>> consumers = new ArrayList<>(moves.size());
this.moveProgress = 0.0f;
Consumer<Float> moveConsumer = (delta) -> {
this.moveProgress += delta / animationTime;
pieceTick(this.moveProgress, pEntity, pMove);
};
this.window.addRegularTask(moveConsumer);
for (Move move : moves) {
final PieceEntity pEntity = this.world.getPiece(move.getStart());
final Consumer<Float> moveConsumer = (delta) -> {
this.moveProgress += delta / animationTime / (float) moves.size();
pieceTick(this.moveProgress, pEntity, move);
};
pEntities.add(pEntity);
consumers.add(moveConsumer);
this.window.addRegularTask(moveConsumer);
}
try {
Thread.sleep((long) (animationTime * 1000.0f));
} catch (InterruptedException e) {
}
this.window.removeRegularTask(moveConsumer);
if (move.getDeadPieceCoords() != null) {
this.world.ejectPiece(move.getDeadPieceCoords());
for (int i = 0; i < moves.size(); i++) {
final Move move = moves.get(i);
final Consumer<Float> moveConsumer = consumers.get(i);
final PieceEntity pEntity = pEntities.get(i);
this.window.removeRegularTask(moveConsumer);
Vector2f pieceDestBoardPos = DDDPlacement.coordinatesToVector(move.getFinish());
Vector3f pieceDestWorldPos = new Vector3f(pieceDestBoardPos.x(), 0, pieceDestBoardPos.y());
if (move.getDeadPieceCoords() != null) {
this.world.ejectPiece(move.getDeadPieceCoords());
}
pEntity.setPosition(pieceDestWorldPos);
this.world.movePiece(pEntity, move);
}
pEntity.setPosition(pieceDestWorldPos);
this.world.movePiece(pEntity, move);
}
@Override
public void onMove(Move move, boolean captured) {
move3DPiece(move);
move3DPieces(List.of(move));
}
private void cameraTick(float delta) {
@@ -349,7 +359,7 @@ public class DDDView extends GameAdapter implements CommandSender {
Consumer<Float> rotationConsumer = this::cameraTick;
this.window.addRegularTask(rotationConsumer);
try {
Thread.sleep((long) (animationTime * 1000));
Thread.sleep((long) (animationTime * 1000.0f));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -431,7 +441,7 @@ public class DDDView extends GameAdapter implements CommandSender {
}
@Override
public void onCastling(boolean bigCastling) {
public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) {
move3DPieces(List.of(kingMove, rookMove));
}
}