2023-08-06 01:59:30 +00:00
|
|
|
use serde_wasm_bindgen::Error;
|
|
|
|
use wasm_bindgen::JsValue;
|
|
|
|
use wasm_bindgen::prelude::wasm_bindgen;
|
2023-08-10 03:00:14 +00:00
|
|
|
use crate::board::CellType;
|
2023-08-06 01:59:30 +00:00
|
|
|
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<JsValue, Error> {
|
|
|
|
let tray = self.0.get_tray();
|
|
|
|
|
|
|
|
serde_wasm_bindgen::to_value(tray)
|
|
|
|
}
|
2023-08-10 03:00:14 +00:00
|
|
|
|
|
|
|
pub fn get_board_cell_types(&self) -> Result<JsValue, Error> {
|
|
|
|
let board = self.0.get_board();
|
|
|
|
|
|
|
|
let cell_types: Vec<CellType> = board.cells.iter().map(|cell| -> CellType {
|
|
|
|
cell.cell_type.clone()
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
serde_wasm_bindgen::to_value(&cell_types)
|
|
|
|
}
|
2023-08-06 01:59:30 +00:00
|
|
|
}
|