From bc05fb1f5b19be50d95dc22803fc89a5481d2723 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Wed, 18 Mar 2020 21:08:02 +0900 Subject: [PATCH 1/6] Add option to select the coordinate type --- src/components/Goban.js | 17 ++++++- src/components/drawers/PreferencesDrawer.js | 53 ++++++++++++++++++++- src/modules/sabaki.js | 2 + src/setting.js | 1 + 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/components/Goban.js b/src/components/Goban.js index a4097c85b..8647c008b 100644 --- a/src/components/Goban.js +++ b/src/components/Goban.js @@ -12,6 +12,7 @@ import * as helper from '../modules/helper.js' const t = i18n.context('Goban') const setting = remote.require('./setting') const alpha = 'ABCDEFGHJKLMNOPQRSTUVWXYZ' +const alphaChinese = 'ABCDEFGHIJKLMNOPQRSTUVWXY' export default class Goban extends Component { constructor(props) { @@ -262,9 +263,21 @@ export default class Goban extends Component { board.height ) + let getCoordTransformer = coordinateType => { + if (coordinateType === 'japanese') { + return [x => x + 1, y => y + 1] + } else if (coordinateType === 'chinese') { + return [x => alphaChinese[x], y => y + 1] + } else { + return [x => alpha[x], y => board.height - y] // global + } + } + + let coordinateType = setting.get('board.coordinate_type') + let coordTransformer = getCoordTransformer(coordinateType) let {coordX, coordY} = gobantransformer.transformCoords( - x => alpha[x], - y => board.height - y, + coordTransformer[0], + coordTransformer[1], transformation, board.width, board.height diff --git a/src/components/drawers/PreferencesDrawer.js b/src/components/drawers/PreferencesDrawer.js index 94c5fd943..1b7e7ac9d 100644 --- a/src/components/drawers/PreferencesDrawer.js +++ b/src/components/drawers/PreferencesDrawer.js @@ -66,7 +66,8 @@ class GeneralTab extends Component { super(props) this.state = { - appLang: setting.get('app.lang') + appLang: setting.get('app.lang'), + coordinateType: setting.get('board.coordinate_type') } this.handleSoundEnabledChange = evt => { @@ -85,9 +86,15 @@ class GeneralTab extends Component { setting.set('app.lang', evt.currentTarget.value) } + this.handleCoordinateTypeChange = evt => { + setting.set('board.coordinate_type', evt.currentTarget.value) + } + setting.events.on(sabaki.window.id, 'change', ({key, value}) => { if (key === 'app.lang') { this.setState({appLang: value}) + } else if (key === 'board.coordinate_type') { + this.setState({coordinateType: value}) } }) } @@ -250,7 +257,49 @@ class GeneralTab extends Component { h(PreferencesItem, { id: 'view.winrategraph_invert', text: t('Invert winrate graph') - }) + }), + h( + 'li', + {class: 'select'}, + h( + 'label', + {}, + t('Coordinate Type:'), + ' ', + + h( + 'select', + {onChange: this.handleCoordinateTypeChange}, + + h( + 'option', + { + value: 'global', + selected: this.state.coordinateType === 'global' + }, + t('Global Type') + ), + + h( + 'option', + { + value: 'japanese', + selected: this.state.coordinateType === 'japanese' + }, + t('Japanese Type') + ), + + h( + 'option', + { + value: 'chinese', + selected: this.state.coordinateType === 'chinese' + }, + t('Chinese Type') + ) + ) + ) + ) ) ) } diff --git a/src/modules/sabaki.js b/src/modules/sabaki.js index e3b5b3792..84b847e26 100644 --- a/src/modules/sabaki.js +++ b/src/modules/sabaki.js @@ -59,6 +59,7 @@ class Sabaki extends EventEmitter { highlightVertices: [], playVariation: null, analysisType: null, + coordinateType: null, showAnalysis: null, showCoordinates: null, showMoveColorization: null, @@ -213,6 +214,7 @@ class Sabaki extends EventEmitter { 'app.zoom_factor': 'zoomFactor', 'board.analysis_type': 'analysisType', 'board.show_analysis': 'showAnalysis', + 'board.coordinate_type': 'coordinateType', 'view.show_menubar': 'showMenuBar', 'view.show_coordinates': 'showCoordinates', 'view.show_move_colorization': 'showMoveColorization', diff --git a/src/setting.js b/src/setting.js index 8d9151c4a..4fb053b78 100644 --- a/src/setting.js +++ b/src/setting.js @@ -47,6 +47,7 @@ let defaults = { 'board.show_analysis': true, 'board.variation_instant_replay': false, 'board.variation_replay_interval': 500, + 'board.coordinate_type': 'global', 'cleanmarkup.annotations': false, 'cleanmarkup.arrow': true, 'cleanmarkup.circle': true, From 532f37d43d81402c494bd283a9dd7b2fd60f9f00 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Wed, 18 Mar 2020 23:39:06 +0900 Subject: [PATCH 2/6] Moved the selection options to main menu. --- src/components/App.js | 1 + src/components/Goban.js | 10 ++-- src/components/drawers/PreferencesDrawer.js | 53 +-------------------- src/menu.js | 40 ++++++++++++++-- src/modules/sabaki.js | 4 +- src/setting.js | 2 +- 6 files changed, 47 insertions(+), 63 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index e8d0a67c0..d02cf448d 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -333,6 +333,7 @@ class App extends Component { analysisType: state.analysisType, showAnalysis: state.showAnalysis, showCoordinates: state.showCoordinates, + coordinatesType: state.coordinatesType, showMoveNumbers: state.showMoveNumbers, showMoveColorization: state.showMoveColorization, showNextMoves: state.showNextMoves, diff --git a/src/components/Goban.js b/src/components/Goban.js index 8647c008b..aa045d4bc 100644 --- a/src/components/Goban.js +++ b/src/components/Goban.js @@ -263,18 +263,18 @@ export default class Goban extends Component { board.height ) - let getCoordTransformer = coordinateType => { - if (coordinateType === 'japanese') { + let getCoordTransformer = coordinatesType => { + if (coordinatesType === 'japanese') { return [x => x + 1, y => y + 1] - } else if (coordinateType === 'chinese') { + } else if (coordinatesType === 'chinese') { return [x => alphaChinese[x], y => y + 1] } else { return [x => alpha[x], y => board.height - y] // global } } - let coordinateType = setting.get('board.coordinate_type') - let coordTransformer = getCoordTransformer(coordinateType) + let coordinatesType = setting.get('view.coordinates_type') + let coordTransformer = getCoordTransformer(coordinatesType) let {coordX, coordY} = gobantransformer.transformCoords( coordTransformer[0], coordTransformer[1], diff --git a/src/components/drawers/PreferencesDrawer.js b/src/components/drawers/PreferencesDrawer.js index 1b7e7ac9d..94c5fd943 100644 --- a/src/components/drawers/PreferencesDrawer.js +++ b/src/components/drawers/PreferencesDrawer.js @@ -66,8 +66,7 @@ class GeneralTab extends Component { super(props) this.state = { - appLang: setting.get('app.lang'), - coordinateType: setting.get('board.coordinate_type') + appLang: setting.get('app.lang') } this.handleSoundEnabledChange = evt => { @@ -86,15 +85,9 @@ class GeneralTab extends Component { setting.set('app.lang', evt.currentTarget.value) } - this.handleCoordinateTypeChange = evt => { - setting.set('board.coordinate_type', evt.currentTarget.value) - } - setting.events.on(sabaki.window.id, 'change', ({key, value}) => { if (key === 'app.lang') { this.setState({appLang: value}) - } else if (key === 'board.coordinate_type') { - this.setState({coordinateType: value}) } }) } @@ -257,49 +250,7 @@ class GeneralTab extends Component { h(PreferencesItem, { id: 'view.winrategraph_invert', text: t('Invert winrate graph') - }), - h( - 'li', - {class: 'select'}, - h( - 'label', - {}, - t('Coordinate Type:'), - ' ', - - h( - 'select', - {onChange: this.handleCoordinateTypeChange}, - - h( - 'option', - { - value: 'global', - selected: this.state.coordinateType === 'global' - }, - t('Global Type') - ), - - h( - 'option', - { - value: 'japanese', - selected: this.state.coordinateType === 'japanese' - }, - t('Japanese Type') - ), - - h( - 'option', - { - value: 'chinese', - selected: this.state.coordinateType === 'chinese' - }, - t('Chinese Type') - ) - ) - ) - ) + }) ) ) } diff --git a/src/menu.js b/src/menu.js index e8154103c..72011be5a 100644 --- a/src/menu.js +++ b/src/menu.js @@ -23,6 +23,7 @@ exports.get = function(props = {}) { analysisType, showAnalysis, showCoordinates, + coordinatesType, showMoveNumbers, showMoveColorization, showNextMoves, @@ -554,10 +555,41 @@ exports.get = function(props = {}) { {type: 'separator'}, { label: i18n.t('menu.view', 'Show &Coordinates'), - accelerator: 'CmdOrCtrl+Shift+C', - type: 'checkbox', - checked: !!showCoordinates, - click: () => toggleSetting('view.show_coordinates') + submenu: [ + { + label: i18n.t('menu.view', '&Don’t Show'), + type: 'checkbox', + checked: !showCoordinates, + click: () => setting.set('view.show_coordinates', false) + }, + { + label: i18n.t('menu.view', '&Global Coordinates'), + type: 'checkbox', + checked: !!showCoordinates && coordinatesType === 'global', + click: () => { + setting.set('view.show_coordinates', true) + setting.set('view.coordinates_type', 'global') + } + }, + { + label: i18n.t('menu.view', '&Japanese Coordinates'), + type: 'checkbox', + checked: !!showCoordinates && coordinatesType === 'japanese', + click: () => { + setting.set('view.show_coordinates', true) + setting.set('view.coordinates_type', 'japanese') + } + }, + { + label: i18n.t('menu.view', '&Chinese Coordinates'), + type: 'checkbox', + checked: !!showCoordinates && coordinatesType === 'chinese', + click: () => { + setting.set('view.show_coordinates', true) + setting.set('view.coordinates_type', 'chinese') + } + } + ] }, { label: i18n.t('menu.view', 'Show Move N&umbers'), diff --git a/src/modules/sabaki.js b/src/modules/sabaki.js index 84b847e26..8cf633506 100644 --- a/src/modules/sabaki.js +++ b/src/modules/sabaki.js @@ -59,7 +59,7 @@ class Sabaki extends EventEmitter { highlightVertices: [], playVariation: null, analysisType: null, - coordinateType: null, + coordinatesType: null, showAnalysis: null, showCoordinates: null, showMoveColorization: null, @@ -214,13 +214,13 @@ class Sabaki extends EventEmitter { 'app.zoom_factor': 'zoomFactor', 'board.analysis_type': 'analysisType', 'board.show_analysis': 'showAnalysis', - 'board.coordinate_type': 'coordinateType', 'view.show_menubar': 'showMenuBar', 'view.show_coordinates': 'showCoordinates', 'view.show_move_colorization': 'showMoveColorization', 'view.show_move_numbers': 'showMoveNumbers', 'view.show_next_moves': 'showNextMoves', 'view.show_siblings': 'showSiblings', + 'view.coordinates_type': 'coordinatesType', 'view.fuzzy_stone_placement': 'fuzzyStonePlacement', 'view.animated_stone_placement': 'animateStonePlacement', 'graph.grid_size': 'graphGridSize', diff --git a/src/setting.js b/src/setting.js index 4fb053b78..75241ab9a 100644 --- a/src/setting.js +++ b/src/setting.js @@ -47,7 +47,6 @@ let defaults = { 'board.show_analysis': true, 'board.variation_instant_replay': false, 'board.variation_replay_interval': 500, - 'board.coordinate_type': 'global', 'cleanmarkup.annotations': false, 'cleanmarkup.arrow': true, 'cleanmarkup.circle': true, @@ -182,6 +181,7 @@ let defaults = { 'theme.custom_background': null, 'theme.current': null, 'view.animated_stone_placement': true, + 'view.coordinates_type': 'global', 'view.fuzzy_stone_placement': true, 'view.leftsidebar_width': 250, 'view.leftsidebar_minwidth': 100, From 00f60f3261984f09ac198bb82da7541285e6ea95 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Thu, 19 Mar 2020 21:18:24 +0900 Subject: [PATCH 3/6] Add shortcuts to toggle the display of the coodinates --- src/menu.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/menu.js b/src/menu.js index 72011be5a..dd6fcb9dc 100644 --- a/src/menu.js +++ b/src/menu.js @@ -558,9 +558,10 @@ exports.get = function(props = {}) { submenu: [ { label: i18n.t('menu.view', '&Don’t Show'), + accelerator: 'CmdOrCtrl+Shift+C', type: 'checkbox', checked: !showCoordinates, - click: () => setting.set('view.show_coordinates', false) + click: () => toggleSetting('view.show_coordinates') }, { label: i18n.t('menu.view', '&Global Coordinates'), From 4d402e6bfc9dfedfe1887a7b910f40ee1dbfc646 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Thu, 19 Mar 2020 21:20:14 +0900 Subject: [PATCH 4/6] Add support for descriptive coordinates --- src/components/Goban.js | 15 +++++++++++++++ src/menu.js | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/components/Goban.js b/src/components/Goban.js index aa045d4bc..066649eab 100644 --- a/src/components/Goban.js +++ b/src/components/Goban.js @@ -263,11 +263,26 @@ export default class Goban extends Component { board.height ) + // Calculate coordinates + + let descriptiveCoord = (x, size) => { + let halfSize = Math.ceil(size / 2) + let ix = size - x + 1 + if (x <= halfSize && x < 10) return x.toString() + else if (ix < halfSize && ix < 10) return `${ix}*` + else return 'X' + } + let getCoordTransformer = coordinatesType => { if (coordinatesType === 'japanese') { return [x => x + 1, y => y + 1] } else if (coordinatesType === 'chinese') { return [x => alphaChinese[x], y => y + 1] + } else if (coordinatesType === 'descriptive') { + return [ + x => descriptiveCoord(x + 1, board.width), + y => descriptiveCoord(board.height - y, board.height) + ] } else { return [x => alpha[x], y => board.height - y] // global } diff --git a/src/menu.js b/src/menu.js index dd6fcb9dc..439a06bf3 100644 --- a/src/menu.js +++ b/src/menu.js @@ -589,6 +589,15 @@ exports.get = function(props = {}) { setting.set('view.show_coordinates', true) setting.set('view.coordinates_type', 'chinese') } + }, + { + label: i18n.t('menu.view', '&Descriptive Coordinates'), + type: 'checkbox', + checked: !!showCoordinates && coordinatesType === 'descriptive', + click: () => { + setting.set('view.show_coordinates', true) + setting.set('view.coordinates_type', 'descriptive') + } } ] }, From b2d62750c1acbc08de60f7dfbcd312cd349cd923 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Fri, 20 Mar 2020 10:09:03 +0900 Subject: [PATCH 5/6] Rename each coordinate system, and remove 'Chinese Coordinates'. --- src/components/Goban.js | 15 ++++++--------- src/menu.js | 27 +++++++++------------------ src/setting.js | 2 +- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/components/Goban.js b/src/components/Goban.js index 066649eab..dd091e5ab 100644 --- a/src/components/Goban.js +++ b/src/components/Goban.js @@ -12,7 +12,6 @@ import * as helper from '../modules/helper.js' const t = i18n.context('Goban') const setting = remote.require('./setting') const alpha = 'ABCDEFGHJKLMNOPQRSTUVWXYZ' -const alphaChinese = 'ABCDEFGHIJKLMNOPQRSTUVWXY' export default class Goban extends Component { constructor(props) { @@ -265,7 +264,7 @@ export default class Goban extends Component { // Calculate coordinates - let descriptiveCoord = (x, size) => { + let relativeCoord = (x, size) => { let halfSize = Math.ceil(size / 2) let ix = size - x + 1 if (x <= halfSize && x < 10) return x.toString() @@ -274,17 +273,15 @@ export default class Goban extends Component { } let getCoordTransformer = coordinatesType => { - if (coordinatesType === 'japanese') { + if (coordinatesType === '1-1') { return [x => x + 1, y => y + 1] - } else if (coordinatesType === 'chinese') { - return [x => alphaChinese[x], y => y + 1] - } else if (coordinatesType === 'descriptive') { + } else if (coordinatesType === 'relative') { return [ - x => descriptiveCoord(x + 1, board.width), - y => descriptiveCoord(board.height - y, board.height) + x => relativeCoord(x + 1, board.width), + y => relativeCoord(board.height - y, board.height) ] } else { - return [x => alpha[x], y => board.height - y] // global + return [x => alpha[x], y => board.height - y] // A1 } } diff --git a/src/menu.js b/src/menu.js index 439a06bf3..af12fdd77 100644 --- a/src/menu.js +++ b/src/menu.js @@ -564,39 +564,30 @@ exports.get = function(props = {}) { click: () => toggleSetting('view.show_coordinates') }, { - label: i18n.t('menu.view', '&Global Coordinates'), + label: i18n.t('menu.view', '&A1 (Default)'), type: 'checkbox', - checked: !!showCoordinates && coordinatesType === 'global', + checked: !!showCoordinates && coordinatesType === 'A1', click: () => { setting.set('view.show_coordinates', true) - setting.set('view.coordinates_type', 'global') + setting.set('view.coordinates_type', 'A1') } }, { - label: i18n.t('menu.view', '&Japanese Coordinates'), + label: i18n.t('menu.view', '1-1'), type: 'checkbox', - checked: !!showCoordinates && coordinatesType === 'japanese', + checked: !!showCoordinates && coordinatesType === '1-1', click: () => { setting.set('view.show_coordinates', true) - setting.set('view.coordinates_type', 'japanese') + setting.set('view.coordinates_type', '1-1') } }, { - label: i18n.t('menu.view', '&Chinese Coordinates'), + label: i18n.t('menu.view', '&Relative'), type: 'checkbox', - checked: !!showCoordinates && coordinatesType === 'chinese', + checked: !!showCoordinates && coordinatesType === 'relative', click: () => { setting.set('view.show_coordinates', true) - setting.set('view.coordinates_type', 'chinese') - } - }, - { - label: i18n.t('menu.view', '&Descriptive Coordinates'), - type: 'checkbox', - checked: !!showCoordinates && coordinatesType === 'descriptive', - click: () => { - setting.set('view.show_coordinates', true) - setting.set('view.coordinates_type', 'descriptive') + setting.set('view.coordinates_type', 'relative') } } ] diff --git a/src/setting.js b/src/setting.js index 75241ab9a..6c71a2770 100644 --- a/src/setting.js +++ b/src/setting.js @@ -181,7 +181,7 @@ let defaults = { 'theme.custom_background': null, 'theme.current': null, 'view.animated_stone_placement': true, - 'view.coordinates_type': 'global', + 'view.coordinates_type': 'A1', 'view.fuzzy_stone_placement': true, 'view.leftsidebar_width': 250, 'view.leftsidebar_minwidth': 100, From 607f750c391c145c6a6298b5ce7f101fd368c0b6 Mon Sep 17 00:00:00 2001 From: ebifrier Date: Fri, 20 Mar 2020 19:27:27 +0900 Subject: [PATCH 6/6] Refactor names and more --- src/components/Goban.js | 19 +++++++++---------- src/menu.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/Goban.js b/src/components/Goban.js index dd091e5ab..058dd9014 100644 --- a/src/components/Goban.js +++ b/src/components/Goban.js @@ -264,18 +264,17 @@ export default class Goban extends Component { // Calculate coordinates - let relativeCoord = (x, size) => { - let halfSize = Math.ceil(size / 2) - let ix = size - x + 1 - if (x <= halfSize && x < 10) return x.toString() - else if (ix < halfSize && ix < 10) return `${ix}*` - else return 'X' - } - - let getCoordTransformer = coordinatesType => { + let getCoordFunctions = coordinatesType => { if (coordinatesType === '1-1') { return [x => x + 1, y => y + 1] } else if (coordinatesType === 'relative') { + let relativeCoord = (x, size) => { + let halfSize = Math.ceil(size / 2) + let ix = size - x + 1 + if (x <= halfSize && x < 10) return x.toString() + else if (ix < halfSize && ix < 10) return `${ix}*` + else return 'X' + } return [ x => relativeCoord(x + 1, board.width), y => relativeCoord(board.height - y, board.height) @@ -286,7 +285,7 @@ export default class Goban extends Component { } let coordinatesType = setting.get('view.coordinates_type') - let coordTransformer = getCoordTransformer(coordinatesType) + let coordTransformer = getCoordFunctions(coordinatesType) let {coordX, coordY} = gobantransformer.transformCoords( coordTransformer[0], coordTransformer[1], diff --git a/src/menu.js b/src/menu.js index af12fdd77..52c2fe0c0 100644 --- a/src/menu.js +++ b/src/menu.js @@ -573,7 +573,7 @@ exports.get = function(props = {}) { } }, { - label: i18n.t('menu.view', '1-1'), + label: i18n.t('menu.view', '&1-1'), type: 'checkbox', checked: !!showCoordinates && coordinatesType === '1-1', click: () => {