Remove old area system.

This commit is contained in:
Nolan Darilek 2021-06-30 09:43:26 -05:00
parent 5ff4a92c44
commit 52ba77be46
3 changed files with 8 additions and 51 deletions

View File

@ -107,25 +107,6 @@ impl From<(usize, usize)> for Coordinates {
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Area {
pub rect: mapgen::geometry::Rect,
pub description: Option<String>,
}
impl Area {
pub fn contains(&self, point: &dyn PointLike) -> bool {
let x = point.x() as usize;
let y = point.y() as usize;
x >= self.rect.x1 && x <= self.rect.x2 && y >= self.rect.y1 && y <= self.rect.y2
}
pub fn center(&self) -> (usize, usize) {
let center = self.rect.center();
(center.x, center.y)
}
}
#[derive(Clone, Copy, Debug, Reflect)]
pub enum Angle {
Degrees(f32),

View File

@ -13,10 +13,8 @@ pub fn error_handler(In(result): In<Result<(), Box<dyn Error>>>) {
fn init_panic_handler() {
panic::set_hook(Box::new(|info| {
let backtrace = Backtrace::default();
let thread = thread::current();
let thread = thread.name().unwrap_or("<unnamed>");
let msg = match info.payload().downcast_ref::<&'static str>() {
Some(s) => *s,
None => match info.payload().downcast_ref::<String>() {
@ -24,7 +22,6 @@ fn init_panic_handler() {
None => "Box<Any>",
},
};
match info.location() {
Some(location) => {
error!(

View File

@ -9,7 +9,7 @@ use maze_generator::{prelude::*, recursive_backtracking::RbGenerator};
use rand::prelude::StdRng;
use crate::{
core::{Area, Coordinates, Player, PointLike},
core::{Coordinates, Player, PointLike},
exploration::{ExplorationType, Mappable},
log::Log,
utils::target_and_other,
@ -26,9 +26,6 @@ impl From<mapgen::geometry::Point> for Coordinates {
#[reflect(Component)]
pub struct AreaTag;
#[derive(Clone, Debug, Default, Deref, DerefMut)]
pub struct Areas(pub Vec<Area>);
#[derive(Clone, Debug, Default, Reflect)]
#[reflect(Component)]
pub struct MapObstruction;
@ -182,13 +179,10 @@ impl MapFilter for GridBuilder {
fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<Map>>) {
for (map_entity, map) in maps.iter() {
let rigid_body_entity = commands
.entity(map_entity)
.insert_bundle(RigidBodyBundle {
body_type: RigidBodyType::Static,
..Default::default()
})
.id();
commands.entity(map_entity).insert_bundle(RigidBodyBundle {
body_type: RigidBodyType::Static,
..Default::default()
});
for x in 0..map.width {
for y in 0..map.height {
let tile = map.at(x, y);
@ -199,7 +193,7 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
..Default::default()
})
.insert(ColliderParent {
handle: rigid_body_entity.handle(),
handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
})
.insert(MapObstruction)
@ -222,7 +216,7 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
..Default::default()
})
.insert(ColliderParent {
handle: rigid_body_entity.handle(),
handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
})
.insert(AreaTag);
@ -333,19 +327,6 @@ fn area_description(
}
}
fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added<Map>, Without<Areas>)>) {
for (entity, map) in query.iter() {
let mut v = vec![];
for room in &map.rooms {
v.push(Area {
rect: *room,
description: None,
});
}
commands.entity(entity).insert(Areas(v));
}
}
pub struct MapPlugin;
impl Plugin for MapPlugin {
@ -356,9 +337,7 @@ impl Plugin for MapPlugin {
let config = app.world().get_resource::<MapConfig>().unwrap().clone();
app.register_type::<Portal>()
.add_system(add_map_colliders.system())
.add_system(portal_spawner.system())
.add_system(add_areas.system())
.add_system_to_stage(CoreStage::PostUpdate, add_areas.system());
.add_system(portal_spawner.system());
if config.speak_area_descriptions {
app.add_system_to_stage(CoreStage::PostUpdate, area_description.system());
}