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 3be4c042bb
commit b99c0f67f0
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
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 piece = getPos(move);
Piece capturePiece = getDest(move); Piece capturePiece = getDest(move);
// TODO: reset halfmove clock
switch (move.type) { switch (move.type) {
case PAWN_PROMOTION: case PAWN_PROMOTION:
setPos(move, null); setPos(move, null);

View File

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

View File

@ -81,8 +81,13 @@ public class MenuBar extends JMenuBar {
"Engine selection", "Engine selection",
JOptionPane.QUESTION_MESSAGE); JOptionPane.QUESTION_MESSAGE);
if (enginePath != null) { if (enginePath != null) {
EngineUtil.addEngine(enginePath); EngineUtil.addEngine(enginePath, () -> {
// TODO: Rebuilt the engine menu 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); engineMenu.add(addEngineMenuItem);