great moves (task 27): the column and its sort count the filter's player only, «Continue» keeps the player, «Open at» shows the report, the Stockfish 19 offer before a pass
This commit is contained in:
parent
e9d22b92c3
commit
6e093b0964
9 changed files with 252 additions and 21 deletions
|
|
@ -306,6 +306,8 @@ pub struct App {
|
||||||
brilliant_start: Option<crate::brilliant_ui::StartDialog>,
|
brilliant_start: Option<crate::brilliant_ui::StartDialog>,
|
||||||
brilliant_pass: Option<crate::brilliant::PassMeta>,
|
brilliant_pass: Option<crate::brilliant::PassMeta>,
|
||||||
brilliant_summary: Option<crate::brilliant_ui::Summary>,
|
brilliant_summary: Option<crate::brilliant_ui::Summary>,
|
||||||
|
/// A pass asked for while Stockfish 19 is fetched or checked: it starts after.
|
||||||
|
brilliant_waiting: Option<crate::brilliant_ui::StartDialog>,
|
||||||
applied_dark: Option<bool>,
|
applied_dark: Option<bool>,
|
||||||
debug: DebugStartup,
|
debug: DebugStartup,
|
||||||
}
|
}
|
||||||
|
|
@ -580,6 +582,7 @@ impl App {
|
||||||
brilliant_start: None,
|
brilliant_start: None,
|
||||||
brilliant_pass: None,
|
brilliant_pass: None,
|
||||||
brilliant_summary: None,
|
brilliant_summary: None,
|
||||||
|
brilliant_waiting: None,
|
||||||
applied_dark: None,
|
applied_dark: None,
|
||||||
debug: DebugStartup::from_env(),
|
debug: DebugStartup::from_env(),
|
||||||
}
|
}
|
||||||
|
|
@ -2043,10 +2046,11 @@ impl App {
|
||||||
};
|
};
|
||||||
let Some(crate::engines::EngineLocation::Program(engine)) = crate::review_engine::engine()
|
let Some(crate::engines::EngineLocation::Program(engine)) = crate::review_engine::engine()
|
||||||
else {
|
else {
|
||||||
self.toast(
|
// The offer of «Analyse game»: download Stockfish 19 (or check the user's);
|
||||||
ctx,
|
// the pass starts after it.
|
||||||
tr("The search needs Stockfish 19: start «Analyse game» once to get it"),
|
dialog.counted = Some(counted);
|
||||||
);
|
self.brilliant_waiting = Some(dialog);
|
||||||
|
self.need_review_engine(ctx, crate::engine_offer::Pending::GreatMoves);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let (Some(db), Some(cache)) = (
|
let (Some(db), Some(cache)) = (
|
||||||
|
|
@ -2224,13 +2228,9 @@ impl App {
|
||||||
self.library.choose_only(&source, record as usize);
|
self.library.choose_only(&source, record as usize);
|
||||||
}
|
}
|
||||||
SummaryAction::Sort => self.library.sort_by_marks(&source),
|
SummaryAction::Sort => self.library.sort_by_marks(&source),
|
||||||
SummaryAction::Continue(rest) => {
|
SummaryAction::Continue { records, filter } => {
|
||||||
let filter = self
|
self.brilliant_summary = None;
|
||||||
.brilliant_summary
|
self.ask_great_moves(ctx, source, records, *filter);
|
||||||
.take()
|
|
||||||
.map(|_| chess_import::chessbase::base::Filter::default())
|
|
||||||
.unwrap_or_default();
|
|
||||||
self.ask_great_moves(ctx, source, rest, filter);
|
|
||||||
}
|
}
|
||||||
SummaryAction::Open { record, ply } => {
|
SummaryAction::Open { record, ply } => {
|
||||||
self.brilliant_summary = None;
|
self.brilliant_summary = None;
|
||||||
|
|
@ -2241,6 +2241,9 @@ impl App {
|
||||||
});
|
});
|
||||||
self.library.choose_only(&source, record as usize);
|
self.library.choose_only(&source, record as usize);
|
||||||
self.open_game(ctx, source, record as usize, at);
|
self.open_game(ctx, source, record as usize, at);
|
||||||
|
if let Some(g) = self.game.as_mut() {
|
||||||
|
g.show_report();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3554,6 +3557,7 @@ impl App {
|
||||||
Some(
|
Some(
|
||||||
crate::engine_offer::Pending::GameAnalysis { .. }
|
crate::engine_offer::Pending::GameAnalysis { .. }
|
||||||
| crate::engine_offer::Pending::OpeningErrors { .. }
|
| crate::engine_offer::Pending::OpeningErrors { .. }
|
||||||
|
| crate::engine_offer::Pending::GreatMoves
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if !own_search || self.settings.active_engine().is_none() {
|
if !own_search || self.settings.active_engine().is_none() {
|
||||||
|
|
@ -3653,6 +3657,11 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(crate::engine_offer::Pending::GreatMoves) => {
|
||||||
|
if let Some(dialog) = self.brilliant_waiting.take() {
|
||||||
|
self.start_great_moves(ctx, dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some(crate::engine_offer::Pending::OpeningErrors { prep }) => {
|
Some(crate::engine_offer::Pending::OpeningErrors { prep }) => {
|
||||||
let actions = match self.prep.as_mut().filter(|p| p.serial == prep) {
|
let actions = match self.prep.as_mut().filter(|p| p.serial == prep) {
|
||||||
Some(p) => p.start_after_engine(ctx),
|
Some(p) => p.start_after_engine(ctx),
|
||||||
|
|
@ -4642,6 +4651,12 @@ impl eframe::App for App {
|
||||||
LibraryAction::OpenGame { path, index, at } => {
|
LibraryAction::OpenGame { path, index, at } => {
|
||||||
self.open_game(&ctx, path, index, at)
|
self.open_game(&ctx, path, index, at)
|
||||||
}
|
}
|
||||||
|
LibraryAction::OpenGameReport { path, index, at } => {
|
||||||
|
self.open_game(&ctx, path, index, at);
|
||||||
|
if let Some(g) = self.game.as_mut() {
|
||||||
|
g.show_report();
|
||||||
|
}
|
||||||
|
}
|
||||||
LibraryAction::Sound(s) => self.play(s),
|
LibraryAction::Sound(s) => self.play(s),
|
||||||
LibraryAction::CopyText(text, msg) => {
|
LibraryAction::CopyText(text, msg) => {
|
||||||
ctx.copy_text(text);
|
ctx.copy_text(text);
|
||||||
|
|
@ -5053,6 +5068,8 @@ fn still_waiting(
|
||||||
Pending::GameAnalysis { game: g, .. } => Some(*g) == game,
|
Pending::GameAnalysis { game: g, .. } => Some(*g) == game,
|
||||||
Pending::OpeningErrors { prep: p } => Some(*p) == prep,
|
Pending::OpeningErrors { prep: p } => Some(*p) == prep,
|
||||||
Pending::LiveAnalysis => false,
|
Pending::LiveAnalysis => false,
|
||||||
|
// The app keeps its question (`brilliant_waiting`) until it starts.
|
||||||
|
Pending::GreatMoves => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,23 @@ pub struct Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
|
/// The entry with only the marks of the sides that count (the filter's player): the
|
||||||
|
/// row's sign and hint show only them.
|
||||||
|
pub fn for_sides(&self, white: bool, black: bool) -> Entry {
|
||||||
|
let keep = |on: bool, s: &SideMarks| if on { *s } else { SideMarks::default() };
|
||||||
|
Entry {
|
||||||
|
white: keep(white, &self.white),
|
||||||
|
black: keep(black, &self.black),
|
||||||
|
found: self
|
||||||
|
.found
|
||||||
|
.iter()
|
||||||
|
.filter(|f| if f.white { white } else { black })
|
||||||
|
.cloned()
|
||||||
|
.collect(),
|
||||||
|
..self.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The !! and ! of the sides that count.
|
/// The !! and ! of the sides that count.
|
||||||
pub fn of_sides(&self, white: bool, black: bool) -> Counts {
|
pub fn of_sides(&self, white: bool, black: bool) -> Counts {
|
||||||
let mut c = Counts::default();
|
let mut c = Counts::default();
|
||||||
|
|
@ -289,12 +306,13 @@ impl Index {
|
||||||
|
|
||||||
/// Where a record goes when the table is sorted by its marks: !! first, then !,
|
/// Where a record goes when the table is sorted by its marks: !! first, then !,
|
||||||
/// analysed without them, not analysable, not analysed.
|
/// analysed without them, not analysable, not analysed.
|
||||||
pub fn rank(&self, record: u32) -> u8 {
|
pub fn rank(&self, record: u32, sides: &Sides) -> u8 {
|
||||||
match self.records.get(&record) {
|
match self.records.get(&record) {
|
||||||
None => 4,
|
None => 4,
|
||||||
Some(e) if e.skip.is_some() => 3,
|
Some(e) if e.skip.is_some() => 3,
|
||||||
Some(e) => {
|
Some(e) => {
|
||||||
let c = e.of_sides(true, true);
|
let (w, b) = sides.of(record);
|
||||||
|
let c = e.of_sides(w, b);
|
||||||
if c.brilliant > 0 {
|
if c.brilliant > 0 {
|
||||||
0
|
0
|
||||||
} else if c.great > 0 {
|
} else if c.great > 0 {
|
||||||
|
|
@ -515,7 +533,8 @@ pub struct Sides {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sides {
|
impl Sides {
|
||||||
fn of(&self, record: u32) -> (bool, bool) {
|
/// Whether White's and Black's moves of `record` count.
|
||||||
|
pub fn of(&self, record: u32) -> (bool, bool) {
|
||||||
match &self.player {
|
match &self.player {
|
||||||
None => (true, true),
|
None => (true, true),
|
||||||
Some((w, b)) => (
|
Some((w, b)) => (
|
||||||
|
|
|
||||||
|
|
@ -344,3 +344,86 @@ fn the_players_sides_come_from_the_filter() {
|
||||||
.is_none()
|
.is_none()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// White found a !! and Black a !: the row of a filter on the Black player shows !.
|
||||||
|
fn two_sided() -> Index {
|
||||||
|
let mut index = Index::default();
|
||||||
|
index.set(
|
||||||
|
0,
|
||||||
|
Entry {
|
||||||
|
line: String::new(),
|
||||||
|
white: side(1, 0, 0, 10, 95.0),
|
||||||
|
black: side(0, 1, 2, 40, 70.0),
|
||||||
|
found: vec![
|
||||||
|
found(20, true, 11, "Rxf7", true),
|
||||||
|
found(23, false, 12, "Nd5", false),
|
||||||
|
],
|
||||||
|
stale: false,
|
||||||
|
skip: None,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
index.set(
|
||||||
|
1,
|
||||||
|
Entry {
|
||||||
|
found: Vec::new(),
|
||||||
|
..index.get(0).unwrap().clone()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
index
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_column_counts_only_the_filters_players_moves() {
|
||||||
|
let index = two_sided();
|
||||||
|
let both = Sides::default();
|
||||||
|
let black = Sides {
|
||||||
|
player: Some((Vec::new(), vec![0])),
|
||||||
|
};
|
||||||
|
assert_eq!(index.rank(0, &both), 0);
|
||||||
|
assert_eq!(index.rank(0, &black), 1);
|
||||||
|
// A game where the player is on neither side has nothing of his.
|
||||||
|
assert_eq!(index.rank(1, &black), 2);
|
||||||
|
let e = index.get(0).unwrap().for_sides(false, true);
|
||||||
|
assert_eq!(e.of_sides(true, true).brilliant, 0);
|
||||||
|
assert_eq!(e.of_sides(true, true).great, 1);
|
||||||
|
assert_eq!(
|
||||||
|
e.found.iter().map(Found::label).collect::<Vec<_>>(),
|
||||||
|
["12…Nd5!"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_summary_keeps_the_player_for_continue() {
|
||||||
|
let dir = Dir::new("summary");
|
||||||
|
let (path, db) = source(&dir);
|
||||||
|
let filter = chess_import::chessbase::base::Filter {
|
||||||
|
player: chess_import::chessbase::base::NameFilter {
|
||||||
|
text: "carlsen".into(),
|
||||||
|
exact: None,
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let sides = player_sides(&db, &filter, &AtomicBool::new(false));
|
||||||
|
let index = two_sided();
|
||||||
|
// Record 0: Carlsen has White (its !!); record 1: Carlsen has Black (a !).
|
||||||
|
let summary = crate::brilliant_ui::Summary::new(
|
||||||
|
&path,
|
||||||
|
&db,
|
||||||
|
&index,
|
||||||
|
&[0, 1, 2],
|
||||||
|
&sides,
|
||||||
|
&filter,
|
||||||
|
String::new(),
|
||||||
|
Some((2, 3)),
|
||||||
|
Vec::new(),
|
||||||
|
);
|
||||||
|
assert_eq!(summary.filter, filter);
|
||||||
|
assert_eq!(summary.rest, vec![2]);
|
||||||
|
assert_eq!(
|
||||||
|
(summary.totals.counts.brilliant, summary.totals.counts.great),
|
||||||
|
(1, 1)
|
||||||
|
);
|
||||||
|
assert_eq!(summary.totals.counts.blunders, 2);
|
||||||
|
assert_eq!(summary.player, Some(("carlsen".to_owned(), 1, 1)));
|
||||||
|
assert_eq!(summary.rows.len(), 1);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,8 @@ pub struct Summary {
|
||||||
pub skipped: Vec<(u32, Skip)>,
|
pub skipped: Vec<(u32, Skip)>,
|
||||||
pub rows: Vec<BrilliantRow>,
|
pub rows: Vec<BrilliantRow>,
|
||||||
pub selected: Option<usize>,
|
pub selected: Option<usize>,
|
||||||
|
/// The pass's filter: «Continue» goes on with it (its player's moves only).
|
||||||
|
pub filter: Filter,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SummaryAction {
|
pub enum SummaryAction {
|
||||||
|
|
@ -245,7 +247,10 @@ pub enum SummaryAction {
|
||||||
record: u32,
|
record: u32,
|
||||||
ply: u16,
|
ply: u16,
|
||||||
},
|
},
|
||||||
Continue(Vec<u32>),
|
Continue {
|
||||||
|
records: Vec<u32>,
|
||||||
|
filter: Box<Filter>,
|
||||||
|
},
|
||||||
/// Sort the table by the «!!» column.
|
/// Sort the table by the «!!» column.
|
||||||
Sort,
|
Sort,
|
||||||
Close,
|
Close,
|
||||||
|
|
@ -311,6 +316,7 @@ impl Summary {
|
||||||
skipped,
|
skipped,
|
||||||
rows,
|
rows,
|
||||||
selected: None,
|
selected: None,
|
||||||
|
filter: filter.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -603,7 +609,10 @@ impl Summary {
|
||||||
&& !self.rest.is_empty()
|
&& !self.rest.is_empty()
|
||||||
&& ui.button(tr("Continue")).clicked()
|
&& ui.button(tr("Continue")).clicked()
|
||||||
{
|
{
|
||||||
out = Some(SummaryAction::Continue(self.rest.clone()));
|
out = Some(SummaryAction::Continue {
|
||||||
|
records: self.rest.clone(),
|
||||||
|
filter: Box::new(self.filter.clone()),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ pub const DOWNLOAD_INDICATOR: &str = "download_indicator";
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum Pending {
|
pub enum Pending {
|
||||||
LiveAnalysis,
|
LiveAnalysis,
|
||||||
|
/// The search for great moves in a database's list (task 27), waiting in the app.
|
||||||
|
GreatMoves,
|
||||||
/// The analysis of the game on the screen whose `serial` is `game` (no other game's);
|
/// The analysis of the game on the screen whose `serial` is `game` (no other game's);
|
||||||
/// `full`: anew, over evaluations read from the PGN.
|
/// `full`: anew, over evaluations read from the PGN.
|
||||||
GameAnalysis {
|
GameAnalysis {
|
||||||
|
|
@ -162,6 +164,9 @@ impl EngineOffer {
|
||||||
Some(Pending::OpeningErrors { .. }) => {
|
Some(Pending::OpeningErrors { .. }) => {
|
||||||
tr("Stockfish installed — the search for opening errors started")
|
tr("Stockfish installed — the search for opening errors started")
|
||||||
}
|
}
|
||||||
|
Some(Pending::GreatMoves) => {
|
||||||
|
tr("Stockfish installed — the search for great moves started")
|
||||||
|
}
|
||||||
None => tr("Stockfish installed"),
|
None => tr("Stockfish installed"),
|
||||||
}
|
}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
|
@ -394,6 +399,9 @@ impl EngineOffer {
|
||||||
Some(Pending::OpeningErrors { .. }) => {
|
Some(Pending::OpeningErrors { .. }) => {
|
||||||
tr("The search for opening errors will start by itself when the download finishes.")
|
tr("The search for opening errors will start by itself when the download finishes.")
|
||||||
}
|
}
|
||||||
|
Some(Pending::GreatMoves) => {
|
||||||
|
tr("The search for great moves will start by itself when the download finishes.")
|
||||||
|
}
|
||||||
_ => tr("Analysis will start by itself when the download finishes."),
|
_ => tr("Analysis will start by itself when the download finishes."),
|
||||||
};
|
};
|
||||||
ui.label(RichText::new(after).weak());
|
ui.label(RichText::new(after).weak());
|
||||||
|
|
|
||||||
|
|
@ -5576,6 +5576,15 @@ fn paste_line_full(line: &[(u32, Color, String)]) -> String {
|
||||||
.join(" ")
|
.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GameView {
|
||||||
|
/// The report tab and the graph shown (a game opened at a move the search for great
|
||||||
|
/// moves found).
|
||||||
|
pub fn show_report(&mut self) {
|
||||||
|
self.review.visible = true;
|
||||||
|
self.side_tab = SideTab::Report;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// «📈 Analyse game» in the colour of «!!» (task 26): the report it makes marks its finds
|
/// «📈 Analyse game» in the colour of «!!» (task 26): the report it makes marks its finds
|
||||||
/// with it. Hover and press stay visible (egui's own states, shaded); a disabled button
|
/// with it. Hover and press stay visible (egui's own states, shaded); a disabled button
|
||||||
/// keeps the usual look.
|
/// keeps the usual look.
|
||||||
|
|
|
||||||
|
|
@ -20634,6 +20634,28 @@ const ROWS: &[[&str; 9]] = &[
|
||||||
"Partiyani ochish",
|
"Partiyani ochish",
|
||||||
"Партияны ашу",
|
"Партияны ашу",
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"Stockfish installed — the search for great moves started",
|
||||||
|
"Stockfish установлен — поиск замечательных ходов начат",
|
||||||
|
"Stockfish installé — la recherche de très bons coups a commencé",
|
||||||
|
"Stockfish installiert — die Suche nach starken Zügen läuft",
|
||||||
|
"Stockfish instalado: la búsqueda de jugadas notables ha empezado",
|
||||||
|
"Stockfish installato — la ricerca di mosse notevoli è iniziata",
|
||||||
|
"Stockfish instalado — a pesquisa de lances notáveis começou",
|
||||||
|
"Stockfish o‘rnatildi — ajoyib yurishlarni qidirish boshlandi",
|
||||||
|
"Stockfish орнатылды — тамаша жүрістерді іздеу басталды",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"The search for great moves will start by itself when the download finishes.",
|
||||||
|
"Поиск замечательных ходов начнётся сам, когда загрузка закончится.",
|
||||||
|
"La recherche de très bons coups commencera d’elle-même à la fin du téléchargement.",
|
||||||
|
"Die Suche nach starken Zügen beginnt von selbst, wenn der Download fertig ist.",
|
||||||
|
"La búsqueda de jugadas notables empezará sola cuando termine la descarga.",
|
||||||
|
"La ricerca di mosse notevoli partirà da sola al termine del download.",
|
||||||
|
"A pesquisa de lances notáveis começa sozinha quando a transferência terminar.",
|
||||||
|
"Yuklab olish tugagach, ajoyib yurishlarni qidirish o‘zi boshlanadi.",
|
||||||
|
"Жүктеу аяқталғанда тамаша жүрістерді іздеу өзі басталады.",
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,10 @@ pub struct LargeView {
|
||||||
shown_marks: std::cell::RefCell<(u64, HashMap<u32, Option<crate::brilliant::Entry>>)>,
|
shown_marks: std::cell::RefCell<(u64, HashMap<u32, Option<crate::brilliant::Entry>>)>,
|
||||||
/// The table sorted by the «!!» column.
|
/// The table sorted by the «!!» column.
|
||||||
marks_sort: bool,
|
marks_sort: bool,
|
||||||
|
/// Whose moves the «!!» column counts: the filter's player's (found in the background
|
||||||
|
/// for that filter), else both sides'.
|
||||||
|
marks_sides: (Option<Filter>, crate::brilliant::Sides),
|
||||||
|
sides_job: Option<(Filter, Receiver<crate::brilliant::Sides>)>,
|
||||||
/// The search under way (here or in another database), set by the library.
|
/// The search under way (here or in another database), set by the library.
|
||||||
pub pass: Option<PassStatus>,
|
pub pass: Option<PassStatus>,
|
||||||
/// Why the search cannot start now (the engine is busy), set by the app.
|
/// Why the search cannot start now (the engine is busy), set by the app.
|
||||||
|
|
@ -499,6 +503,8 @@ impl LargeView {
|
||||||
marks: None,
|
marks: None,
|
||||||
shown_marks: std::cell::RefCell::new((u64::MAX, HashMap::new())),
|
shown_marks: std::cell::RefCell::new((u64::MAX, HashMap::new())),
|
||||||
marks_sort: false,
|
marks_sort: false,
|
||||||
|
marks_sides: (None, Default::default()),
|
||||||
|
sides_job: None,
|
||||||
pass: None,
|
pass: None,
|
||||||
engine_busy: None,
|
engine_busy: None,
|
||||||
pass_error: None,
|
pass_error: None,
|
||||||
|
|
@ -671,6 +677,49 @@ impl LargeView {
|
||||||
self.selected = Some(index);
|
self.selected = Some(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The filter's player's sides of each record, for the «!!» column: found again in
|
||||||
|
/// the background when the filter changes; both sides without a player.
|
||||||
|
fn update_marks_sides(&mut self, db: &Arc<Database>, ctx: &egui::Context) {
|
||||||
|
let filter = self.form.filter();
|
||||||
|
if let Some((f, rx)) = &self.sides_job
|
||||||
|
&& let Ok(sides) = rx.try_recv()
|
||||||
|
{
|
||||||
|
self.marks_sides = (Some(f.clone()), sides);
|
||||||
|
self.sides_job = None;
|
||||||
|
self.shown_marks.borrow_mut().1.clear();
|
||||||
|
if self.marks_sort {
|
||||||
|
self.sort_by_marks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let wanted = self.marks_sides.0.as_ref() == Some(&filter)
|
||||||
|
|| self.sides_job.as_ref().is_some_and(|(f, _)| *f == filter);
|
||||||
|
if wanted {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if !filter.player.is_set() {
|
||||||
|
self.marks_sides = (Some(filter), Default::default());
|
||||||
|
self.sides_job = None;
|
||||||
|
self.shown_marks.borrow_mut().1.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
let (db, f, ctx) = (db.clone(), filter.clone(), ctx.clone());
|
||||||
|
let spawned = std::thread::Builder::new()
|
||||||
|
.name("marks-sides".into())
|
||||||
|
.spawn(move || {
|
||||||
|
let sides = crate::brilliant::player_sides(
|
||||||
|
&db,
|
||||||
|
&f,
|
||||||
|
&std::sync::atomic::AtomicBool::new(false),
|
||||||
|
);
|
||||||
|
let _ = tx.send(sides);
|
||||||
|
ctx.request_repaint();
|
||||||
|
});
|
||||||
|
if spawned.is_ok() {
|
||||||
|
self.sides_job = Some((filter, rx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The table sorted by its «!!» column (the summary's «Sort»).
|
/// The table sorted by its «!!» column (the summary's «Sort»).
|
||||||
pub fn sort_marks_on(&mut self) {
|
pub fn sort_marks_on(&mut self) {
|
||||||
self.marks_sort = true;
|
self.marks_sort = true;
|
||||||
|
|
@ -685,7 +734,8 @@ impl LargeView {
|
||||||
let Ok(index) = index.lock() else {
|
let Ok(index) = index.lock() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.view.sort_by_key(|&r| (index.rank(r), r));
|
let sides = &self.marks_sides.1;
|
||||||
|
self.view.sort_by_key(|&r| (index.rank(r, sides), r));
|
||||||
self.view_gen += 1;
|
self.view_gen += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -694,6 +744,7 @@ impl LargeView {
|
||||||
fn shown_mark(
|
fn shown_mark(
|
||||||
marks: &Option<Arc<std::sync::Mutex<crate::brilliant::Index>>>,
|
marks: &Option<Arc<std::sync::Mutex<crate::brilliant::Index>>>,
|
||||||
shown: &std::cell::RefCell<(u64, HashMap<u32, Option<crate::brilliant::Entry>>)>,
|
shown: &std::cell::RefCell<(u64, HashMap<u32, Option<crate::brilliant::Entry>>)>,
|
||||||
|
sides: &crate::brilliant::Sides,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
record: u32,
|
record: u32,
|
||||||
) -> Option<crate::brilliant::Entry> {
|
) -> Option<crate::brilliant::Entry> {
|
||||||
|
|
@ -714,6 +765,10 @@ impl LargeView {
|
||||||
(entry.line == line).then_some(entry)
|
(entry.line == line).then_some(entry)
|
||||||
})
|
})
|
||||||
.clone()
|
.clone()
|
||||||
|
.map(|e| {
|
||||||
|
let (w, b) = sides.of(record);
|
||||||
|
e.for_sides(w, b)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// «!! Find great moves» (the button, Shift+A): the library asks first.
|
/// «!! Find great moves» (the button, Shift+A): the library asks first.
|
||||||
|
|
@ -2626,6 +2681,7 @@ impl LargeView {
|
||||||
(true, _) => {}
|
(true, _) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.update_marks_sides(db, ui.ctx());
|
||||||
// `CP_MARKS_DEMO=1`: made-up marks for the first rows (screenshots of the column).
|
// `CP_MARKS_DEMO=1`: made-up marks for the first rows (screenshots of the column).
|
||||||
if std::env::var_os("CP_MARKS_DEMO").is_some()
|
if std::env::var_os("CP_MARKS_DEMO").is_some()
|
||||||
&& self.shown.is_some()
|
&& self.shown.is_some()
|
||||||
|
|
@ -2777,7 +2833,8 @@ impl LargeView {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.filter(|p| p.here)
|
.filter(|p| p.here)
|
||||||
.and_then(|p| p.current);
|
.and_then(|p| p.current);
|
||||||
let (marks_ref, shown_ref) = (&self.marks, &self.shown_marks);
|
let (marks_ref, shown_ref, sides_ref) =
|
||||||
|
(&self.marks, &self.shown_marks, &self.marks_sides.1);
|
||||||
let view = &self.view;
|
let view = &self.view;
|
||||||
let selected = self.selected;
|
let selected = self.selected;
|
||||||
let marked = &self.marked;
|
let marked = &self.marked;
|
||||||
|
|
@ -2887,7 +2944,7 @@ impl LargeView {
|
||||||
(_, Some(SortKey::BlackElo)) => RichText::new(elo(r.black_elo)),
|
(_, Some(SortKey::BlackElo)) => RichText::new(elo(r.black_elo)),
|
||||||
(_, Some(SortKey::Result)) => RichText::new(result),
|
(_, Some(SortKey::Result)) => RichText::new(result),
|
||||||
("!!", None) => {
|
("!!", None) => {
|
||||||
marks_cell(ui, Self::shown_mark(marks_ref, shown_ref, db, index as u32), pass_current == Some(index as u32), is_marked);
|
marks_cell(ui, Self::shown_mark(marks_ref, shown_ref, sides_ref, db, index as u32), pass_current == Some(index as u32), is_marked);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(_, Some(SortKey::Moves)) => RichText::new(match r.moves {
|
(_, Some(SortKey::Moves)) => RichText::new(match r.moves {
|
||||||
|
|
@ -2957,7 +3014,7 @@ impl LargeView {
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
// The first !! (else !) the search found: the game at it.
|
// The first !! (else !) the search found: the game at it.
|
||||||
if let Some(f) = Self::shown_mark(marks_ref, shown_ref, db, index as u32)
|
if let Some(f) = Self::shown_mark(marks_ref, shown_ref, sides_ref, db, index as u32)
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
let first = e.found.iter().find(|f| f.brilliant).or(e.found.first());
|
let first = e.found.iter().find(|f| f.brilliant).or(e.found.first());
|
||||||
first.cloned()
|
first.cloned()
|
||||||
|
|
@ -2970,7 +3027,7 @@ impl LargeView {
|
||||||
let node = *p.game.mainline().get(f.ply as usize)?;
|
let node = *p.game.mainline().get(f.ply as usize)?;
|
||||||
Some(p.game.node(node)?.position().clone())
|
Some(p.game.node(node)?.position().clone())
|
||||||
});
|
});
|
||||||
actions.push(LibraryAction::OpenGame {
|
actions.push(LibraryAction::OpenGameReport {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
index,
|
index,
|
||||||
at,
|
at,
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,13 @@ pub enum LibraryAction {
|
||||||
},
|
},
|
||||||
/// A short message (a toast).
|
/// A short message (a toast).
|
||||||
Notice(String),
|
Notice(String),
|
||||||
|
/// Open a game at the position `at` with its report shown (a move the search for
|
||||||
|
/// great moves found).
|
||||||
|
OpenGameReport {
|
||||||
|
path: PathBuf,
|
||||||
|
index: usize,
|
||||||
|
at: Option<shakmaty::Chess>,
|
||||||
|
},
|
||||||
/// «!! Find great moves» over the list `records` of `path` (in the table's order),
|
/// «!! Find great moves» over the list `records` of `path` (in the table's order),
|
||||||
/// found by `filter` (task 27).
|
/// found by `filter` (task 27).
|
||||||
FindGreatMoves {
|
FindGreatMoves {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue