Set up SGF reading and start on the game database #47
|
@ -51,6 +51,7 @@ dependencies = [
|
|||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
|
@ -68,7 +69,9 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"chrono",
|
||||
"nom",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"typeshare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -94,6 +97,12 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.64"
|
||||
|
@ -170,6 +179,54 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.164"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.164"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.18"
|
||||
|
@ -198,7 +255,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -212,6 +269,28 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeshare"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"typeshare-annotation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeshare-annotation"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc670d0e358428857cc3b4bf504c691e572fccaec9542ff09212d3f13d74b7a9"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.9"
|
||||
|
@ -245,7 +324,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.18",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -267,7 +346,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.18",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
|
|
@ -6,6 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4", features = [ "serde" ] }
|
||||
nom = { version = "7" }
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
thiserror = { version = "1"}
|
||||
chrono = { version = "0.4" }
|
||||
typeshare = { version = "1" }
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use chrono::{Datelike, NaiveDate};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::num::ParseIntError;
|
||||
use thiserror::Error;
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
pub enum Error {
|
||||
|
@ -14,7 +16,8 @@ pub enum Error {
|
|||
Unsupported,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd)]
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize, Serialize)]
|
||||
#[typeshare]
|
||||
pub enum Date {
|
||||
Year(i32),
|
||||
YearMonth(i32, u32),
|
||||
|
|
|
@ -72,6 +72,8 @@ use crate::{
|
|||
date::{self, parse_date_field, Date},
|
||||
tree::{parse_collection, ParseSizeError, Size},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<'a> {
|
||||
|
@ -97,7 +99,8 @@ impl<'a> From<ParseSizeError> for Error<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub enum Rank {
|
||||
Kyu(u8),
|
||||
Dan(u8),
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
pub mod date;
|
||||
pub mod go;
|
||||
pub mod tree;
|
||||
mod date;
|
||||
pub use date::Date;
|
||||
|
||||
mod go;
|
||||
pub use go::{parse_sgf, GameTree, GameType, Rank};
|
||||
|
||||
mod tree;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ dependencies = [
|
|||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
|
@ -125,7 +126,9 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"chrono",
|
||||
"nom",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"typeshare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -74,6 +74,8 @@ impl CoreApp {
|
|||
let config = Config::from_path(config_path).expect("configuration to open");
|
||||
let state = Arc::new(RwLock::new(AppState::new()));
|
||||
|
||||
println!("config: {:?}", config);
|
||||
|
||||
Self { config, state }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{ffi::OsStr, io::Read, os::unix::ffi::OsStrExt, path::PathBuf};
|
||||
|
||||
use go_sgf::go::{parse_sgf, GameTree, GameType};
|
||||
use go_sgf::{parse_sgf, GameTree};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
@ -58,6 +58,7 @@ impl Database {
|
|||
mod test {
|
||||
use super::*;
|
||||
use cool_asserts::assert_matches;
|
||||
use go_sgf::{Date, GameType};
|
||||
|
||||
#[test]
|
||||
fn it_reads_empty_database() {
|
||||
|
@ -79,7 +80,7 @@ mod test {
|
|||
Some(game) => {
|
||||
assert_eq!(game.info.black_player, Some("Steve".to_owned()));
|
||||
assert_eq!(game.info.white_player, Some("Savanni".to_owned()));
|
||||
assert_eq!(game.info.date, vec![chrono::NaiveDate::from_ymd_opt(2023, 4, 19).unwrap()]);
|
||||
assert_eq!(game.info.date, vec![Date::Date(chrono::NaiveDate::from_ymd_opt(2023, 4, 19).unwrap())]);
|
||||
assert_eq!(game.info.komi, Some(6.5));
|
||||
}
|
||||
);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
use go_sgf::{Date, GameTree, Rank};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[typeshare]
|
||||
pub struct GamePreviewElement {
|
||||
pub date: Vec<Date>,
|
||||
pub black_player: String,
|
||||
pub black_rank: Option<Rank>,
|
||||
pub white_player: String,
|
||||
pub white_rank: Option<Rank>,
|
||||
}
|
||||
|
||||
impl GamePreviewElement {
|
||||
pub fn new(game: GameTree) -> GamePreviewElement {
|
||||
GamePreviewElement {
|
||||
date: game.info.date.clone(),
|
||||
black_player: game
|
||||
.info
|
||||
.black_player
|
||||
.clone()
|
||||
.unwrap_or("black_player".to_owned()),
|
||||
black_rank: game.info.black_rank.clone(),
|
||||
white_player: game
|
||||
.info
|
||||
.white_player
|
||||
.clone()
|
||||
.unwrap_or("white_player".to_owned()),
|
||||
white_rank: game.info.white_rank.clone(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod action;
|
||||
pub mod game_preview;
|
||||
pub mod menu;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::ui::Action;
|
||||
use crate::ui::{Action, GamePreviewElement};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
|
@ -51,6 +51,7 @@ pub struct BotPlayerElement {}
|
|||
pub struct HomeView {
|
||||
pub black_player: PlayerElement,
|
||||
pub white_player: PlayerElement,
|
||||
pub games: Vec<GamePreviewElement>,
|
||||
pub start_game: Action<()>,
|
||||
}
|
||||
|
||||
|
@ -68,6 +69,7 @@ pub fn home() -> HomeView {
|
|||
HomeView {
|
||||
black_player,
|
||||
white_player,
|
||||
games: vec![],
|
||||
start_game: Action {
|
||||
id: "start-game-action".to_owned(),
|
||||
label: "New Game".to_owned(),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod elements;
|
||||
pub use elements::{action::Action, menu::Menu};
|
||||
pub use elements::{action::Action, game_preview::GamePreviewElement, menu::Menu};
|
||||
|
||||
mod playing_field;
|
||||
pub use playing_field::{playing_field, PlayingFieldView};
|
||||
|
|
|
@ -121,6 +121,7 @@ dependencies = [
|
|||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
|
@ -550,7 +551,9 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"chrono",
|
||||
"nom",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"typeshare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
Loading…
Reference in New Issue