Skip to content

Commit

Permalink
fix: wrong warpzone to target
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed May 2, 2024
1 parent dd5c6b2 commit 1dfa649
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct WarpZone {
pub start: i32,
pub end: i32,
pub direction: ZoneDirection,
pub to: Cid,
pub to: Did,
}

#[derive(Debug)]
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Display {
pub fn from(item: DisplayInfo, cid: Cid) -> Self {
Display {
name: item.name,
id: rand::random(),
id: item.id,
// raw_handle - cannot serialize
x: item.x,
y: item.y,
Expand Down Expand Up @@ -150,14 +150,14 @@ pub fn create_warpzones(a: &mut Vec<Display>, b: &mut Vec<Display>, eq: bool) ->
start,
end,
direction,
to: target.owner,
to: target.id,
});

target.warpzones.push(WarpZone {
start,
end,
direction: direction.reverse(),
to: disp.owner,
to: disp.id,
});
}
}
Expand All @@ -178,6 +178,13 @@ pub fn create_warpzones_hashmap(
// check overlap and isolated displays first
for disp in a.iter() {
for target in b.iter() {
if disp.id == target.id {
return Err(Error::new(
InvalidInput,
"display ids are not identical",
));
}

if disp.is_overlap(target.clone()) {
return Err(Error::new(
InvalidInput,
Expand All @@ -197,7 +204,7 @@ pub fn create_warpzones_hashmap(
start,
end,
direction,
to: target.owner,
to: target.id,
});

let mut target = target.clone();
Expand All @@ -207,7 +214,7 @@ pub fn create_warpzones_hashmap(
start,
end,
direction: direction.reverse(),
to: disp.owner,
to: disp.id,
});

hashmap.insert(target.id, target);
Expand Down

0 comments on commit 1dfa649

Please sign in to comment.