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 Request { PlayingField, PlayStoneRequest(PlayStoneRequest), } #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[typeshare] pub struct PlayStoneRequest { pub column: usize, pub row: usize, } #[derive(Clone, Debug, Serialize, Deserialize)] #[typeshare] #[serde(tag = "type", content = "content")] pub enum Response { 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: Request) -> Response { match request { Request::PlayingField => { let app_state = self.state.read().unwrap(); let game = app_state.game.as_ref().unwrap(); Response::PlayingFieldView(playing_field(game)) } Request::PlayStoneRequest(request) => { let mut app_state = self.state.write().unwrap(); app_state.place_stone(request); let game = app_state.game.as_ref().unwrap(); Response::PlayingFieldView(playing_field(game)) } } } pub async fn run(&self) {} }