Set up SGF reading and start on the game database #47

Merged
savanni merged 20 commits from kifu/sgf into main 2023-07-26 13:54:28 +00:00
8 changed files with 76 additions and 30 deletions
Showing only changes of commit 1b9a8eee67 - Show all commits

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
types::{AppState, GameState, Player, Rank}, types::{AppState, GameState, Player, Rank},
ui::{new_game, playing_field, NewGameView, PlayingFieldView}, ui::{home, playing_field, HomeView, PlayingFieldView},
Config, Config,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -13,7 +13,7 @@ use typeshare::typeshare;
pub enum CoreRequest { pub enum CoreRequest {
CreateGame(CreateGameRequest), CreateGame(CreateGameRequest),
LaunchScreen, LaunchScreen,
NewGame, Home,
PlayingField, PlayingField,
PlayStone(PlayStoneRequest), PlayStone(PlayStoneRequest),
StartGame, StartGame,
@ -59,7 +59,7 @@ impl From<HotseatPlayerRequest> for Player {
#[typeshare] #[typeshare]
#[serde(tag = "type", content = "content")] #[serde(tag = "type", content = "content")]
pub enum CoreResponse { pub enum CoreResponse {
NewGameView(NewGameView), HomeView(HomeView),
PlayingFieldView(PlayingFieldView), PlayingFieldView(PlayingFieldView),
} }
@ -113,8 +113,8 @@ impl CoreApp {
let game_state = app_state.game.as_ref().unwrap(); let game_state = app_state.game.as_ref().unwrap();
CoreResponse::PlayingFieldView(playing_field(game_state)) CoreResponse::PlayingFieldView(playing_field(game_state))
} }
CoreRequest::LaunchScreen => CoreResponse::NewGameView(new_game()), CoreRequest::LaunchScreen => CoreResponse::HomeView(home()),
CoreRequest::NewGame => CoreResponse::NewGameView(new_game()), CoreRequest::Home => CoreResponse::HomeView(home()),
CoreRequest::PlayingField => { CoreRequest::PlayingField => {
let app_state = self.state.read().unwrap(); let app_state = self.state.read().unwrap();
let game = app_state.game.as_ref().unwrap(); let game = app_state.game.as_ref().unwrap();

View File

@ -13,4 +13,5 @@ mod database;
mod types; mod types;
pub use types::{BoardError, Color, Rank, Size}; pub use types::{BoardError, Color, Rank, Size};
pub mod ui; pub mod ui;

View File

@ -48,13 +48,13 @@ pub struct BotPlayerElement {}
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[typeshare] #[typeshare]
pub struct NewGameView { pub struct HomeView {
pub black_player: PlayerElement, pub black_player: PlayerElement,
pub white_player: PlayerElement, pub white_player: PlayerElement,
pub start_game: Action<()>, pub start_game: Action<()>,
} }
pub fn new_game() -> NewGameView { pub fn home() -> HomeView {
let black_player = PlayerElement::Hotseat(HotseatPlayerElement { let black_player = PlayerElement::Hotseat(HotseatPlayerElement {
placeholder: Some("black player".to_owned()), placeholder: Some("black player".to_owned()),
default_rank: None, default_rank: None,
@ -65,7 +65,7 @@ pub fn new_game() -> NewGameView {
default_rank: None, default_rank: None,
ranks: rank_strings(), ranks: rank_strings(),
}); });
NewGameView { HomeView {
black_player, black_player,
white_player, white_player,
start_game: Action { start_game: Action {

View File

@ -7,8 +7,8 @@ pub use playing_field::{playing_field, PlayingFieldView};
// mod launch_screen; // mod launch_screen;
// pub use launch_screen::{launch_screen, LaunchScreenView}; // pub use launch_screen::{launch_screen, LaunchScreenView};
mod new_game; mod home;
pub use new_game::{new_game, HotseatPlayerElement, NewGameView, PlayerElement}; pub use home::{home, HomeView, HotseatPlayerElement, PlayerElement};
mod types; mod types;
pub use types::{ pub use types::{

49
kifu/gtk/Cargo.lock generated
View File

@ -121,6 +121,7 @@ dependencies = [
"js-sys", "js-sys",
"num-integer", "num-integer",
"num-traits", "num-traits",
"time",
"wasm-bindgen", "wasm-bindgen",
"winapi", "winapi",
] ]
@ -442,7 +443,7 @@ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
"libc", "libc",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen", "wasm-bindgen",
] ]
@ -543,6 +544,15 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "go-sgf"
version = "0.1.0"
dependencies = [
"chrono",
"nom",
"thiserror",
]
[[package]] [[package]]
name = "gobject-sys" name = "gobject-sys"
version = "0.17.4" version = "0.17.4"
@ -785,6 +795,8 @@ dependencies = [
name = "kifu-core" name = "kifu-core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"go-sgf",
"grid", "grid",
"serde", "serde",
"serde_json", "serde_json",
@ -862,6 +874,12 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.6.2" version = "0.6.2"
@ -879,7 +897,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys", "windows-sys",
] ]
@ -898,6 +916,16 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@ -1330,6 +1358,17 @@ dependencies = [
"weezl", "weezl",
] ]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.26.0" version = "1.26.0"
@ -1433,6 +1472,12 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use kifu_core::{CoreApp, CoreRequest, CoreResponse}; use kifu_core::{CoreApp, CoreRequest, CoreResponse};
use kifu_gtk::{ use kifu_gtk::{
perftrace, perftrace,
ui::{NewGame, PlayingField}, ui::{Home, PlayingField},
CoreApi, CoreApi,
}; };
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
@ -10,10 +10,10 @@ use std::sync::{Arc, RwLock};
fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreResponse) { fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreResponse) {
let playing_field = Arc::new(RwLock::new(None)); let playing_field = Arc::new(RwLock::new(None));
match message { match message {
CoreResponse::NewGameView(view) => perftrace("NewGameView", || { CoreResponse::HomeView(view) => perftrace("HomeView", || {
let api = api.clone(); let api = api.clone();
let new_game = NewGame::new(api, view); let new_game = Home::new(api, view);
window.set_child(Some(&new_game)); window.set_child(Some(&new_game));
}), }),
CoreResponse::PlayingFieldView(view) => perftrace("PlayingFieldView", || { CoreResponse::PlayingFieldView(view) => perftrace("PlayingFieldView", || {
@ -87,7 +87,7 @@ fn main() {
} }
}); });
api.dispatch(CoreRequest::NewGame); api.dispatch(CoreRequest::Home);
} }
}); });

View File

@ -2,7 +2,7 @@ use crate::CoreApi;
use glib::Object; use glib::Object;
use gtk::{glib, prelude::*, subclass::prelude::*}; use gtk::{glib, prelude::*, subclass::prelude::*};
use kifu_core::{ use kifu_core::{
ui::{NewGameView, PlayerElement}, ui::{HomeView, PlayerElement},
CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest, CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
}; };
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
@ -82,12 +82,12 @@ impl PlayerDataEntry {
} }
} }
pub struct NewGamePrivate { pub struct HomePrivate {
black_player: Rc<RefCell<Option<PlayerDataEntry>>>, black_player: Rc<RefCell<Option<PlayerDataEntry>>>,
white_player: Rc<RefCell<Option<PlayerDataEntry>>>, white_player: Rc<RefCell<Option<PlayerDataEntry>>>,
} }
impl Default for NewGamePrivate { impl Default for HomePrivate {
fn default() -> Self { fn default() -> Self {
Self { Self {
black_player: Rc::new(RefCell::new(None)), black_player: Rc::new(RefCell::new(None)),
@ -97,22 +97,22 @@ impl Default for NewGamePrivate {
} }
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for NewGamePrivate { impl ObjectSubclass for HomePrivate {
const NAME: &'static str = "NewGame"; const NAME: &'static str = "Home";
type Type = NewGame; type Type = Home;
type ParentType = gtk::Grid; type ParentType = gtk::Grid;
} }
impl ObjectImpl for NewGamePrivate {} impl ObjectImpl for HomePrivate {}
impl WidgetImpl for NewGamePrivate {} impl WidgetImpl for HomePrivate {}
impl GridImpl for NewGamePrivate {} impl GridImpl for HomePrivate {}
glib::wrapper! { glib::wrapper! {
pub struct NewGame(ObjectSubclass<NewGamePrivate>) @extends gtk::Grid, gtk::Widget; pub struct Home(ObjectSubclass<HomePrivate>) @extends gtk::Grid, gtk::Widget;
} }
impl NewGame { impl Home {
pub fn new(api: CoreApi, view: NewGameView) -> NewGame { pub fn new(api: CoreApi, view: HomeView) -> Home {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
let black_player = PlayerDataEntry::new(view.black_player); let black_player = PlayerDataEntry::new(view.black_player);

View File

@ -7,8 +7,8 @@ pub use chat::Chat;
mod playing_field; mod playing_field;
pub use playing_field::PlayingField; pub use playing_field::PlayingField;
mod new_game; mod home;
pub use new_game::NewGame; pub use home::Home;
mod board; mod board;
pub use board::Board; pub use board::Board;