opening trainer: the branch header names the branch in SAN with move numbers (also from the QA hook)
This commit is contained in:
parent
94ddbfa27a
commit
ebd705cf5d
3 changed files with 30 additions and 16 deletions
|
|
@ -203,6 +203,25 @@ pub(crate) fn move_text(game: &Game, node: NodeId) -> Option<String> {
|
|||
})
|
||||
}
|
||||
|
||||
/// "1. e4 e5 2. Nf3": the moves from the start to `node` with move numbers.
|
||||
pub(crate) fn path_text(game: &Game, node: NodeId) -> String {
|
||||
let mut words = Vec::new();
|
||||
for id in game.path(node).into_iter().skip(1) {
|
||||
let Some(mv) = game.game_move(id) else {
|
||||
continue;
|
||||
};
|
||||
let san = crate::san::show(&mv.san).into_owned();
|
||||
match game.move_number(id) {
|
||||
Some((number, Color::White)) => words.push(format!("{number}. {san}")),
|
||||
Some((number, Color::Black)) if words.is_empty() => {
|
||||
words.push(format!("{number}… {san}"))
|
||||
}
|
||||
_ => words.push(san),
|
||||
}
|
||||
}
|
||||
words.join(" ")
|
||||
}
|
||||
|
||||
/// The symbol of a move's assessment (`!`, `?!` …) and its colour for text.
|
||||
pub(crate) fn assessment(game: &Game, node: NodeId, dark: bool) -> Option<(&'static str, Color32)> {
|
||||
let nag = game
|
||||
|
|
|
|||
|
|
@ -252,21 +252,7 @@ impl OpeningLinesUi {
|
|||
|
||||
/// "… 4. Ba4 Nf6": the moves to a node in the notation of the application.
|
||||
fn path_label(&self, node: NodeId) -> String {
|
||||
let mut words = Vec::new();
|
||||
for id in self.game.path(node).into_iter().skip(1) {
|
||||
let Some(mv) = self.game.game_move(id) else {
|
||||
continue;
|
||||
};
|
||||
let san = crate::san::show(&mv.san).into_owned();
|
||||
match self.game.move_number(id) {
|
||||
Some((number, Color::White)) => words.push(format!("{number}. {san}")),
|
||||
Some((number, Color::Black)) if words.is_empty() => {
|
||||
words.push(format!("{number}… {san}"))
|
||||
}
|
||||
_ => words.push(san),
|
||||
}
|
||||
}
|
||||
words.join(" ")
|
||||
layout::path_text(&self.game, node)
|
||||
}
|
||||
|
||||
fn below(&self, path: &[String]) -> Option<(usize, usize, usize)> {
|
||||
|
|
|
|||
|
|
@ -2231,7 +2231,16 @@ impl RepertoireUi {
|
|||
.split_whitespace()
|
||||
.map(str::to_owned)
|
||||
.collect();
|
||||
let label = through.join(" ");
|
||||
// The label in the notation of the application, as «Lines» gives it.
|
||||
let label = self
|
||||
.selected
|
||||
.as_ref()
|
||||
.and_then(|id| self.library.repertoire(id))
|
||||
.map(|r| r.game())
|
||||
.and_then(|game| {
|
||||
layout::node_at(&game, &through).map(|at| layout::path_text(&game, at))
|
||||
})
|
||||
.unwrap_or_else(|| through.join(" "));
|
||||
self.start(SessionKind::Branch { through, label }, settings);
|
||||
}
|
||||
"menu" => self.debug_menu = true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue