use crate::types::AppState; use crate::ui::{playing_field, PlayingFieldView}; use serde::{Deserialize, Serialize}; use std::sync::{Arc, RwLock}; use typeshare::typeshare; #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[typeshare] #[serde(tag = "type", content = "content")] pub enum CoreRequest { PlayingField, PlayStoneRequest(PlayStoneRequest), } #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[typeshare] pub struct PlayStoneRequest { pub column: u8, pub row: u8, } #[derive(Clone, Debug, Serialize, Deserialize)] #[typeshare] #[serde(tag = "type", content = "content")] pub enum CoreResponse { PlayingFieldView(PlayingFieldView), } #[derive(Clone, Debug)] pub struct CoreApp { state: Arc>, } impl CoreApp { pub fn new() -> Self { let state = Arc::new(RwLock::new(AppState::new())); Self { state } } pub async fn dispatch(&self, request: CoreRequest) -> CoreResponse { match request { CoreRequest::PlayingField => { let app_state = self.state.read().unwrap(); let game = app_state.game.as_ref().unwrap(); CoreResponse::PlayingFieldView(playing_field(game)) } CoreRequest::PlayStoneRequest(request) => { let mut app_state = self.state.write().unwrap(); app_state.place_stone(request); let game = app_state.game.as_ref().unwrap(); CoreResponse::PlayingFieldView(playing_field(game)) } } } pub async fn run(&self) {} }