diff --git a/sgf/src/go.rs b/sgf/src/go.rs index 6a610a5..167b0c2 100644 --- a/sgf/src/go.rs +++ b/sgf/src/go.rs @@ -78,23 +78,16 @@ use typeshare::typeshare; #[derive(Clone, Debug)] pub struct Game { - pub file_format: i8, - pub app_name: Option, pub board_size: Size, pub info: GameInfo, + + pub tree: Tree, } impl TryFrom for Game { type Error = Error; fn try_from(tree: Tree) -> Result { - let file_format = match tree.sequence[0].find_prop("FF") { - Some(prop) => prop.values[0].parse::().unwrap(), - None => 4, - }; - let app_name = tree.sequence[0] - .find_prop("AP") - .map(|prop| prop.values[0].clone()); let board_size = match tree.sequence[0].find_prop("SZ") { Some(prop) => Size::try_from(prop.values[0].as_str())?, None => Size { @@ -103,6 +96,9 @@ impl TryFrom for Game { }, }; let mut info = GameInfo::default(); + info.app_name = tree.sequence[0] + .find_prop("AP") + .map(|prop| prop.values[0].clone()); info.black_player = tree.sequence[0] .find_prop("PB") .map(|prop| prop.values.join(", ")); @@ -165,10 +161,10 @@ impl TryFrom for Game { .map(|prop| prop.values.join(", ")); Ok(Game { - file_format, - app_name, board_size, info, + + tree, }) } } @@ -203,6 +199,7 @@ impl ToString for Rank { #[derive(Clone, Debug, Default)] pub struct GameInfo { + pub app_name: Option, pub annotator: Option, pub copyright: Option, pub event: Option, @@ -335,8 +332,7 @@ mod tests { with_text(EXAMPLE, |trees| { assert_eq!(trees.len(), 1); let tree = &trees[0]; - assert_eq!(tree.file_format, 4); - assert_eq!(tree.app_name, None); + assert_eq!(tree.info.app_name, None); assert_eq!( tree.board_size, Size { @@ -350,8 +346,7 @@ mod tests { with_file(std::path::Path::new("test_data/print1.sgf"), |trees| { assert_eq!(trees.len(), 1); let tree = &trees[0]; - assert_eq!(tree.file_format, 4); - assert_eq!(tree.app_name, None); + assert_eq!(tree.info.app_name, None); assert_eq!( tree.board_size, Size { diff --git a/sgf/src/tree.rs b/sgf/src/tree.rs index c0d46ff..59d24c0 100644 --- a/sgf/src/tree.rs +++ b/sgf/src/tree.rs @@ -52,7 +52,7 @@ impl TryFrom<&str> for Size { } } -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct Tree { pub sequence: Vec, pub sub_sequences: Vec, @@ -74,7 +74,7 @@ impl ToString for Tree { } } -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct Node { pub properties: Vec, }