diff --git a/rust/src/js_api.rs b/rust/src/js_api.rs index 42052f0..cceef7a 100644 --- a/rust/src/js_api.rs +++ b/rust/src/js_api.rs @@ -35,6 +35,9 @@ extern "C" { #[wasm_bindgen(method, getter, js_name = "ds")] fn door_state(this: &JsWallData) -> DoorState; + + #[wasm_bindgen(method, getter, js_name = "move")] + fn move_type(this: &JsWallData) -> WallSenseType; } #[wasm_bindgen] @@ -97,21 +100,43 @@ impl TryFrom for DoorType { } } +#[wasm_bindgen] +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum WallSenseType { + NONE = 0, + LIMITED = 10, + NORMAL = 20, +} + +impl TryFrom for WallSenseType { + type Error = (); + fn try_from(value: usize) -> Result { + match value { + x if x == Self::NONE as usize => Ok(Self::NONE), + x if x == Self::LIMITED as usize => Ok(Self::LIMITED), + x if x == Self::NORMAL as usize => Ok(Self::NORMAL), + _ => Err(()), + } + } +} + #[derive(Debug, Clone, Copy)] pub struct Wall { pub p1: Point, pub p2: Point, pub door_type: DoorType, pub door_state: DoorState, + pub move_type: WallSenseType, } impl Wall { - pub fn new(p1: Point, p2: Point, door_type: DoorType, door_state: DoorState) -> Self { + pub fn new(p1: Point, p2: Point, door_type: DoorType, door_state: DoorState, move_type: WallSenseType) -> Self { Self { p1, p2, door_type, door_state, + move_type, } } @@ -134,6 +159,7 @@ impl Wall { Point::new(c[2], c[3]), data.door_type(), data.door_state(), + data.move_type(), ) } } diff --git a/rust/src/pathfinder.rs b/rust/src/pathfinder.rs index f778b30..1aeb1a2 100644 --- a/rust/src/pathfinder.rs +++ b/rust/src/pathfinder.rs @@ -6,7 +6,7 @@ use rustc_hash::FxHashMap; use crate::{ geometry::{LineSegment, Point}, - js_api::Wall, + js_api::{Wall, WallSenseType}, ptr_indexed_hash_set::PtrIndexedHashSet, }; @@ -156,10 +156,12 @@ impl Pathfinder { let mut endpoints = FxHashMap::>::default(); let mut line_segments = Vec::new(); for wall in walls { + if wall.move_type == WallSenseType::NONE { + continue; + } if wall.is_door() && wall.is_open() { continue; } - // TODO Check if wall is ethereal let x_diff = wall.p2.x - wall.p1.x; let y_diff = wall.p2.y - wall.p1.y; let p1_angle = y_diff.atan2(x_diff);