Show the name of the game, and create one if it doesn't exist

This commit is contained in:
Savanni D'Gerinel 2023-08-20 12:53:14 -04:00
parent e5d0b7d20f
commit d8534a08eb
3 changed files with 13 additions and 0 deletions

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(", "));