Make maps optional for exploration.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4b07388a56
commit
6b6a961720
|
@ -229,34 +229,37 @@ fn exploration_focus<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
|
|||
config.action_explore_left.clone(),
|
||||
config.action_explore_right.clone(),
|
||||
) {
|
||||
for map in map.iter() {
|
||||
if let Ok((entity, transform, exploring)) = explorers.get_single() {
|
||||
let coordinates = transform.translation;
|
||||
let mut exploring = if let Some(exploring) = exploring {
|
||||
**exploring
|
||||
} else {
|
||||
let floor = coordinates.floor();
|
||||
(floor.x, floor.y)
|
||||
};
|
||||
let orig = exploring;
|
||||
if input.just_active(explore_forward.clone()) {
|
||||
exploring.1 += 1.;
|
||||
} else if input.just_active(explore_backward.clone()) {
|
||||
exploring.1 -= 1.;
|
||||
} else if input.just_active(explore_left.clone()) {
|
||||
exploring.0 -= 1.;
|
||||
} else if input.just_active(explore_right.clone()) {
|
||||
exploring.0 += 1.;
|
||||
}
|
||||
if orig != exploring
|
||||
&& exploring.0 >= 0.
|
||||
&& exploring.0 < map.width as f32
|
||||
&& exploring.1 >= 0.
|
||||
&& exploring.1 < map.height as f32
|
||||
{
|
||||
commands.entity(entity).insert(Exploring(exploring));
|
||||
if let Ok((entity, transform, exploring)) = explorers.get_single() {
|
||||
let coordinates = transform.translation;
|
||||
let mut exploring = if let Some(exploring) = exploring {
|
||||
**exploring
|
||||
} else {
|
||||
let floor = coordinates.floor();
|
||||
(floor.x, floor.y)
|
||||
};
|
||||
let orig = exploring;
|
||||
if input.just_active(explore_forward) {
|
||||
exploring.1 += 1.;
|
||||
} else if input.just_active(explore_backward) {
|
||||
exploring.1 -= 1.;
|
||||
} else if input.just_active(explore_left) {
|
||||
exploring.0 -= 1.;
|
||||
} else if input.just_active(explore_right) {
|
||||
exploring.0 += 1.;
|
||||
}
|
||||
let dimensions = if let Ok(map) = map.get_single() {
|
||||
Some((map.width as f32, map.height as f32))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some((width, height)) = dimensions {
|
||||
if exploring.0 >= width || exploring.1 >= height {
|
||||
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() {
|
||||
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 shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON);
|
||||
let known = revealed_tiles[idx];
|
||||
let visible = viewshed.is_point_visible(exploring);
|
||||
let fog_of_war = known && !visible;
|
||||
let description = if known {
|
||||
let mut tokens: Vec<String> = vec![];
|
||||
for entity in focused.iter() {
|
||||
commands.entity(entity).remove::<ExplorationFocused>();
|
||||
}
|
||||
let exploring = Vec2::new(exploring.x(), exploring.y());
|
||||
rapier_context.intersections_with_shape(
|
||||
exploring,
|
||||
0.,
|
||||
&shape,
|
||||
QueryFilter::new().predicate(&|v| explorable.get(v).is_ok()),
|
||||
|entity| {
|
||||
commands.entity(entity).insert(ExplorationFocused);
|
||||
if visible || mappables.get(entity).is_ok() {
|
||||
if let Ok(name) = names.get(entity) {
|
||||
tokens.push(name.to_string());
|
||||
}
|
||||
if tokens.is_empty() {
|
||||
if let Ok(t) = types.get(entity) {
|
||||
tokens.push((*t).into());
|
||||
}
|
||||
(revealed_tiles[idx], Some(idx))
|
||||
} else {
|
||||
(false, None)
|
||||
};
|
||||
let visible = viewshed.is_point_visible(exploring);
|
||||
let fog_of_war = !visible && known;
|
||||
let description: String = if known || visible {
|
||||
let mut tokens: Vec<String> = vec![];
|
||||
for entity in focused.iter() {
|
||||
commands.entity(entity).remove::<ExplorationFocused>();
|
||||
}
|
||||
let exploring = Vec2::new(exploring.x(), exploring.y());
|
||||
rapier_context.intersections_with_shape(
|
||||
exploring,
|
||||
0.,
|
||||
&shape,
|
||||
QueryFilter::new().predicate(&|v| explorable.get(v).is_ok()),
|
||||
|entity| {
|
||||
commands.entity(entity).insert(ExplorationFocused);
|
||||
if visible || mappables.get(entity).is_ok() {
|
||||
if let Ok(name) = names.get(entity) {
|
||||
tokens.push(name.to_string());
|
||||
}
|
||||
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 {
|
||||
tokens.join(": ")
|
||||
true
|
||||
},
|
||||
);
|
||||
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 {
|
||||
"Unknown".to_string()
|
||||
};
|
||||
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());
|
||||
tokens.join(": ")
|
||||
}
|
||||
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(())
|
||||
}
|
||||
|
|
13
src/map.rs
13
src/map.rs
|
@ -97,7 +97,7 @@ impl Default for MapConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
#[derive(Bundle, Default)]
|
||||
pub struct PortalBundle {
|
||||
pub portal: Portal,
|
||||
pub mappable: Mappable,
|
||||
|
@ -105,17 +105,6 @@ pub struct PortalBundle {
|
|||
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)]
|
||||
pub struct MapBundle<D: 'static + Clone + Default + Send + Sync> {
|
||||
pub map: Map<D>,
|
||||
|
|
Loading…
Reference in New Issue
Block a user