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,7 +229,6 @@ 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 {
|
||||
|
@ -239,24 +238,28 @@ fn exploration_focus<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
|
|||
(floor.x, floor.y)
|
||||
};
|
||||
let orig = exploring;
|
||||
if input.just_active(explore_forward.clone()) {
|
||||
if input.just_active(explore_forward) {
|
||||
exploring.1 += 1.;
|
||||
} else if input.just_active(explore_backward.clone()) {
|
||||
} else if input.just_active(explore_backward) {
|
||||
exploring.1 -= 1.;
|
||||
} else if input.just_active(explore_left.clone()) {
|
||||
} else if input.just_active(explore_left) {
|
||||
exploring.0 -= 1.;
|
||||
} else if input.just_active(explore_right.clone()) {
|
||||
} else if input.just_active(explore_right) {
|
||||
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));
|
||||
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,14 +308,17 @@ 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 idx = point.to_index(map.width);
|
||||
let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON);
|
||||
let known = revealed_tiles[idx];
|
||||
let (known, idx) = if let Ok((map, revealed_tiles)) = map.get_single() {
|
||||
let idx = point.to_index(map.width);
|
||||
(revealed_tiles[idx], Some(idx))
|
||||
} else {
|
||||
(false, None)
|
||||
};
|
||||
let visible = viewshed.is_point_visible(exploring);
|
||||
let fog_of_war = known && !visible;
|
||||
let description = if known {
|
||||
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>();
|
||||
|
@ -339,27 +345,31 @@ where
|
|||
},
|
||||
);
|
||||
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() {
|
||||
"wall".to_string()
|
||||
tokens.push("wall".to_string());
|
||||
} else {
|
||||
"floor".to_string()
|
||||
tokens.push("floor".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
tokens.first().cloned().unwrap_or_default()
|
||||
} else {
|
||||
tokens.join(": ")
|
||||
}
|
||||
} else {
|
||||
"Unknown".to_string()
|
||||
};
|
||||
let mut tokens: Vec<String> = vec![
|
||||
let mut tokens = 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)?;
|
||||
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