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

Add option to select the coordinate type #665

Merged
merged 6 commits into from
Mar 20, 2020
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
1 change: 1 addition & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 26 additions & 2 deletions src/components/Goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,33 @@ export default class Goban extends Component {
board.height
)

// Calculate coordinates

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)
]
} else {
return [x => alpha[x], y => board.height - y] // A1
}
}

let coordinatesType = setting.get('view.coordinates_type')
let coordTransformer = getCoordFunctions(coordinatesType)
let {coordX, coordY} = gobantransformer.transformCoords(
x => alpha[x],
y => board.height - y,
coordTransformer[0],
coordTransformer[1],
transformation,
board.width,
board.height
Expand Down
41 changes: 37 additions & 4 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports.get = function(props = {}) {
analysisType,
showAnalysis,
showCoordinates,
coordinatesType,
showMoveNumbers,
showMoveColorization,
showNextMoves,
Expand Down Expand Up @@ -554,10 +555,42 @@ 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'),
accelerator: 'CmdOrCtrl+Shift+C',
type: 'checkbox',
checked: !showCoordinates,
click: () => toggleSetting('view.show_coordinates')
},
{
label: i18n.t('menu.view', '&A1 (Default)'),
type: 'checkbox',
checked: !!showCoordinates && coordinatesType === 'A1',
click: () => {
setting.set('view.show_coordinates', true)
setting.set('view.coordinates_type', 'A1')
}
},
{
label: i18n.t('menu.view', '&1-1'),
type: 'checkbox',
checked: !!showCoordinates && coordinatesType === '1-1',
click: () => {
setting.set('view.show_coordinates', true)
setting.set('view.coordinates_type', '1-1')
}
},
{
label: i18n.t('menu.view', '&Relative'),
type: 'checkbox',
checked: !!showCoordinates && coordinatesType === 'relative',
click: () => {
setting.set('view.show_coordinates', true)
setting.set('view.coordinates_type', 'relative')
}
}
]
},
{
label: i18n.t('menu.view', 'Show Move N&umbers'),
Expand Down
2 changes: 2 additions & 0 deletions src/modules/sabaki.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Sabaki extends EventEmitter {
highlightVertices: [],
playVariation: null,
analysisType: null,
coordinatesType: null,
showAnalysis: null,
showCoordinates: null,
showMoveColorization: null,
Expand Down Expand Up @@ -219,6 +220,7 @@ class Sabaki extends EventEmitter {
'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',
Expand Down
1 change: 1 addition & 0 deletions src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ let defaults = {
'theme.custom_background': null,
'theme.current': null,
'view.animated_stone_placement': true,
'view.coordinates_type': 'A1',
'view.fuzzy_stone_placement': true,
'view.leftsidebar_width': 250,
'view.leftsidebar_minwidth': 100,
Expand Down