feat: working pgn simulation
All checks were successful
Linux arm64 / Build (push) Successful in 56s
All checks were successful
Linux arm64 / Build (push) Successful in 56s
This commit is contained in:
@@ -3,6 +3,7 @@ package chess;
|
|||||||
import chess.controller.CommandExecutor;
|
import chess.controller.CommandExecutor;
|
||||||
import chess.controller.commands.NewGameCommand;
|
import chess.controller.commands.NewGameCommand;
|
||||||
import chess.model.Game;
|
import chess.model.Game;
|
||||||
|
import chess.pgn.PgnFileSimulator;
|
||||||
import chess.view.DDDrender.DDDView;
|
import chess.view.DDDrender.DDDView;
|
||||||
|
|
||||||
public class OpenGLMain {
|
public class OpenGLMain {
|
||||||
@@ -10,8 +11,12 @@ public class OpenGLMain {
|
|||||||
Game game = new Game();
|
Game game = new Game();
|
||||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||||
|
|
||||||
|
PgnFileSimulator fileSimulator = new PgnFileSimulator(commandExecutor, "games/FoolCheckmate.pgn");
|
||||||
|
|
||||||
DDDView ddd = new DDDView(commandExecutor);
|
DDDView ddd = new DDDView(commandExecutor);
|
||||||
|
|
||||||
commandExecutor.addListener(ddd);
|
commandExecutor.addListener(ddd);
|
||||||
|
commandExecutor.addListener(fileSimulator);
|
||||||
|
|
||||||
commandExecutor.executeCommand(new NewGameCommand());
|
commandExecutor.executeCommand(new NewGameCommand());
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class Camera {
|
|||||||
|
|
||||||
public Camera() {
|
public Camera() {
|
||||||
this.pos = new Vector3f(0.0f, camHeight, 0.0f);
|
this.pos = new Vector3f(0.0f, camHeight, 0.0f);
|
||||||
setRotateAngle(0.0f);
|
setRotateAngle((float) Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(float x, float y) {
|
public void move(float x, float y) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import chess.controller.commands.*;
|
import chess.controller.commands.*;
|
||||||
|
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImBoolean;
|
import imgui.type.ImBoolean;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
@@ -22,6 +23,7 @@ import chess.model.Piece;
|
|||||||
import chess.view.DDDrender.world.BoardEntity;
|
import chess.view.DDDrender.world.BoardEntity;
|
||||||
import chess.view.DDDrender.world.PieceEntity;
|
import chess.view.DDDrender.world.PieceEntity;
|
||||||
import chess.view.DDDrender.world.World;
|
import chess.view.DDDrender.world.World;
|
||||||
|
import common.Signal0;
|
||||||
|
|
||||||
public class DDDView extends GameAdapter implements CommandSender {
|
public class DDDView extends GameAdapter implements CommandSender {
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
private static final Vector3f WHITE = new Vector3f(1.0f, 1.0f, 1.0f);
|
private static final Vector3f WHITE = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||||
private static final Vector3f RED = new Vector3f(1.0f, 0.0f, 0.0f);
|
private static final Vector3f RED = new Vector3f(1.0f, 0.0f, 0.0f);
|
||||||
private static final Vector3f YELLOW = new Vector3f(1.0f, 1.0f, 0.0f);
|
private static final Vector3f YELLOW = new Vector3f(1.0f, 1.0f, 0.0f);
|
||||||
|
private static final Vector3f BLUE = new Vector3f(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
private final CommandExecutor commandExecutor;
|
private final CommandExecutor commandExecutor;
|
||||||
private final Window window;
|
private final Window window;
|
||||||
@@ -37,7 +40,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
private final Camera camera;
|
private final Camera camera;
|
||||||
private Coordinate click = null;
|
private Coordinate click = null;
|
||||||
|
|
||||||
private static final float animationTime = 1.5f; // in seconds
|
private static final float animationTime = 0.5f; // in seconds
|
||||||
private static final int animationTurns = 1;
|
private static final int animationTurns = 1;
|
||||||
|
|
||||||
private float moveProgress = 0.0f;
|
private float moveProgress = 0.0f;
|
||||||
@@ -45,6 +48,8 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
private String waitingPopup = null;
|
private String waitingPopup = null;
|
||||||
private final ImBoolean popupOpened = new ImBoolean(false);
|
private final ImBoolean popupOpened = new ImBoolean(false);
|
||||||
|
|
||||||
|
public final Signal0 OnReady = new Signal0();
|
||||||
|
|
||||||
public DDDView(CommandExecutor commandExecutor) {
|
public DDDView(CommandExecutor commandExecutor) {
|
||||||
this.commandExecutor = commandExecutor;
|
this.commandExecutor = commandExecutor;
|
||||||
this.world = new World();
|
this.world = new World();
|
||||||
@@ -75,6 +80,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
}
|
}
|
||||||
setClick(coordinate);
|
setClick(coordinate);
|
||||||
previewMoves(coordinate);
|
previewMoves(coordinate);
|
||||||
|
// this.boardEntity.setCellColor(coordinate, BLUE);
|
||||||
System.out.println("First click on " + coordinate);
|
System.out.println("First click on " + coordinate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -127,15 +133,17 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
if (this.click == null) {
|
if (this.click == null) {
|
||||||
// small test turning a cell red when hovered
|
// small test turning a cell red when hovered
|
||||||
this.boardEntity.setCellColor(coordinate, RED);
|
this.boardEntity.setCellColor(coordinate, RED);
|
||||||
Piece p = pieceAt(coordinate);
|
|
||||||
if (p == null)
|
PieceEntity pEntity = this.world.getPiece(coordinate);
|
||||||
|
if (pEntity == null)
|
||||||
return;
|
return;
|
||||||
this.world.getPiece(coordinate).setColor(RED);
|
|
||||||
|
pEntity.setColor(RED);
|
||||||
List<Coordinate> allowedMoves = getPieceAllowedMoves(coordinate);
|
List<Coordinate> allowedMoves = getPieceAllowedMoves(coordinate);
|
||||||
if (allowedMoves.isEmpty())
|
if (allowedMoves.isEmpty())
|
||||||
return;
|
return;
|
||||||
for (Coordinate destCoord : allowedMoves) {
|
for (Coordinate destCoord : allowedMoves) {
|
||||||
this.boardEntity.setCellColor(destCoord, RED);
|
this.boardEntity.setCellColor(destCoord, YELLOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +155,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
Piece p = pieceAt(coordinate);
|
Piece p = pieceAt(coordinate);
|
||||||
if (p == null)
|
if (p == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PieceEntity pEntity = this.world.getPiece(coordinate);
|
PieceEntity pEntity = this.world.getPiece(coordinate);
|
||||||
if (pEntity == null)
|
if (pEntity == null)
|
||||||
return;
|
return;
|
||||||
@@ -195,7 +204,20 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
this.window.OnCellExit.connect(this::onCellExit);
|
this.window.OnCellExit.connect(this::onCellExit);
|
||||||
this.window.OnImGuiTopRender.connect(this::onHeaderRender);
|
this.window.OnImGuiTopRender.connect(this::onHeaderRender);
|
||||||
this.window.OnImGuiBottomRender.connect(this::onFooterRender);
|
this.window.OnImGuiBottomRender.connect(this::onFooterRender);
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
try {
|
||||||
|
wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onHeaderRender() {
|
private void onHeaderRender() {
|
||||||
@@ -291,14 +313,14 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
this.moveProgress = 0.0f;
|
this.moveProgress = 0.0f;
|
||||||
|
|
||||||
Consumer<Float> moveConsumer = (delta) -> {
|
Consumer<Float> moveConsumer = (delta) -> {
|
||||||
this.moveProgress += delta;
|
this.moveProgress += delta / animationTime;
|
||||||
pieceTick(this.moveProgress, pEntity, pMove);
|
pieceTick(this.moveProgress, pEntity, pMove);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.window.addRegularTask(moveConsumer);
|
this.window.addRegularTask(moveConsumer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep((long) (animationTime * 1000.0f));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
this.window.removeRegularTask(moveConsumer);
|
this.window.removeRegularTask(moveConsumer);
|
||||||
@@ -314,7 +336,6 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
@Override
|
@Override
|
||||||
public void onMove(Move move, boolean captured) {
|
public void onMove(Move move, boolean captured) {
|
||||||
move3DPiece(move);
|
move3DPiece(move);
|
||||||
cameraRotate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cameraTick(float delta) {
|
private void cameraTick(float delta) {
|
||||||
@@ -336,6 +357,11 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
this.camera.setRotateAngle(end);
|
this.camera.setRotateAngle(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerTurn(Color color, boolean undone) {
|
||||||
|
cameraRotate();
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
this.window.run();
|
this.window.run();
|
||||||
|
|
||||||
@@ -403,4 +429,9 @@ public class DDDView extends GameAdapter implements CommandSender {
|
|||||||
openPopup(color == Color.White ? "White surrender" : "Black surrender");
|
openPopup(color == Color.White ? "White surrender" : "Black surrender");
|
||||||
openPopup(color == Color.White ? "Black victory" : "White victory");
|
openPopup(color == Color.White ? "Black victory" : "White victory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCastling(boolean bigCastling) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user