Move new area initialization to existing collider initialization system.

This commit is contained in:
Nolan Darilek 2021-06-29 10:31:18 -05:00
parent 0b37adb797
commit 80f163f65f

View File

@ -209,6 +209,23 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
}
}
}
for room in &map.rooms {
commands
.spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid(
(room.width() / 2) as f32,
(room.height() / 2) as f32,
),
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default()
})
.insert(ColliderParent {
handle: rigid_body_entity.handle(),
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
})
.insert(AreaTag);
}
}
}
@ -331,21 +348,6 @@ fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added<Map>, W
for (entity, map) in query.iter() {
let mut v = vec![];
for room in &map.rooms {
commands
.spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid(
(room.width() / 2) as f32,
(room.height() / 2) as f32,
),
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default()
})
.insert(ColliderParent {
handle: entity.handle(),
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
})
.insert(AreaTag);
v.push(Area {
rect: *room,
description: None,