Show a list of games in the library #64

Merged
savanni merged 9 commits from kifu/game-library into main 2023-08-20 17:02:14 +00:00
3 changed files with 13 additions and 0 deletions
Showing only changes of commit d8534a08eb - Show all commits

View File

@ -6,6 +6,7 @@ use typeshare::typeshare;
#[typeshare]
pub struct GamePreviewElement {
pub date: Vec<String>,
pub name: String,
pub black_player: String,
pub white_player: String,
}
@ -31,6 +32,11 @@ impl GamePreviewElement {
None => white_player,
};
let name = match game.info.game_name {
Some(ref name) => name.clone(),
None => format!("{} vs. {}", black_player, white_player),
};
GamePreviewElement {
date: game
.info
@ -38,6 +44,7 @@ impl GamePreviewElement {
.iter()
.map(|dt| dt.to_string())
.collect::<Vec<String>>(),
name,
black_player,
white_player,
}

View File

@ -43,6 +43,7 @@ impl GamePreview {
pub fn set_game(&self, element: GamePreviewElement) {
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);
}

View File

@ -99,6 +99,11 @@ impl TryFrom<Tree> for Game {
info.app_name = tree.sequence[0]
.find_prop("AP")
.map(|prop| prop.values[0].clone());
info.game_name = tree.sequence[0]
.find_prop("GN")
.map(|prop| prop.values[0].clone());
info.black_player = tree.sequence[0]
.find_prop("PB")
.map(|prop| prop.values.join(", "));