Simplified EngineUtil and MenuBar
This commit is contained in:
parent
1a7abafc28
commit
6b6bda32ee
@ -30,7 +30,7 @@ public class EngineUtil {
|
||||
|
||||
private EngineUtil() {}
|
||||
|
||||
public static void addEngine(String enginePath, Runnable followup) {
|
||||
public static void addEngine(String enginePath) {
|
||||
try {
|
||||
EngineInfo info = new EngineInfo(enginePath);
|
||||
UCIHandle handle = new UCIHandle(enginePath);
|
||||
@ -51,7 +51,6 @@ public class EngineUtil {
|
||||
engineInfos.add(info);
|
||||
handle.quit();
|
||||
saveEngineInfos();
|
||||
followup.run();
|
||||
}
|
||||
});
|
||||
handle.start();
|
||||
|
@ -9,7 +9,6 @@ import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import dev.kske.chess.game.Game;
|
||||
import dev.kske.chess.ui.EngineUtil.EngineInfo;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
@ -52,37 +51,19 @@ public class MenuBar extends JMenuBar {
|
||||
private void initEngineMenu() {
|
||||
JMenu engineMenu = new JMenu("Engine");
|
||||
|
||||
// TODO: Adjust menu
|
||||
|
||||
JMenuItem addEngineMenuItem = new JMenuItem("Add engine");
|
||||
addEngineMenuItem.addActionListener((evt) -> {
|
||||
String enginePath = JOptionPane.showInputDialog(getParent(),
|
||||
"Enter the path to a UCI-compatible chess engine:",
|
||||
"Engine selection",
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if (enginePath != null) {
|
||||
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);
|
||||
*/
|
||||
});
|
||||
}
|
||||
if (enginePath != null) EngineUtil.addEngine(enginePath);
|
||||
});
|
||||
engineMenu.add(addEngineMenuItem);
|
||||
|
||||
/*
|
||||
* for (EngineInfo info : EngineUtil.getEngineInfos()) {
|
||||
* JMenuItem engineMenuItem = new JMenuItem(info.name);
|
||||
* engineMenuItem.addActionListener((evt) -> startGame(Game.createUCI(boardPane,
|
||||
* info.path)));
|
||||
* engineMenu.add(engineMenuItem);
|
||||
* }
|
||||
*/
|
||||
JMenuItem showInfoMenuItem = new JMenuItem("Show engine info");
|
||||
|
||||
engineMenu.add(addEngineMenuItem);
|
||||
engineMenu.add(showInfoMenuItem);
|
||||
add(engineMenu);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user