use serde_wasm_bindgen::Error; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; use crate::board::CellType; use crate::game::Game; #[wasm_bindgen] pub struct GameWasm(Game); #[wasm_bindgen] impl GameWasm { #[wasm_bindgen(constructor)] pub fn new(seed: u64) -> GameWasm { GameWasm(Game::new(seed)) } pub fn get_tray(&self) -> Result { let tray = self.0.get_tray(); serde_wasm_bindgen::to_value(tray) } pub fn get_board_cell_types(&self) -> Result { let board = self.0.get_board(); let cell_types: Vec = board.cells.iter().map(|cell| -> CellType { cell.cell_type.clone() }).collect(); serde_wasm_bindgen::to_value(&cell_types) } }