Fixed engine menu reloading on engine addition

This commit is contained in:
Kai S. K. Engelbart 2019-07-24 19:07:22 +02:00
parent 36832733b6
commit 4c0432ca30
3 changed files with 9 additions and 5 deletions

View File

@ -103,8 +103,6 @@ public class Board implements Cloneable {
Piece piece = getPos(move);
Piece capturePiece = getDest(move);
// TODO: reset halfmove clock
switch (move.type) {
case PAWN_PROMOTION:
setPos(move, null);

View File

@ -30,7 +30,7 @@ public class EngineUtil {
private EngineUtil() {}
public static void addEngine(String enginePath) {
public static void addEngine(String enginePath, Runnable followup) {
try {
EngineInfo info = new EngineInfo(enginePath);
UCIHandle handle = new UCIHandle(enginePath);
@ -51,6 +51,7 @@ public class EngineUtil {
engineInfos.add(info);
handle.quit();
saveEngineInfos();
followup.run();
}
});
handle.start();

View File

@ -81,8 +81,13 @@ public class MenuBar extends JMenuBar {
"Engine selection",
JOptionPane.QUESTION_MESSAGE);
if (enginePath != null) {
EngineUtil.addEngine(enginePath);
// TODO: Rebuilt the engine menu
EngineUtil.addEngine(enginePath, () -> {
EngineInfo info = EngineUtil.getEngineInfos()
.get(EngineUtil.getEngineInfos().size() - 1);
JMenuItem engineMenuItem = new JMenuItem(info.name);
engineMenuItem.addActionListener((evt2) -> startGame(Game.createUCI(boardPane, info.path)));
engineMenu.add(engineMenuItem);
});
}
});
engineMenu.add(addEngineMenuItem);