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

View File

@ -54,7 +54,7 @@ pub struct ErrorPlugin;
impl Plugin for ErrorPlugin {
fn build(&self, app: &mut App) {
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 {
let guard = sentry::init(dsn.clone());
app.insert_resource(guard);

View File

@ -265,7 +265,7 @@ fn exploration_focus<S, A: 'static>(
config.action_explore_right.clone(),
) {
for map in map.iter() {
if let Ok((entity, coordinates, exploring)) = explorers.single() {
if let (entity, coordinates, exploring) = explorers.single() {
let coordinates = **coordinates;
let mut exploring = if let Some(exploring) = exploring {
**exploring
@ -334,7 +334,7 @@ fn exploration_changed_announcement(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
) -> 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 coordinates = coordinates.floor();
for (map, revealed_tiles) in map.iter() {
@ -457,11 +457,11 @@ where
'a: 'static,
{
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());
}
let config = app
.world()
.world
.get_resource::<ExplorationConfig<S, A>>()
.unwrap()
.clone();

View File

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

View File

@ -195,14 +195,17 @@ fn speak_direction(
mut tts: ResMut<Tts>,
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
) -> Result<(), Box<dyn Error>> {
if let Ok(direction) = player.single() {
if let direction = player.single() {
let direction: String = (*direction).into();
tts.speak(direction, true)?;
}
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() {
if let Ok(mut velocity) = query.get_mut(entity) {
velocity.linvel = Vec2::ZERO.into();
@ -260,11 +263,11 @@ where
'a: 'static,
{
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());
}
let config = app
.world()
.world
.get_resource::<NavigationConfig<S, A>>()
.unwrap()
.clone();

View File

@ -92,7 +92,7 @@ impl<'world, 'state>
.0
.iter()
.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)>>();
let mut m = HashMap::new();
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 {
self.0.len()
}
fn for_each(&self, _f: impl FnMut(Index, &SharedShape)) {
fn for_each(&self, _f: impl FnMut(Index, &ColliderShape)) {
unimplemented!()
}
}
impl ComponentSetOption<SharedShape> for StaticColliderComponentsSet {
fn get(&self, index: Index) -> Option<&SharedShape> {
impl ComponentSetOption<ColliderShape> for StaticColliderComponentsSet {
fn get(&self, index: Index) -> Option<&ColliderShape> {
self.0.get(&index.entity()).map(|v| &v.1)
}
}
@ -158,7 +158,7 @@ fn find_path_for_shape(
query_pipeline: &QueryPipeline,
map: &Map,
collider_set: StaticColliderComponentsSet,
shape: &SharedShape,
shape: &ColliderShape,
) -> Option<Path> {
let path = astar(
&start.i32(),
@ -219,7 +219,7 @@ fn calculate_path(
.remove::<Speed>();
continue;
}
for map in map.iter() {
if let map = map.single() {
let coordinates_clone = *coordinates;
let destination_clone = *destination;
let query_pipeline_clone = query_pipeline.clone();

View File

@ -285,12 +285,12 @@ where
'a: 'static,
{
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());
}
const SOUND_ICON_AND_EXPLORATION_STAGE: &str = "sound_icon_and_exploration";
let core_config = *app.world().get_resource::<CoreConfig>().unwrap();
if let Some(context) = app.world().get_resource::<Context>() {
let core_config = *app.world.get_resource::<CoreConfig>().unwrap();
if let Some(context) = app.world.get_resource::<Context>() {
context
.set_meters_per_unit(1. / core_config.pixels_per_unit as f32)
.unwrap();

View File

@ -281,7 +281,7 @@ fn update_viewshed(
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
viewers.get_mut(*entity)
{
if let Ok(map) = map.single() {
if let map = map.single() {
let mut cache = HashMap::new();
viewshed.update(
&viewer_entity,
@ -314,7 +314,7 @@ fn remove_visible(
continue;
}
visible_entities.remove(&removed);
if let Ok(map) = map.single() {
if let map = map.single() {
let mut cache = HashMap::new();
viewshed.update(
&viewer_entity,
@ -375,7 +375,7 @@ fn log_visible(
continue;
}
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 {
(p.position.translation.x, p.position.translation.y)
} else if let Some(p) = collider_position {