Allow movement through etheral walls

This commit is contained in:
Manuel Vögele
2022-02-15 16:40:41 +01:00
parent 17d8db6c34
commit 833aced2be
2 changed files with 31 additions and 3 deletions
+27 -1
View File
@@ -35,6 +35,9 @@ extern "C" {
#[wasm_bindgen(method, getter, js_name = "ds")] #[wasm_bindgen(method, getter, js_name = "ds")]
fn door_state(this: &JsWallData) -> DoorState; fn door_state(this: &JsWallData) -> DoorState;
#[wasm_bindgen(method, getter, js_name = "move")]
fn move_type(this: &JsWallData) -> WallSenseType;
} }
#[wasm_bindgen] #[wasm_bindgen]
@@ -97,21 +100,43 @@ impl TryFrom<usize> for DoorType {
} }
} }
#[wasm_bindgen]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WallSenseType {
NONE = 0,
LIMITED = 10,
NORMAL = 20,
}
impl TryFrom<usize> for WallSenseType {
type Error = ();
fn try_from(value: usize) -> Result<Self, Self::Error> {
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)] #[derive(Debug, Clone, Copy)]
pub struct Wall { pub struct Wall {
pub p1: Point, pub p1: Point,
pub p2: Point, pub p2: Point,
pub door_type: DoorType, pub door_type: DoorType,
pub door_state: DoorState, pub door_state: DoorState,
pub move_type: WallSenseType,
} }
impl Wall { 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 { Self {
p1, p1,
p2, p2,
door_type, door_type,
door_state, door_state,
move_type,
} }
} }
@@ -134,6 +159,7 @@ impl Wall {
Point::new(c[2], c[3]), Point::new(c[2], c[3]),
data.door_type(), data.door_type(),
data.door_state(), data.door_state(),
data.move_type(),
) )
} }
} }
+4 -2
View File
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
use crate::{ use crate::{
geometry::{LineSegment, Point}, geometry::{LineSegment, Point},
js_api::Wall, js_api::{Wall, WallSenseType},
ptr_indexed_hash_set::PtrIndexedHashSet, ptr_indexed_hash_set::PtrIndexedHashSet,
}; };
@@ -156,10 +156,12 @@ impl Pathfinder {
let mut endpoints = FxHashMap::<Point, Vec<f64>>::default(); let mut endpoints = FxHashMap::<Point, Vec<f64>>::default();
let mut line_segments = Vec::new(); let mut line_segments = Vec::new();
for wall in walls { for wall in walls {
if wall.move_type == WallSenseType::NONE {
continue;
}
if wall.is_door() && wall.is_open() { if wall.is_door() && wall.is_open() {
continue; continue;
} }
// TODO Check if wall is ethereal
let x_diff = wall.p2.x - wall.p1.x; let x_diff = wall.p2.x - wall.p1.x;
let y_diff = wall.p2.y - wall.p1.y; let y_diff = wall.p2.y - wall.p1.y;
let p1_angle = y_diff.atan2(x_diff); let p1_angle = y_diff.atan2(x_diff);