use crate::types::AppState; use crate::ui::{playing_field, PlayingFieldView}; use std::sync::{Arc, RwLock}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Request { PlayingField, PlayStoneRequest(PlayStoneRequest), } #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PlayStoneRequest { pub column: usize, pub row: usize, } #[derive(Clone, Debug)] pub enum Response { PlayingFieldView(PlayingFieldView), } #[derive(Clone)] 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) {} }