Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow file loading using CLI argument #326

Merged
merged 3 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/featurecat/lizzie/Lizzie.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public static void main(String[] args) throws IOException, JSONException, ClassN
if(config.handicapInsteadOfWinrate) {
leelaz.estimatePassWinrate();
}
if (config.config.getJSONObject("ui").getBoolean("resume-previous-game")) {
if (args.length == 1) {
frame.loadFile(new File(args[0]));
} else if (config.config.getJSONObject("ui").getBoolean("resume-previous-game")) {
board.resumePreviousGame();
}
leelaz.togglePonder();
Expand All @@ -67,15 +69,15 @@ public static void main(String[] args) throws IOException, JSONException, ClassN
}
}).start();


}

public static void shutdown() {
PluginManager.onShutdown();
if (board != null && config.config.getJSONObject("ui").getBoolean("confirm-exit")) {
int ret = JOptionPane.showConfirmDialog(null, "Do you want to save this SGF?", "Save SGF?", JOptionPane.OK_CANCEL_OPTION);
if (ret == JOptionPane.OK_OPTION) {
LizzieFrame.saveSgf();
LizzieFrame.saveFile();
}
}
if (board != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void keyPressed(KeyEvent e) {
undo();
}
break;

case VK_PAGE_DOWN:
if (controlIsPressed(e) && e.isShiftDown()) {
Lizzie.frame.increaseMaxAlpha(-5);
Expand Down Expand Up @@ -247,7 +247,7 @@ public void keyPressed(KeyEvent e) {
case VK_H:
Lizzie.config.toggleHandicapInsteadOfWinrate();
break;

case VK_PAGE_UP:
if (controlIsPressed(e) && e.isShiftDown()) {
Lizzie.frame.increaseMaxAlpha(5);
Expand All @@ -266,13 +266,13 @@ public void keyPressed(KeyEvent e) {
// stop the ponder
if (Lizzie.leelaz.isPondering())
Lizzie.leelaz.togglePonder();
LizzieFrame.saveSgf();
LizzieFrame.saveFile();
break;

case VK_O:
if (Lizzie.leelaz.isPondering())
Lizzie.leelaz.togglePonder();
LizzieFrame.openSgf();
LizzieFrame.openFile();
break;

case VK_V:
Expand Down
45 changes: 24 additions & 21 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public LizzieFrame() {
variationTree = new VariationTree();
winrateGraph = new WinrateGraph();

setMinimumSize( new Dimension(640,480) );
setMinimumSize( new Dimension(640,480) );
setLocationRelativeTo(null); // start centered
JSONArray windowSize = Lizzie.config.uiConfig.getJSONArray("window-size");
setSize(windowSize.getInt(0), windowSize.getInt(1)); // use config file window size
Expand Down Expand Up @@ -185,7 +185,7 @@ public static void editGameInfo() {
gameInfoDialog.dispose();
}

public static void saveSgf() {
public static void saveFile() {
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.sgf", "SGF");
JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem");
JFileChooser chooser = new JFileChooser(filesystem.getString("last-folder"));
Expand All @@ -207,36 +207,39 @@ public static void saveSgf() {
SGFParser.save(Lizzie.board, file.getPath());
filesystem.put("last-folder", file.getParent());
} catch (IOException err) {
JOptionPane.showConfirmDialog(null, resourceBundle.getString("LizzieFrame.prompt.failedToSaveSgf"), "Error", JOptionPane.ERROR);
JOptionPane.showConfirmDialog(null, resourceBundle.getString("LizzieFrame.prompt.failedTosaveFile"), "Error", JOptionPane.ERROR);
}
}
}

public static void openSgf() {
public static void openFile() {
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.sgf or *.gib", "SGF", "GIB");
JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem");
JFileChooser chooser = new JFileChooser(filesystem.getString("last-folder"));

chooser.setFileFilter(filter);
chooser.setMultiSelectionEnabled(false);
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!(file.getPath().endsWith(".sgf") || file.getPath().endsWith(".gib"))) {
file = new File(file.getPath() + ".sgf");
}
try {
System.out.println(file.getPath());
if (file.getPath().endsWith(".sgf")) {
SGFParser.load(file.getPath());
} else {
GIBParser.load(file.getPath());
}
filesystem.put("last-folder", file.getParent());
} catch (IOException err) {
JOptionPane.showConfirmDialog(null, resourceBundle.getString("LizzieFrame.prompt.failedToOpenSgf"), "Error", JOptionPane.ERROR);
}
}
if (result == JFileChooser.APPROVE_OPTION)
loadFile(chooser.getSelectedFile());
}

public static void loadFile(File file) {
JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem");
if (!(file.getPath().endsWith(".sgf") || file.getPath().endsWith(".gib"))) {
file = new File(file.getPath() + ".sgf");
}
try {
System.out.println(file.getPath());
if (file.getPath().endsWith(".sgf")) {
SGFParser.load(file.getPath());
} else {
GIBParser.load(file.getPath());
}
filesystem.put("last-folder", file.getParent());
} catch (IOException err) {
JOptionPane.showConfirmDialog(null, resourceBundle.getString("LizzieFrame.prompt.failedToOpenFile"), "Error", JOptionPane.ERROR);
}
}

private BufferedImage cachedImage = null;
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ LizzieFrame.commands.keyW=w|toggle winrate display
LizzieFrame.commands.keyPeriod=.|score game
LizzieFrame.commands.mouseWheelScroll=scrollwheel|undo/redo
LizzieFrame.commands.rightClick=right click|undo
LizzieFrame.prompt.failedToOpenSgf=Failed to open the SGF file.
LizzieFrame.prompt.failedToSaveSgf=Failed to save the SGF file.
LizzieFrame.prompt.failedToOpenFile=Failed to open file.
LizzieFrame.prompt.failedToSaveFile=Failed to save file.
LizzieFrame.prompt.sgfExists=The SGF file already exists, do you want to replace it?
LizzieFrame.prompt.showControlsHint=hold x = view controls
LizzieFrame.display.lastMove=Last move
LizzieFrame.display.pondering=Pondering
LizzieFrame.display.pondering=Pondering
LizzieFrame.display.on=on
LizzieFrame.display.off=off
LizzieFrame.display.loading=Leela Zero is loading...
LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time.
LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage
LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage
LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage
4 changes: 2 additions & 2 deletions src/main/resources/l10n/DisplayStrings_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ LizzieFrame.commands.keyW=w|\u663E\u793A/\u9690\u85CF\u80DC\u7387\u56FE
LizzieFrame.commands.keyPeriod=.(\u5C0F\u6570\u70B9)|\u70B9\u76EE
LizzieFrame.commands.mouseWheelScroll=\u9F20\u6807\u6EDA\u8F6E|\u5728\u68CB\u8C31\u4E2D\u5411\u524D/\u5411\u540E\u79FB\u52A8
LizzieFrame.commands.rightClick=\u9F20\u6807\u53F3\u952E|\u56DE\u4E0A\u4E00\u624B
LizzieFrame.prompt.failedToOpenSgf=\u4E0D\u80FD\u6253\u5F00SGF\u6587\u4EF6.
LizzieFrame.prompt.failedToSaveSgf=\u4E0D\u80FD\u4FDD\u5B58SGF\u6587\u4EF6.
LizzieFrame.prompt.failedToOpenFile=\u4E0D\u80FD\u6253\u5F00SGF\u6587\u4EF6.
LizzieFrame.prompt.failedToSaveFile=\u4E0D\u80FD\u4FDD\u5B58SGF\u6587\u4EF6.
LizzieFrame.prompt.sgfExists=SGF\u6587\u4EF6\u5DF2\u7ECF\u5B58\u5728, \u9700\u8981\u66FF\u6362\u5417?
LizzieFrame.prompt.showControlsHint=\u6309\u4F4FX\u4E0D\u653E\u67E5\u770B\u5FEB\u6377\u952E\u63D0\u793A
LizzieFrame.display.lastMove=\u6700\u540E\u4E00\u624B
Expand Down