Make maps optional for exploration.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nolan Darilek 2022-07-12 17:28:36 -05:00
parent 4b07388a56
commit 6b6a961720
2 changed files with 84 additions and 85 deletions

View File

@ -229,34 +229,37 @@ fn exploration_focus<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
config.action_explore_left.clone(), config.action_explore_left.clone(),
config.action_explore_right.clone(), config.action_explore_right.clone(),
) { ) {
for map in map.iter() { if let Ok((entity, transform, exploring)) = explorers.get_single() {
if let Ok((entity, transform, exploring)) = explorers.get_single() { let coordinates = transform.translation;
let coordinates = transform.translation; let mut exploring = if let Some(exploring) = exploring {
let mut exploring = if let Some(exploring) = exploring { **exploring
**exploring } else {
} else { let floor = coordinates.floor();
let floor = coordinates.floor(); (floor.x, floor.y)
(floor.x, floor.y) };
}; let orig = exploring;
let orig = exploring; if input.just_active(explore_forward) {
if input.just_active(explore_forward.clone()) { exploring.1 += 1.;
exploring.1 += 1.; } else if input.just_active(explore_backward) {
} else if input.just_active(explore_backward.clone()) { exploring.1 -= 1.;
exploring.1 -= 1.; } else if input.just_active(explore_left) {
} else if input.just_active(explore_left.clone()) { exploring.0 -= 1.;
exploring.0 -= 1.; } else if input.just_active(explore_right) {
} else if input.just_active(explore_right.clone()) { exploring.0 += 1.;
exploring.0 += 1.; }
} let dimensions = if let Ok(map) = map.get_single() {
if orig != exploring Some((map.width as f32, map.height as f32))
&& exploring.0 >= 0. } else {
&& exploring.0 < map.width as f32 None
&& exploring.1 >= 0. };
&& exploring.1 < map.height as f32 if let Some((width, height)) = dimensions {
{ if exploring.0 >= width || exploring.1 >= height {
commands.entity(entity).insert(Exploring(exploring)); return;
} }
} }
if orig != exploring && exploring.0 >= 0. && exploring.1 >= 0. {
commands.entity(entity).insert(Exploring(exploring));
}
} }
} }
} }
@ -305,61 +308,68 @@ where
{ {
if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() { if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() {
let coordinates = coordinates.floor(); let coordinates = coordinates.floor();
for (map, revealed_tiles) in map.iter() { let point = **exploring;
let point = **exploring; let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON);
let (known, idx) = if let Ok((map, revealed_tiles)) = map.get_single() {
let idx = point.to_index(map.width); let idx = point.to_index(map.width);
let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON); (revealed_tiles[idx], Some(idx))
let known = revealed_tiles[idx]; } else {
let visible = viewshed.is_point_visible(exploring); (false, None)
let fog_of_war = known && !visible; };
let description = if known { let visible = viewshed.is_point_visible(exploring);
let mut tokens: Vec<String> = vec![]; let fog_of_war = !visible && known;
for entity in focused.iter() { let description: String = if known || visible {
commands.entity(entity).remove::<ExplorationFocused>(); let mut tokens: Vec<String> = vec![];
} for entity in focused.iter() {
let exploring = Vec2::new(exploring.x(), exploring.y()); commands.entity(entity).remove::<ExplorationFocused>();
rapier_context.intersections_with_shape( }
exploring, let exploring = Vec2::new(exploring.x(), exploring.y());
0., rapier_context.intersections_with_shape(
&shape, exploring,
QueryFilter::new().predicate(&|v| explorable.get(v).is_ok()), 0.,
|entity| { &shape,
commands.entity(entity).insert(ExplorationFocused); QueryFilter::new().predicate(&|v| explorable.get(v).is_ok()),
if visible || mappables.get(entity).is_ok() { |entity| {
if let Ok(name) = names.get(entity) { commands.entity(entity).insert(ExplorationFocused);
tokens.push(name.to_string()); if visible || mappables.get(entity).is_ok() {
} if let Ok(name) = names.get(entity) {
if tokens.is_empty() { tokens.push(name.to_string());
if let Ok(t) = types.get(entity) { }
tokens.push((*t).into()); if tokens.is_empty() {
} if let Ok(t) = types.get(entity) {
tokens.push((*t).into());
} }
} }
true
},
);
if tokens.is_empty() {
let tile = map.tiles[idx];
if tile.is_blocked() {
"wall".to_string()
} else {
"floor".to_string()
} }
} else { true
tokens.join(": ") },
);
if tokens.is_empty() {
if let Some(idx) = idx {
if let Ok((map, _)) = map.get_single() {
let tile = map.tiles[idx];
if tile.is_blocked() {
tokens.push("wall".to_string());
} else {
tokens.push("floor".to_string());
}
}
} }
tokens.first().cloned().unwrap_or_default()
} else { } else {
"Unknown".to_string() tokens.join(": ")
};
let mut tokens: Vec<String> = vec![
description,
coordinates.direction_and_distance(exploring, None),
];
if fog_of_war {
tokens.push("in the fog of war".into());
} }
tts.speak(tokens.join(", ").to_string(), true)?; } else {
"Unknown".to_string()
};
let mut tokens = vec![
description,
coordinates.direction_and_distance(exploring, None),
];
if fog_of_war {
tokens.push("in the fog of war".to_string());
} }
tts.speak(tokens.join(", "), true)?;
} }
Ok(()) Ok(())
} }

View File

@ -97,7 +97,7 @@ impl Default for MapConfig {
} }
} }
#[derive(Bundle)] #[derive(Bundle, Default)]
pub struct PortalBundle { pub struct PortalBundle {
pub portal: Portal, pub portal: Portal,
pub mappable: Mappable, pub mappable: Mappable,
@ -105,17 +105,6 @@ pub struct PortalBundle {
pub global_transform: GlobalTransform, pub global_transform: GlobalTransform,
} }
impl Default for PortalBundle {
fn default() -> Self {
Self {
portal: Default::default(),
mappable: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
}
}
}
#[derive(Bundle, Clone, Default)] #[derive(Bundle, Clone, Default)]
pub struct MapBundle<D: 'static + Clone + Default + Send + Sync> { pub struct MapBundle<D: 'static + Clone + Default + Send + Sync> {
pub map: Map<D>, pub map: Map<D>,