From 3c063af525ff0293bc29f8018be5d456b9eb6aad Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 20 Aug 2023 13:17:54 -0400 Subject: [PATCH] Add the game result to the list of visible games --- kifu/core/src/ui/elements/game_preview.rs | 25 +++++++++++++++++++---- kifu/gtk/src/ui/game_preview.rs | 9 ++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/kifu/core/src/ui/elements/game_preview.rs b/kifu/core/src/ui/elements/game_preview.rs index afc9e2b..b8660f6 100644 --- a/kifu/core/src/ui/elements/game_preview.rs +++ b/kifu/core/src/ui/elements/game_preview.rs @@ -1,14 +1,15 @@ use serde::{Deserialize, Serialize}; -use sgf::go::Game; +use sgf::go::{Game, GameResult, Win}; use typeshare::typeshare; #[derive(Clone, Debug, Deserialize, Serialize)] #[typeshare] pub struct GamePreviewElement { - pub date: Vec, + pub date: String, pub name: String, pub black_player: String, pub white_player: String, + pub result: String, } impl GamePreviewElement { @@ -37,16 +38,32 @@ impl GamePreviewElement { None => format!("{} vs. {}", black_player, white_player), }; + let format_win = |win: &Win| match win { + Win::Resignation => "Resignation".to_owned(), + Win::Time => "Timeout".to_owned(), + Win::Forfeit => "Forfeit".to_owned(), + Win::Score(score) => format!("{:.1}", score), + }; + + let result = match game.info.result { + Some(GameResult::Annulled) => "Annulled".to_owned(), + Some(GameResult::Draw) => "Draw".to_owned(), + Some(GameResult::Black(ref win)) => format!("Black by {}", format_win(win)), + Some(GameResult::White(ref win)) => format!("White by {}", format_win(win)), + None => "".to_owned(), + }; + GamePreviewElement { date: game .info .date - .iter() + .first() .map(|dt| dt.to_string()) - .collect::>(), + .unwrap_or("".to_owned()), name, black_player, white_player, + result, } } } diff --git a/kifu/gtk/src/ui/game_preview.rs b/kifu/gtk/src/ui/game_preview.rs index ed0d131..feafa96 100644 --- a/kifu/gtk/src/ui/game_preview.rs +++ b/kifu/gtk/src/ui/game_preview.rs @@ -4,10 +4,11 @@ use kifu_core::ui::GamePreviewElement; #[derive(Default)] pub struct GamePreviewPrivate { + date: gtk::Label, title: gtk::Label, black_player: gtk::Label, white_player: gtk::Label, - date: gtk::Label, + result: gtk::Label, } #[glib::object_subclass] @@ -36,6 +37,7 @@ impl GamePreview { s.append(&s.imp().title); s.append(&s.imp().black_player); s.append(&s.imp().white_player); + s.append(&s.imp().result); s } @@ -44,8 +46,7 @@ impl GamePreview { self.imp().black_player.set_text(&element.black_player); self.imp().white_player.set_text(&element.white_player); self.imp().title.set_text(&element.name); - if let Some(date) = element.date.first() { - self.imp().date.set_text(&date); - } + self.imp().date.set_text(&element.date); + self.imp().result.set_text(&element.result); } } -- 2.44.1