WIP: Continue upgrade.

This commit is contained in:
Nolan Darilek 2022-01-10 23:05:51 -06:00
parent cb02e39870
commit 698f12d9bd
8 changed files with 43 additions and 42 deletions

View File

@ -646,9 +646,9 @@ fn copy_coordinates_to_transform(
( (
Changed<Transform>, Changed<Transform>,
Without<RigidBodyPositionComponent>, Without<RigidBodyPositionComponent>,
Without<RigidBodyPositionSyncComponent>, Without<RigidBodyPositionSync>,
Without<ColliderPositionComponent>, Without<ColliderPositionComponent>,
Without<ColliderPositionSyncComponent>, Without<ColliderPositionSync>,
), ),
>, >,
) { ) {
@ -686,7 +686,7 @@ fn copy_collider_position_to_coordinates(
( (
Without<RigidBodyPositionComponent>, Without<RigidBodyPositionComponent>,
Changed<ColliderPositionComponent>, Changed<ColliderPositionComponent>,
With<ColliderPositionSyncComponent>, With<ColliderPositionSync>,
), ),
>, >,
) { ) {
@ -726,7 +726,7 @@ pub struct CorePlugin;
impl Plugin for CorePlugin { impl Plugin for CorePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<CoreConfig>() { if !app.world.contains_resource::<CoreConfig>() {
app.insert_resource(CoreConfig::default()); app.insert_resource(CoreConfig::default());
} }
app.register_type::<Coordinates>() app.register_type::<Coordinates>()

View File

@ -54,7 +54,7 @@ pub struct ErrorPlugin;
impl Plugin for ErrorPlugin { impl Plugin for ErrorPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
init_panic_handler(); init_panic_handler();
if let Some(config) = app.world().get_resource::<ErrorConfig>() { if let Some(config) = app.world.get_resource::<ErrorConfig>() {
if let Some(dsn) = &config.sentry_dsn { if let Some(dsn) = &config.sentry_dsn {
let guard = sentry::init(dsn.clone()); let guard = sentry::init(dsn.clone());
app.insert_resource(guard); app.insert_resource(guard);

View File

@ -265,7 +265,7 @@ fn exploration_focus<S, A: 'static>(
config.action_explore_right.clone(), config.action_explore_right.clone(),
) { ) {
for map in map.iter() { for map in map.iter() {
if let Ok((entity, coordinates, exploring)) = explorers.single() { if let (entity, coordinates, exploring) = explorers.single() {
let coordinates = **coordinates; let coordinates = **coordinates;
let mut exploring = if let Some(exploring) = exploring { let mut exploring = if let Some(exploring) = exploring {
**exploring **exploring
@ -334,7 +334,7 @@ fn exploration_changed_announcement(
query_pipeline: Res<QueryPipeline>, query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery, collider_query: QueryPipelineColliderComponentsQuery,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
if let Ok((coordinates, exploring, viewshed)) = explorer.single() { if let (coordinates, exploring, viewshed) = explorer.single() {
let collider_set = QueryPipelineColliderComponentsSet(&collider_query); let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
let coordinates = coordinates.floor(); let coordinates = coordinates.floor();
for (map, revealed_tiles) in map.iter() { for (map, revealed_tiles) in map.iter() {
@ -457,11 +457,11 @@ where
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<ExplorationConfig<S, A>>() { if !app.world.contains_resource::<ExplorationConfig<S, A>>() {
app.insert_resource(ExplorationConfig::<S, A>::default()); app.insert_resource(ExplorationConfig::<S, A>::default());
} }
let config = app let config = app
.world() .world
.get_resource::<ExplorationConfig<S, A>>() .get_resource::<ExplorationConfig<S, A>>()
.unwrap() .unwrap()
.clone(); .clone();

View File

@ -22,12 +22,10 @@ impl From<mapgen::geometry::Point> for Coordinates {
} }
} }
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Deref, DerefMut)]
#[reflect(Component)]
pub struct Area(AABB); pub struct Area(AABB);
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Default, Deref, DerefMut)]
#[reflect(Component)]
pub struct Map(pub MapgenMap); pub struct Map(pub MapgenMap);
#[derive(Component, Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
@ -152,7 +150,7 @@ impl GridBuilder {
} }
impl MapFilter for GridBuilder { impl MapFilter for GridBuilder {
fn modify_map(&self, _rng: &mut StdRng, map: &Map) -> Map { fn modify_map(&self, _rng: &mut StdRng, map: &MapgenMap) -> MapgenMap {
let mut map = map.clone(); let mut map = map.clone();
let mut generator = RbGenerator::new(None); let mut generator = RbGenerator::new(None);
let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32); let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32);
@ -219,7 +217,7 @@ fn spawn_colliders(
.remove::<SpawnColliders>() .remove::<SpawnColliders>()
.remove::<SpawnColliderPerTile>() .remove::<SpawnColliderPerTile>()
.insert_bundle(RigidBodyBundle { .insert_bundle(RigidBodyBundle {
body_type: RigidBodyType::Static, body_type: RigidBodyTypeComponent(RigidBodyType::Static),
..Default::default() ..Default::default()
}); });
if **spawn_collider_per_tile { if **spawn_collider_per_tile {
@ -229,7 +227,7 @@ fn spawn_colliders(
if tile.blocks_motion() { if tile.blocks_motion() {
let id = commands let id = commands
.spawn_bundle(ColliderBundle { .spawn_bundle(ColliderBundle {
shape: ColliderShape::cuboid(0.5, 0.5), shape: ColliderShapeComponent(ColliderShape::cuboid(0.5, 0.5)),
position: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(), position: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
..Default::default() ..Default::default()
}) })
@ -324,7 +322,7 @@ fn spawn_colliders(
);*/ );*/
let id = commands let id = commands
.spawn_bundle(ColliderBundle { .spawn_bundle(ColliderBundle {
shape: ColliderShape::cuboid(half_width, half_height), shape: ColliderShapeComponent(ColliderShape::cuboid(half_width, half_height)),
position: Vec2::new(x, y).into(), position: Vec2::new(x, y).into(),
..Default::default() ..Default::default()
}) })
@ -343,13 +341,13 @@ fn spawn_colliders(
for room in &map.rooms { for room in &map.rooms {
let shape = let shape =
ColliderShape::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32); ColliderShape::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32);
let position: ColliderPosition = let position: ColliderPositionComponent =
point!(room.center().x(), room.center().y()).into(); point!(room.center().x(), room.center().y()).into();
let aabb = shape.compute_aabb(&position); let aabb = shape.compute_aabb(&position);
let id = commands let id = commands
.spawn_bundle(ColliderBundle { .spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor, collider_type: ColliderTypeComponent(ColliderType::Sensor),
shape: shape.clone(), shape: ColliderShapeComponent(shape.clone()),
flags: ActiveEvents::INTERSECTION_EVENTS.into(), flags: ActiveEvents::INTERSECTION_EVENTS.into(),
position, position,
..Default::default() ..Default::default()
@ -429,8 +427,8 @@ fn spawn_portal_colliders(
commands commands
.entity(portal_entity) .entity(portal_entity)
.insert_bundle(ColliderBundle { .insert_bundle(ColliderBundle {
collider_type: ColliderType::Sensor, collider_type: ColliderTypeComponent(ColliderType::Sensor),
shape: ColliderShape::cuboid(0.5, 0.5), shape: ColliderShapeComponent(ColliderShape::cuboid(0.5, 0.5)),
position, position,
flags: ActiveEvents::INTERSECTION_EVENTS.into(), flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default() ..Default::default()
@ -456,7 +454,7 @@ fn area_description(
}) })
{ {
if players.get(other).is_ok() { if players.get(other).is_ok() {
if let Ok(mut log) = log.single_mut() { if let mut log = log.single_mut() {
if let Ok((aabb, area_name)) = areas.get(area) { if let Ok((aabb, area_name)) = areas.get(area) {
let name = if let Some(name) = area_name { let name = if let Some(name) = area_name {
Some(name.to_string()) Some(name.to_string())
@ -483,10 +481,10 @@ pub struct MapPlugin;
impl Plugin for MapPlugin { impl Plugin for MapPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<MapConfig>() { if !app.world.contains_resource::<MapConfig>() {
app.insert_resource(MapConfig::default()); app.insert_resource(MapConfig::default());
} }
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(spawn_colliders) .add_system(spawn_colliders)
.add_system(spawn_portals) .add_system(spawn_portals)

View File

@ -195,14 +195,17 @@ fn speak_direction(
mut tts: ResMut<Tts>, mut tts: ResMut<Tts>,
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>, player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
if let Ok(direction) = player.single() { if let direction = player.single() {
let direction: String = (*direction).into(); let direction: String = (*direction).into();
tts.speak(direction, true)?; tts.speak(direction, true)?;
} }
Ok(()) Ok(())
} }
fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut RigidBodyVelocityComponent>) { fn remove_speed(
removed: RemovedComponents<Speed>,
mut query: Query<&mut RigidBodyVelocityComponent>,
) {
for entity in removed.iter() { for entity in removed.iter() {
if let Ok(mut velocity) = query.get_mut(entity) { if let Ok(mut velocity) = query.get_mut(entity) {
velocity.linvel = Vec2::ZERO.into(); velocity.linvel = Vec2::ZERO.into();
@ -260,11 +263,11 @@ where
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<NavigationConfig<S, A>>() { if !app.world.contains_resource::<NavigationConfig<S, A>>() {
app.insert_resource(NavigationConfig::<S, A>::default()); app.insert_resource(NavigationConfig::<S, A>::default());
} }
let config = app let config = app
.world() .world
.get_resource::<NavigationConfig<S, A>>() .get_resource::<NavigationConfig<S, A>>()
.unwrap() .unwrap()
.clone(); .clone();

View File

@ -92,7 +92,7 @@ impl<'world, 'state>
.0 .0
.iter() .iter()
.filter(|(a, _, _, _)| query.1.get(*a).is_ok()) .filter(|(a, _, _, _)| query.1.get(*a).is_ok())
.map(|(a, b, c, d)| (a, *b, c.clone(), *d)) .map(|(a, b, c, d)| (a, **b, (*c).clone(), **d))
.collect::<Vec<(Entity, ColliderPosition, ColliderShape, ColliderFlags)>>(); .collect::<Vec<(Entity, ColliderPosition, ColliderShape, ColliderFlags)>>();
let mut m = HashMap::new(); let mut m = HashMap::new();
for (e, a, b, c) in entries { for (e, a, b, c) in entries {
@ -102,18 +102,18 @@ impl<'world, 'state>
} }
} }
impl ComponentSet<SharedShape> for StaticColliderComponentsSet { impl ComponentSet<ColliderShape> for StaticColliderComponentsSet {
fn size_hint(&self) -> usize { fn size_hint(&self) -> usize {
self.0.len() self.0.len()
} }
fn for_each(&self, _f: impl FnMut(Index, &SharedShape)) { fn for_each(&self, _f: impl FnMut(Index, &ColliderShape)) {
unimplemented!() unimplemented!()
} }
} }
impl ComponentSetOption<SharedShape> for StaticColliderComponentsSet { impl ComponentSetOption<ColliderShape> for StaticColliderComponentsSet {
fn get(&self, index: Index) -> Option<&SharedShape> { fn get(&self, index: Index) -> Option<&ColliderShape> {
self.0.get(&index.entity()).map(|v| &v.1) self.0.get(&index.entity()).map(|v| &v.1)
} }
} }
@ -158,7 +158,7 @@ fn find_path_for_shape(
query_pipeline: &QueryPipeline, query_pipeline: &QueryPipeline,
map: &Map, map: &Map,
collider_set: StaticColliderComponentsSet, collider_set: StaticColliderComponentsSet,
shape: &SharedShape, shape: &ColliderShape,
) -> Option<Path> { ) -> Option<Path> {
let path = astar( let path = astar(
&start.i32(), &start.i32(),
@ -219,7 +219,7 @@ fn calculate_path(
.remove::<Speed>(); .remove::<Speed>();
continue; continue;
} }
for map in map.iter() { if let map = map.single() {
let coordinates_clone = *coordinates; let coordinates_clone = *coordinates;
let destination_clone = *destination; let destination_clone = *destination;
let query_pipeline_clone = query_pipeline.clone(); let query_pipeline_clone = query_pipeline.clone();

View File

@ -285,12 +285,12 @@ where
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<SoundConfig<S>>() { if !app.world.contains_resource::<SoundConfig<S>>() {
app.insert_resource(SoundConfig::<S>::default()); app.insert_resource(SoundConfig::<S>::default());
} }
const SOUND_ICON_AND_EXPLORATION_STAGE: &str = "sound_icon_and_exploration"; const SOUND_ICON_AND_EXPLORATION_STAGE: &str = "sound_icon_and_exploration";
let core_config = *app.world().get_resource::<CoreConfig>().unwrap(); let core_config = *app.world.get_resource::<CoreConfig>().unwrap();
if let Some(context) = app.world().get_resource::<Context>() { if let Some(context) = app.world.get_resource::<Context>() {
context context
.set_meters_per_unit(1. / core_config.pixels_per_unit as f32) .set_meters_per_unit(1. / core_config.pixels_per_unit as f32)
.unwrap(); .unwrap();

View File

@ -281,7 +281,7 @@ fn update_viewshed(
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) = if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
viewers.get_mut(*entity) viewers.get_mut(*entity)
{ {
if let Ok(map) = map.single() { if let map = map.single() {
let mut cache = HashMap::new(); let mut cache = HashMap::new();
viewshed.update( viewshed.update(
&viewer_entity, &viewer_entity,
@ -314,7 +314,7 @@ fn remove_visible(
continue; continue;
} }
visible_entities.remove(&removed); visible_entities.remove(&removed);
if let Ok(map) = map.single() { if let map = map.single() {
let mut cache = HashMap::new(); let mut cache = HashMap::new();
viewshed.update( viewshed.update(
&viewer_entity, &viewer_entity,
@ -375,7 +375,7 @@ fn log_visible(
continue; continue;
} }
if let Ok((name, body_position, collider_position)) = visible.get(*viewed) { if let Ok((name, body_position, collider_position)) = visible.get(*viewed) {
if let Ok(mut log) = log.single_mut() { if let mut log = log.single_mut() {
let viewed_coordinates = if let Some(p) = body_position { let viewed_coordinates = if let Some(p) = body_position {
(p.position.translation.x, p.position.translation.y) (p.position.translation.x, p.position.translation.y)
} else if let Some(p) = collider_position { } else if let Some(p) = collider_position {