Skip to content

Commit

Permalink
Add keyboard shortcuts for Estimate/Score
Browse files Browse the repository at this point in the history
Close #345
  • Loading branch information
yishn committed Feb 28, 2020
1 parent eea323f commit e2dce4c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {h, render, Component} from 'preact'
import classNames from 'classnames'
import fixPath from 'fix-path'

import deadstones from '@sabaki/deadstones'
import influence from '@sabaki/influence'

import TripleSplitContainer from './helpers/TripleSplitContainer.js'
Expand All @@ -28,7 +27,6 @@ const setting = remote.require('./setting')
const leftSidebarMinWidth = setting.get('view.sidebar_minwidth')
const sidebarMinWidth = setting.get('view.leftsidebar_minwidth')

deadstones.useFetch('./node_modules/@sabaki/deadstones/wasm/deadstones_bg.wasm')
fixPath()

class App extends Component {
Expand Down Expand Up @@ -311,7 +309,7 @@ class App extends Component {

areaMap =
state.mode === 'estimator'
? influence.map(scoreBoard.signMap)
? influence.map(scoreBoard.signMap, {discrete: true})
: influence.areaMap(scoreBoard.signMap)
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/MainView.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ export default class MainView extends Component {
let paintMap

if (['scoring', 'estimator'].includes(mode)) {
paintMap = areaMap.map(row =>
row.map(x => ((Math.abs(x) * 2 + 1) / 3) * Math.sign(x))
)
paintMap = areaMap
} else if (mode === 'guess') {
paintMap = [...Array(board.height)].map(_ => Array(board.width).fill(0))

Expand Down
16 changes: 11 additions & 5 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exports.get = function(props = {}) {
},
{type: 'separator'},
{
label: i18n.t('menu.play', '&Select Point'),
label: i18n.t('menu.play', 'Se&lect Point'),
accelerator: 'CmdOrCtrl+L',
click: async () => {
let value = await dialog.showInputBox(
Expand All @@ -135,17 +135,23 @@ exports.get = function(props = {}) {
click: () => sabaki.makeMove([-1, -1])
},
{
label: i18n.t('menu.play', '&Resign'),
label: i18n.t('menu.play', 'Resig&n'),
click: () => sabaki.makeResign()
},
{type: 'separator'},
{
label: i18n.t('menu.play', '&Estimate'),
click: () => sabaki.setMode('estimator')
accelerator: 'CmdOrCtrl+Shift+E',
click: () =>
sabaki.setMode(
sabaki.state.mode === 'estimator' ? 'play' : 'estimator'
)
},
{
label: i18n.t('menu.play', 'Sc&ore'),
click: () => sabaki.setMode('scoring')
label: i18n.t('menu.play', 'Sco&re'),
accelerator: 'CmdOrCtrl+Shift+R',
click: () =>
sabaki.setMode(sabaki.state.mode === 'scoring' ? 'play' : 'scoring')
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions src/modules/sabaki.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import * as gtplogger from './gtplogger.js'
import * as helper from './helper.js'
import * as sound from './sound.js'

deadstones.useFetch('./node_modules/@sabaki/deadstones/wasm/deadstones_bg.wasm')

const {app} = remote
const setting = remote.require('./setting')

Expand Down Expand Up @@ -212,6 +214,8 @@ class Sabaki extends EventEmitter {
// User Interface

setMode(mode) {
if (this.state.mode === mode) return

let stateChange = {mode}

if (['scoring', 'estimator'].includes(mode)) {
Expand Down

0 comments on commit e2dce4c

Please sign in to comment.