diff --git a/kifu/core/src/database.rs b/kifu/core/src/database.rs index 9ace920..cad6a5c 100644 --- a/kifu/core/src/database.rs +++ b/kifu/core/src/database.rs @@ -1,6 +1,6 @@ use std::{ffi::OsStr, io::Read, os::unix::ffi::OsStrExt, path::PathBuf}; -use sgf::{parse_sgf, GameTree}; +use sgf::{go, parse_sgf, Game}; use thiserror::Error; #[derive(Error, Debug)] @@ -20,12 +20,12 @@ impl From for Error { #[derive(Debug)] pub struct Database { path: PathBuf, - games: Vec, + games: Vec, } impl Database { pub fn open_path(path: PathBuf) -> Result { - let mut games: Vec = Vec::new(); + let mut games: Vec = Vec::new(); let extension = PathBuf::from("sgf").into_os_string(); @@ -39,8 +39,12 @@ impl Database { .unwrap() .read_to_string(&mut buffer) .unwrap(); - let sgf = parse_sgf(&buffer).unwrap(); - games.extend(sgf); + for sgf in parse_sgf(&buffer).unwrap() { + match sgf { + Game::Go(game) => games.push(game), + Game::Unsupported(_) => {} + } + } } } Err(err) => println!("failed entry: {:?}", err), @@ -54,7 +58,7 @@ impl Database { self.games.len() } - pub fn all_games(&self) -> impl Iterator { + pub fn all_games(&self) -> impl Iterator { self.games.iter() } } @@ -63,7 +67,7 @@ impl Database { mod test { use super::*; use cool_asserts::assert_matches; - use sgf::{Date, GameType}; + use sgf::Date; #[test] fn it_reads_empty_database() { @@ -77,9 +81,7 @@ mod test { let db = Database::open_path(PathBuf::from("fixtures/five_games/")).expect("database to open"); assert_eq!(db.all_games().count(), 5); - for game in db.all_games() { - assert_eq!(game.game_type, GameType::Go); - } + for game in db.all_games() {} assert_matches!(db.all_games().find(|g| g.info.black_player == Some("Steve".to_owned())), Some(game) => { diff --git a/kifu/core/src/ui/elements/game_preview.rs b/kifu/core/src/ui/elements/game_preview.rs index 6669d71..1624fb9 100644 --- a/kifu/core/src/ui/elements/game_preview.rs +++ b/kifu/core/src/ui/elements/game_preview.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use sgf::{Date, GameTree, Rank}; +use sgf::{ + go::{Game, Rank}, + Date, +}; use typeshare::typeshare; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -13,7 +16,7 @@ pub struct GamePreviewElement { } impl GamePreviewElement { - pub fn new(game: &GameTree) -> GamePreviewElement { + pub fn new(game: &Game) -> GamePreviewElement { GamePreviewElement { date: game.info.date.clone(), black_player: game diff --git a/kifu/core/src/ui/home.rs b/kifu/core/src/ui/home.rs index 7c06ae2..59a064b 100644 --- a/kifu/core/src/ui/home.rs +++ b/kifu/core/src/ui/home.rs @@ -1,6 +1,6 @@ use crate::ui::{Action, GamePreviewElement}; use serde::{Deserialize, Serialize}; -use sgf::GameTree; +use sgf::go::Game; use typeshare::typeshare; fn rank_strings() -> Vec { @@ -56,7 +56,7 @@ pub struct HomeView { pub start_game: Action<()>, } -pub fn home<'a>(games: impl Iterator) -> HomeView { +pub fn home<'a>(games: impl Iterator) -> HomeView { let black_player = PlayerElement::Hotseat(HotseatPlayerElement { placeholder: Some("black player".to_owned()), default_rank: None, diff --git a/sgf/src/go.rs b/sgf/src/go.rs index 831a092..6a610a5 100644 --- a/sgf/src/go.rs +++ b/sgf/src/go.rs @@ -76,6 +76,7 @@ use crate::{ use serde::{Deserialize, Serialize}; use typeshare::typeshare; +#[derive(Clone, Debug)] pub struct Game { pub file_format: i8, pub app_name: Option,