Remove old area system.
This commit is contained in:
parent
5ff4a92c44
commit
52ba77be46
19
src/core.rs
19
src/core.rs
|
@ -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)]
|
#[derive(Clone, Copy, Debug, Reflect)]
|
||||||
pub enum Angle {
|
pub enum Angle {
|
||||||
Degrees(f32),
|
Degrees(f32),
|
||||||
|
|
|
@ -13,10 +13,8 @@ pub fn error_handler(In(result): In<Result<(), Box<dyn Error>>>) {
|
||||||
fn init_panic_handler() {
|
fn init_panic_handler() {
|
||||||
panic::set_hook(Box::new(|info| {
|
panic::set_hook(Box::new(|info| {
|
||||||
let backtrace = Backtrace::default();
|
let backtrace = Backtrace::default();
|
||||||
|
|
||||||
let thread = thread::current();
|
let thread = thread::current();
|
||||||
let thread = thread.name().unwrap_or("<unnamed>");
|
let thread = thread.name().unwrap_or("<unnamed>");
|
||||||
|
|
||||||
let msg = match info.payload().downcast_ref::<&'static str>() {
|
let msg = match info.payload().downcast_ref::<&'static str>() {
|
||||||
Some(s) => *s,
|
Some(s) => *s,
|
||||||
None => match info.payload().downcast_ref::<String>() {
|
None => match info.payload().downcast_ref::<String>() {
|
||||||
|
@ -24,7 +22,6 @@ fn init_panic_handler() {
|
||||||
None => "Box<Any>",
|
None => "Box<Any>",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
match info.location() {
|
match info.location() {
|
||||||
Some(location) => {
|
Some(location) => {
|
||||||
error!(
|
error!(
|
||||||
|
|
33
src/map.rs
33
src/map.rs
|
@ -9,7 +9,7 @@ use maze_generator::{prelude::*, recursive_backtracking::RbGenerator};
|
||||||
use rand::prelude::StdRng;
|
use rand::prelude::StdRng;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{Area, Coordinates, Player, PointLike},
|
core::{Coordinates, Player, PointLike},
|
||||||
exploration::{ExplorationType, Mappable},
|
exploration::{ExplorationType, Mappable},
|
||||||
log::Log,
|
log::Log,
|
||||||
utils::target_and_other,
|
utils::target_and_other,
|
||||||
|
@ -26,9 +26,6 @@ impl From<mapgen::geometry::Point> for Coordinates {
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct AreaTag;
|
pub struct AreaTag;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
|
||||||
pub struct Areas(pub Vec<Area>);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Reflect)]
|
#[derive(Clone, Debug, Default, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct MapObstruction;
|
pub struct MapObstruction;
|
||||||
|
@ -182,13 +179,10 @@ impl MapFilter for GridBuilder {
|
||||||
|
|
||||||
fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<Map>>) {
|
fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<Map>>) {
|
||||||
for (map_entity, map) in maps.iter() {
|
for (map_entity, map) in maps.iter() {
|
||||||
let rigid_body_entity = commands
|
commands.entity(map_entity).insert_bundle(RigidBodyBundle {
|
||||||
.entity(map_entity)
|
|
||||||
.insert_bundle(RigidBodyBundle {
|
|
||||||
body_type: RigidBodyType::Static,
|
body_type: RigidBodyType::Static,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
});
|
||||||
.id();
|
|
||||||
for x in 0..map.width {
|
for x in 0..map.width {
|
||||||
for y in 0..map.height {
|
for y in 0..map.height {
|
||||||
let tile = map.at(x, y);
|
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()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(ColliderParent {
|
.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(),
|
pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
|
||||||
})
|
})
|
||||||
.insert(MapObstruction)
|
.insert(MapObstruction)
|
||||||
|
@ -222,7 +216,7 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(ColliderParent {
|
.insert(ColliderParent {
|
||||||
handle: rigid_body_entity.handle(),
|
handle: map_entity.handle(),
|
||||||
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
|
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
|
||||||
})
|
})
|
||||||
.insert(AreaTag);
|
.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;
|
pub struct MapPlugin;
|
||||||
|
|
||||||
impl Plugin for MapPlugin {
|
impl Plugin for MapPlugin {
|
||||||
|
@ -356,9 +337,7 @@ impl Plugin for MapPlugin {
|
||||||
let config = app.world().get_resource::<MapConfig>().unwrap().clone();
|
let config = app.world().get_resource::<MapConfig>().unwrap().clone();
|
||||||
app.register_type::<Portal>()
|
app.register_type::<Portal>()
|
||||||
.add_system(add_map_colliders.system())
|
.add_system(add_map_colliders.system())
|
||||||
.add_system(portal_spawner.system())
|
.add_system(portal_spawner.system());
|
||||||
.add_system(add_areas.system())
|
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, add_areas.system());
|
|
||||||
if config.speak_area_descriptions {
|
if config.speak_area_descriptions {
|
||||||
app.add_system_to_stage(CoreStage::PostUpdate, area_description.system());
|
app.add_system_to_stage(CoreStage::PostUpdate, area_description.system());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user