Opponent prep: which games by period or number, saved preparations

The report takes all the player's games, those of the last 1/2/5 years
before his newest game, or his last 50/100/200 of each colour; every
choice shows how many games it takes. Undated games count only with all.
«💾 Save» keeps a preparation with its errors in the program's data;
«📑 Preparations» in the library opens, renames and deletes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-31 18:11:58 +03:00
parent 1ac5645ef7
commit 57fa98241b
12 changed files with 1334 additions and 37 deletions

View file

@ -286,6 +286,10 @@ pub struct App {
/// between the library and the game (opponent-prep.md §3.1).
prep_dialog: Option<PrepDialog>,
prep: Option<PrepScreen>,
/// The library's «Preparations» window, and a saved preparation waiting for its
/// database to be read.
prep_list: Option<crate::prep_ui::PrepList>,
prep_waiting: Option<crate::prep_ui::PrepStart>,
/// Quitting while the opening errors are searched: asked first; «Quit» answered.
prep_quit_ask: bool,
prep_quit_ok: bool,
@ -511,6 +515,8 @@ impl App {
reference: Default::default(),
prep_dialog: None,
prep: None,
prep_list: None,
prep_waiting: None,
prep_quit_ask: false,
prep_quit_ok: false,
engine_offer: crate::engine_offer::EngineOffer::new(),
@ -928,6 +934,71 @@ impl App {
}
}
/// «📑 Preparations», and a saved preparation opened once its database is read.
fn prep_list(&mut self, ctx: &egui::Context) {
if let Some(start) = self.prep_waiting.take() {
if self.library.database(&start.path).is_some() {
self.open_prep(ctx, start);
} else if let Some(e) = self.library.failure(&start.path) {
let e = e.to_owned();
self.toast(
ctx,
trf("This database cannot be opened: {e}", &[("e", &e)]),
);
} else {
self.prep_waiting = Some(start);
}
}
let Some(list) = self.prep_list.as_mut() else {
return;
};
let can_new = !self.settings.databases.is_empty();
match list.show(ctx, can_new) {
Some(crate::prep_ui::ListOutcome::Close) => self.prep_list = None,
Some(crate::prep_ui::ListOutcome::New) => {
self.prep_list = None;
let (path, entry) = match self.library.prep_entry() {
Some((path, entry)) => (path, entry.unwrap_or_default()),
None => match self.settings.databases.first() {
Some(p) => (p.clone(), Default::default()),
None => return,
},
};
self.prep_dialog = Some(PrepDialog::new(path, entry));
}
Some(crate::prep_ui::ListOutcome::Open(id)) => {
let Some(meta) = crate::prep_saved::dir()
.as_deref()
.and_then(|d| crate::prep_saved::get(d, &id))
else {
return;
};
self.prep_list = None;
if !self.settings.databases.contains(&meta.path) {
self.settings.touch_database(&meta.path);
self.settings_dirty = true;
}
let dbs = self.shelf_dbs();
let start = crate::prep_ui::PrepStart {
book: crate::prep_ui::BookChoice::from_setting(
Some(&meta.book),
&meta.path,
&dbs,
),
path: meta.path,
player: meta.player,
side: meta.color,
};
if self.library.database(&start.path).is_none() {
self.library.load(&start.path, ctx);
}
self.prep_waiting = Some(start);
ctx.request_repaint();
}
None => {}
}
}
/// The preparation's dialog, when it is open.
fn prep_dialog(&mut self, ctx: &egui::Context) {
if self.prep_dialog.is_none() {
@ -3942,6 +4013,9 @@ impl eframe::App for App {
LibraryAction::PrepareAgainst { path, entry } => {
self.prep_dialog = Some(PrepDialog::new(path, entry));
}
LibraryAction::Preparations => {
self.prep_list = Some(crate::prep_ui::PrepList::new());
}
}
}
}
@ -4020,6 +4094,7 @@ impl eframe::App for App {
self.confirm_dialog(&ctx);
self.own_dialogs(&ctx);
self.prep_list(&ctx);
self.prep_dialog(&ctx);
self.prep_quit_question(&ctx);
// Whether the database the dialog names is there, as last found.