Opponent prep: the tester's findings
A saved preparation is the player's by his names, not the database's name ids (they shift when a game is deleted or the file is replaced): opened from the list, the names are found again. The period counts are of the games a report can take (set-up games left out first). A partly known date is in a period when any day it can mean is; a date after today is not the newest. Reopening a hidden report notices a deleted preparation; a colour change is saved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e80933d48d
commit
758856f458
6 changed files with 165 additions and 43 deletions
|
|
@ -289,7 +289,8 @@ pub struct App {
|
|||
/// 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>,
|
||||
/// The names of its player, found again in the database once it is read.
|
||||
prep_waiting: Option<(crate::prep_ui::PrepStart, Vec<String>)>,
|
||||
/// Quitting while the opening errors are searched: asked first; «Quit» answered.
|
||||
prep_quit_ask: bool,
|
||||
prep_quit_ok: bool,
|
||||
|
|
@ -941,9 +942,31 @@ 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);
|
||||
if let Some((mut start, names)) = self.prep_waiting.take() {
|
||||
if let Some(db) = self.library.database(&start.path) {
|
||||
// The player by his names: the database's ids of them may have changed.
|
||||
let mut ids = Vec::new();
|
||||
let mut missing = None;
|
||||
for name in &names {
|
||||
let (found, _) = prep::candidates(&db, name, 50);
|
||||
match found.iter().find(|c| c.name == *name) {
|
||||
Some(c) => ids.push(c.id),
|
||||
None => missing = Some(name.clone()),
|
||||
}
|
||||
}
|
||||
match missing {
|
||||
Some(name) => self.toast(
|
||||
ctx,
|
||||
trf(
|
||||
"The player is not in the database: {name}",
|
||||
&[("name", &name)],
|
||||
),
|
||||
),
|
||||
None => {
|
||||
start.player = prep::Player::new(ids);
|
||||
self.open_prep(ctx, start);
|
||||
}
|
||||
}
|
||||
} else if let Some(e) = self.library.failure(&start.path) {
|
||||
let e = e.to_owned();
|
||||
self.toast(
|
||||
|
|
@ -951,7 +974,7 @@ impl App {
|
|||
trf("This database cannot be opened: {e}", &[("e", &e)]),
|
||||
);
|
||||
} else {
|
||||
self.prep_waiting = Some(start);
|
||||
self.prep_waiting = Some((start, names));
|
||||
}
|
||||
}
|
||||
let Some(list) = self.prep_list.as_mut() else {
|
||||
|
|
@ -998,7 +1021,7 @@ impl App {
|
|||
self.library.load(&start.path, ctx);
|
||||
self.toast(ctx, tr("Opening the database…"));
|
||||
}
|
||||
self.prep_waiting = Some(start);
|
||||
self.prep_waiting = Some((start, meta.names));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
None => {}
|
||||
|
|
|
|||
|
|
@ -16045,6 +16045,17 @@ const ROWS: &[[&str; 9]] = &[
|
|||
"Baza topilmadi: faylni joyiga qaytaring yoki tayyorgarlikni o‘chiring",
|
||||
"База табылмады: файлды орнына қайтарыңыз немесе дайындықты жойыңыз",
|
||||
],
|
||||
[
|
||||
"The player is not in the database: {name}",
|
||||
"Игрока нет в базе: {name}",
|
||||
"Le joueur n’est pas dans la base : {name}",
|
||||
"Der Spieler ist nicht in der Datenbank: {name}",
|
||||
"El jugador no está en la base: {name}",
|
||||
"Il giocatore non è nel database: {name}",
|
||||
"O jogador não está na base: {name}",
|
||||
"O‘yinchi bazada yo‘q: {name}",
|
||||
"Ойыншы базада жоқ: {name}",
|
||||
],
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ pub fn dir() -> Option<PathBuf> {
|
|||
crate::platform::data_dir().map(|d| d.join("preparations"))
|
||||
}
|
||||
|
||||
/// The id of the preparation of `player` in the database `path`.
|
||||
pub fn id(path: &Path, player: &Player) -> String {
|
||||
/// The id of the preparation of the player named `names` in the database `path`: by
|
||||
/// the names, not the database's name ids, which change when a game before his first
|
||||
/// one is deleted or the database is replaced by a new version.
|
||||
pub fn id(path: &Path, names: &[String]) -> String {
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
let mut eat = |b: u8| {
|
||||
h ^= u64::from(b);
|
||||
|
|
@ -50,8 +52,12 @@ pub fn id(path: &Path, player: &Player) -> String {
|
|||
for b in path.to_string_lossy().bytes() {
|
||||
eat(b);
|
||||
}
|
||||
for id in &player.ids {
|
||||
for b in id.to_le_bytes() {
|
||||
let mut names: Vec<&String> = names.iter().collect();
|
||||
names.sort();
|
||||
names.dedup();
|
||||
for n in names {
|
||||
eat(0);
|
||||
for b in n.bytes() {
|
||||
eat(b);
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +116,7 @@ pub fn report(dir: &Path, id: &str) -> Option<PrepReport> {
|
|||
/// Keeps `meta` and `report` as the preparation of their player and database (the
|
||||
/// report first: a list entry never points to a missing report).
|
||||
pub fn save(dir: &Path, meta: &SavedPrep, report: &PrepReport) -> std::io::Result<()> {
|
||||
let id = id(&meta.path, &meta.player);
|
||||
let id = id(&meta.path, &meta.names);
|
||||
let bytes = serde_json::to_vec(report).map_err(std::io::Error::other)?;
|
||||
write_atomic(&report_path(dir, &id), &bytes)?;
|
||||
let bytes = serde_json::to_vec_pretty(meta).map_err(std::io::Error::other)?;
|
||||
|
|
@ -183,7 +189,7 @@ mod tests {
|
|||
let l = list(&dir);
|
||||
assert_eq!(l.len(), 2);
|
||||
assert_eq!(l[0].1, a2);
|
||||
let ida = id(&a.path, &a.player);
|
||||
let ida = id(&a.path, &a.names);
|
||||
assert!(report_path(&dir, &ida).exists());
|
||||
assert!(super::report(&dir, &ida).is_some());
|
||||
rename(&dir, &ida, "Вафин — финал").expect("rename");
|
||||
|
|
|
|||
|
|
@ -1735,7 +1735,8 @@ impl PrepScreen {
|
|||
let mut cache = dir.as_deref().map(PositionCache::load).unwrap_or_default();
|
||||
// A saved preparation of this player: its depth and games, its report.
|
||||
let saved_dir = crate::prep_saved::dir();
|
||||
let saved_id = crate::prep_saved::id(&start.path, &start.player);
|
||||
let names = start.player.names(&db);
|
||||
let saved_id = crate::prep_saved::id(&start.path, &names);
|
||||
let saved = saved_dir
|
||||
.as_deref()
|
||||
.and_then(|d| crate::prep_saved::get(d, &saved_id));
|
||||
|
|
@ -1759,7 +1760,10 @@ impl PrepScreen {
|
|||
if r.search != game_review::SEARCH_VERSION {
|
||||
return None;
|
||||
}
|
||||
if r.fingerprint == prep::fingerprint(&db) && r.options() == options {
|
||||
if r.fingerprint == prep::fingerprint(&db)
|
||||
&& r.options() == options
|
||||
&& r.player == start.player
|
||||
{
|
||||
return Some(r);
|
||||
}
|
||||
for (k, e) in r.evals {
|
||||
|
|
@ -1767,7 +1771,6 @@ impl PrepScreen {
|
|||
}
|
||||
None
|
||||
});
|
||||
let names = start.player.names(&db);
|
||||
let mut screen = PrepScreen {
|
||||
serial: crate::engine_offer::next_serial(),
|
||||
db_name: base_name(&start.path),
|
||||
|
|
@ -1920,6 +1923,10 @@ impl PrepScreen {
|
|||
/// The same player asked for again from the dialog: its colour and book.
|
||||
pub fn reopen(&mut self, side: ColorChoice, book: BookChoice) {
|
||||
self.shown = true;
|
||||
// Deleted from «Preparations» while this screen was hidden: «Save» again.
|
||||
self.saved &= crate::prep_saved::dir().is_some_and(|d| {
|
||||
crate::prep_saved::get(&d, &crate::prep_saved::id(&self.path, &self.names)).is_some()
|
||||
});
|
||||
self.set_color(side);
|
||||
if book != self.book {
|
||||
self.book = book;
|
||||
|
|
@ -1929,6 +1936,8 @@ impl PrepScreen {
|
|||
}
|
||||
|
||||
fn set_color(&mut self, color: ColorChoice) {
|
||||
// The colour a saved preparation opens with.
|
||||
self.dirty |= self.saved && color != self.color;
|
||||
self.color = color;
|
||||
// A selection of a colour no longer shown is dropped.
|
||||
let keep = match &self.selection {
|
||||
|
|
@ -2463,7 +2472,7 @@ impl PrepScreen {
|
|||
}
|
||||
// Deleted from «Preparations» meanwhile: not written back.
|
||||
self.saved &= crate::prep_saved::dir().is_some_and(|d| {
|
||||
crate::prep_saved::get(&d, &crate::prep_saved::id(&self.path, &self.player))
|
||||
crate::prep_saved::get(&d, &crate::prep_saved::id(&self.path, &self.names))
|
||||
.is_some()
|
||||
});
|
||||
if self.saved
|
||||
|
|
@ -2485,7 +2494,7 @@ impl PrepScreen {
|
|||
let Some(report) = &self.report else {
|
||||
return Ok(());
|
||||
};
|
||||
let id = crate::prep_saved::id(&self.path, &self.player);
|
||||
let id = crate::prep_saved::id(&self.path, &self.names);
|
||||
let title = crate::prep_saved::get(&dir, &id)
|
||||
.map(|m| m.title)
|
||||
.unwrap_or_else(|| self.names.first().cloned().unwrap_or_default());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue