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 the option to switch on/off the display of variations #668

Merged
merged 1 commit into from
Mar 22, 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
6 changes: 3 additions & 3 deletions src/components/ContentDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export default class ContentDisplay extends Component {

sabaki.setState({playVariation: {sign, moves, sibling}})

if (setting.get('board.variation_instant_replay')) {
currentTarget.style.backgroundSize = '100% 100%'
} else {
if (setting.get('board.variation_replay_mode') === 'move_by_move') {
clearInterval(this.variationIntervalId)
this.variationIntervalId = setInterval(() => {
if (counter >= moves.length) {
Expand All @@ -102,6 +100,8 @@ export default class ContentDisplay extends Component {
currentTarget.style.backgroundSize = `${percent}% 100%`
counter++
}, setting.get('board.variation_replay_interval'))
} else {
currentTarget.style.backgroundSize = '100% 100%'
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/components/Goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ export default class Goban extends Component {
}

playVariation(sign, moves, sibling = false) {
if (setting.get('board.variation_instant_replay')) {
let replayMode = setting.get('board.variation_replay_mode')
if (replayMode === 'instantly') {
this.variationIntervalId = true

this.setState({
Expand All @@ -181,7 +182,7 @@ export default class Goban extends Component {
variationSibling: sibling,
variationIndex: moves.length
})
} else {
} else if (replayMode === 'move_by_move') {
clearInterval(this.variationIntervalId)

this.variationIntervalId = setInterval(() => {
Expand All @@ -192,6 +193,8 @@ export default class Goban extends Component {
variationIndex: variationIndex + 1
}))
}, setting.get('board.variation_replay_interval'))
} else {
this.stopPlayingVariation()
}
}

Expand Down
56 changes: 51 additions & 5 deletions src/components/drawers/PreferencesDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class GeneralTab extends Component {
super(props)

this.state = {
appLang: setting.get('app.lang')
appLang: setting.get('app.lang'),
variationReplayMode: setting.get('board.variation_replay_mode')
}

this.handleSoundEnabledChange = evt => {
Expand All @@ -85,9 +86,15 @@ class GeneralTab extends Component {
setting.set('app.lang', evt.currentTarget.value)
}

this.handleVariationReplayModeChange = evt => {
setting.set('board.variation_replay_mode', evt.currentTarget.value)
}

setting.events.on(sabaki.window.id, 'change', ({key, value}) => {
if (key === 'app.lang') {
this.setState({appLang: value})
} else if (key === 'board.variation_replay_mode') {
this.setState({variationReplayMode: value})
}
})
}
Expand Down Expand Up @@ -124,10 +131,49 @@ class GeneralTab extends Component {
id: 'view.animated_stone_placement',
text: t('Animate fuzzy placement')
}),
h(PreferencesItem, {
id: 'board.variation_instant_replay',
text: t('Instantly play out analysis variations on board')
}),

h(
'li',
{class: 'select'},
h(
'label',
{},
t('Replay mode of analysis variations:'),
' ',

h(
'select',
{onChange: this.handleVariationReplayModeChange},

h(
'option',
{
value: 'dont_play',
selected: this.state.variationReplayMode === 'dont_play'
},
t("Don't Play")
),

h(
'option',
{
value: 'instantly',
selected: this.state.variationReplayMode === 'instantly'
},
t('Instantly')
),

h(
'option',
{
value: 'move_by_move',
selected: this.state.variationReplayMode === 'move_by_move'
},
t('Move by Move')
)
)
)
),

h(
'li',
Expand Down
2 changes: 1 addition & 1 deletion src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let defaults = {
'board.analysis_interval': 50,
'board.analysis_type': 'winrate',
'board.show_analysis': true,
'board.variation_instant_replay': false,
'board.variation_replay_mode': 'move_by_move',
'board.variation_replay_interval': 500,
'cleanmarkup.annotations': false,
'cleanmarkup.arrow': true,
Expand Down