fix: Use standard JSON output for WASM to match server output
This commit is contained in:
parent
3e187b57fb
commit
0a4c213644
1 changed files with 9 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
|||
use serde::Serialize;
|
||||
use serde_wasm_bindgen::Serializer;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsValue;
|
||||
use word_grid::api::APIGame;
|
||||
|
@ -6,6 +8,8 @@ use word_grid::player_interaction::ai::Difficulty;
|
|||
|
||||
const PLAYER_NAME: &str = "Player";
|
||||
|
||||
const SERIALIZER: Serializer = Serializer::json_compatible();
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmAPI(APIGame);
|
||||
|
||||
|
@ -30,18 +34,18 @@ impl WasmAPI {
|
|||
|
||||
let result = self.0.exchange(PLAYER_NAME, selection);
|
||||
|
||||
serde_wasm_bindgen::to_value(&result).unwrap()
|
||||
result.serialize(&SERIALIZER).unwrap()
|
||||
}
|
||||
|
||||
pub fn pass(&mut self) -> JsValue {
|
||||
let result = self.0.pass(PLAYER_NAME);
|
||||
|
||||
serde_wasm_bindgen::to_value(&result).unwrap()
|
||||
result.serialize(&SERIALIZER).unwrap()
|
||||
}
|
||||
|
||||
pub fn load(&mut self) -> JsValue {
|
||||
let result = self.0.load(PLAYER_NAME);
|
||||
serde_wasm_bindgen::to_value(&result).unwrap()
|
||||
result.serialize(&SERIALIZER).unwrap()
|
||||
}
|
||||
|
||||
pub fn play(&mut self, tray_tile_locations: JsValue, commit_move: bool) -> JsValue {
|
||||
|
@ -49,12 +53,12 @@ impl WasmAPI {
|
|||
serde_wasm_bindgen::from_value(tray_tile_locations).unwrap();
|
||||
|
||||
let result = self.0.play(PLAYER_NAME, tray_tile_locations, commit_move);
|
||||
serde_wasm_bindgen::to_value(&result).unwrap()
|
||||
result.serialize(&SERIALIZER).unwrap()
|
||||
}
|
||||
|
||||
pub fn add_to_dictionary(&mut self, word: &str) -> JsValue {
|
||||
let result = self.0.add_to_dictionary(PLAYER_NAME, word);
|
||||
|
||||
serde_wasm_bindgen::to_value(&result).unwrap()
|
||||
result.serialize(&SERIALIZER).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue