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

View File

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

View File

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

View File

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

49
kifu/gtk/Cargo.lock generated
View File

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

View File

@ -2,7 +2,7 @@ use gtk::prelude::*;
use kifu_core::{CoreApp, CoreRequest, CoreResponse};
use kifu_gtk::{
perftrace,
ui::{NewGame, PlayingField},
ui::{Home, PlayingField},
CoreApi,
};
use std::sync::{Arc, RwLock};
@ -10,10 +10,10 @@ use std::sync::{Arc, RwLock};
fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreResponse) {
let playing_field = Arc::new(RwLock::new(None));
match message {
CoreResponse::NewGameView(view) => perftrace("NewGameView", || {
CoreResponse::HomeView(view) => perftrace("HomeView", || {
let api = api.clone();
let new_game = NewGame::new(api, view);
let new_game = Home::new(api, view);
window.set_child(Some(&new_game));
}),
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 gtk::{glib, prelude::*, subclass::prelude::*};
use kifu_core::{
ui::{NewGameView, PlayerElement},
ui::{HomeView, PlayerElement},
CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
};
use std::{cell::RefCell, rc::Rc};
@ -82,12 +82,12 @@ impl PlayerDataEntry {
}
}
pub struct NewGamePrivate {
pub struct HomePrivate {
black_player: Rc<RefCell<Option<PlayerDataEntry>>>,
white_player: Rc<RefCell<Option<PlayerDataEntry>>>,
}
impl Default for NewGamePrivate {
impl Default for HomePrivate {
fn default() -> Self {
Self {
black_player: Rc::new(RefCell::new(None)),
@ -97,22 +97,22 @@ impl Default for NewGamePrivate {
}
#[glib::object_subclass]
impl ObjectSubclass for NewGamePrivate {
const NAME: &'static str = "NewGame";
type Type = NewGame;
impl ObjectSubclass for HomePrivate {
const NAME: &'static str = "Home";
type Type = Home;
type ParentType = gtk::Grid;
}
impl ObjectImpl for NewGamePrivate {}
impl WidgetImpl for NewGamePrivate {}
impl GridImpl for NewGamePrivate {}
impl ObjectImpl for HomePrivate {}
impl WidgetImpl for HomePrivate {}
impl GridImpl for HomePrivate {}
glib::wrapper! {
pub struct NewGame(ObjectSubclass<NewGamePrivate>) @extends gtk::Grid, gtk::Widget;
pub struct Home(ObjectSubclass<HomePrivate>) @extends gtk::Grid, gtk::Widget;
}
impl NewGame {
pub fn new(api: CoreApi, view: NewGameView) -> NewGame {
impl Home {
pub fn new(api: CoreApi, view: HomeView) -> Home {
let s: Self = Object::builder().build();
let black_player = PlayerDataEntry::new(view.black_player);

View File

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