kaorahi / lizgoban

Leela Zero & KataGo visualizer
GNU General Public License v3.0
169 stars 28 forks source link

Can we go back to the sgf_from_image page again? #111

Closed qcgm1978 closed 7 months ago

qcgm1978 commented 7 months ago

When I use the Paste image function, I often find that the generated sgf is incorrect. I want to have the option to go back to the sgf_from_image page and make changes. Currently, the page closes when I click OK. It would be better if the page was hidden instead of closed, and then reopened when needed. In addition to adding an option in the app menu, a right-click menu with an editing option could also be considered for the page.

Here is a demonstration of the function and the core code:

https://github.com/kaorahi/lizgoban/assets/3024299/6a4d45f0-477d-4ab3-bf56-99566b64f41e

// hide page window
if (image_win && image_win.isVisible()) {
    image_win.hide()
}
// context menu
menu = new Menu();
const items = [{
    label: lang.edit,
    click: () => {
        image_win.show()
},
},...];
items.forEach(item => {
    menu.append(new MenuItem(item));
});
mainWindow.contextMenu = menu;
kaorahi commented 7 months ago

Sounds nice. I prefer everything be undoable.

I've implemented this locally and will push it after dogfooding for a while.

Also, a free-editing feature is already available. Place a black or white stone using b key + click or w key + click. To remove an existing stone, press either b or w key and click on it. This is described in the Help section under Display > Board > Mouse controls.

qcgm1978 commented 7 months ago

I noticed the keyboard shortcuts for adding and removing stones, but I think it's easier to use the mouse to do it directly on the page. This is because it's more in line with the WYSIWYG principle, which means what you see is what you get.

kaorahi commented 7 months ago

We need to add the following code to the definition of new_window().

    // Hidden sgf_from_image windows prevent 'window-all-closed' event.
    // So we need an explicit check here for a clean exit.
    win.on('closed', () => empty(get_windows()) && electron.app.quit())
qcgm1978 commented 7 months ago

I discovered that it is important to modify read_sgf to replace_sequence if returned from sgf_from_image page. Otherwise, it will always create a new board. It should be determined whether to create a new board based on the sequence_cursor. However, it increases the complexity of the code. For example:

// main.js
image_win.webContents.on('did-finish-load', () => {
    image_win.webContents.send('set_sequence_cursor', sequence_cursor);
});
function memorize_settings_for_sgf_from_image(settings) {
    the_settings_for_sgf_from_image = settings
    img_sequence_cursor = sequence_cursor
    hide_img_win();
}
function backup_and_replace_game(new_game, before, delete_future_p) {
    (game.is_empty() || img_sequence_cursor == sequence_cursor) ? replace_sequence(new_game) : insert_sequence(new_game, before)
    ...
// sgf_from_image.js
let sequence_cursor
function set_sequence_cursor(dummy_ipc_event, id) {
    sequence_cursor = id
};
function finish_electron() {
    ...
    send('memorize_settings_for_sgf_from_image', {...settings,sequence_cursor})
kaorahi commented 7 months ago

implemented