From f92c586cfc0c0c357d0b63c9a800994c1f4f4698 Mon Sep 17 00:00:00 2001 From: milo Date: Sat, 9 Mar 2024 17:01:08 -0500 Subject: [PATCH] return ints from suggest() and interpret them in worker.js --- fish-webworker/src/lib.rs | 22 ++++++++-------------- fish-webworker/src/worker.js | 7 ++++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fish-webworker/src/lib.rs b/fish-webworker/src/lib.rs index 85fb228..a9fefd2 100644 --- a/fish-webworker/src/lib.rs +++ b/fish-webworker/src/lib.rs @@ -3,7 +3,7 @@ use wasm_bindgen_macro::wasm_bindgen; use fish::{Bot, Weights}; use mino::srs::{PieceType, Queue}; -use mino::{MatBuf, Rot}; +use mino::MatBuf; struct State { weights: Weights, @@ -45,7 +45,7 @@ pub fn get_config() -> Vec { } #[wasm_bindgen] -pub fn suggest(matrix: String, hold: String, next: String) -> Result { +pub fn suggest(matrix: String, hold: String, next: String) -> Result, String> { let matrix = parse_matrix(&matrix); let hold = parse_hold(&hold)?; let next = parse_queue(&next)?; @@ -59,18 +59,12 @@ pub fn suggest(matrix: String, hold: String, next: String) -> Result "spawn", - Rot::E => "right", - Rot::S => "reverse", - Rot::W => "left", - }, - res.ty.name(), - )) + Ok(vec![ + res.loc.x as i16 as i32, + res.loc.y as i16 as i32, + res.loc.r as i8 as i32, + res.ty as u8 as i32, + ]) } fn parse_matrix(s: &str) -> MatBuf { diff --git a/fish-webworker/src/worker.js b/fish-webworker/src/worker.js index a224371..d7170a2 100644 --- a/fish-webworker/src/worker.js +++ b/fish-webworker/src/worker.js @@ -19,9 +19,10 @@ async function handle(msg) { case 'suggest': { - let res = suggest(msg.state.matrix, msg.state.hold, msg.state.next); - let [x, y, r, type] = res.split(','); - x = +x, y = +y; + let [x, y, r, type] = suggest(msg.state.matrix, msg.state.hold, msg.state.next); + console.log(x,y,r,type); + r = ['north', 'right', 'south', 'west'][r]; + type = 'IJLOSTZ'[type]; return { x, y, r, type }; }