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_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 {
|
||||||
|
@ -239,24 +238,28 @@ fn exploration_focus<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
|
||||||
(floor.x, floor.y)
|
(floor.x, floor.y)
|
||||||
};
|
};
|
||||||
let orig = exploring;
|
let orig = exploring;
|
||||||
if input.just_active(explore_forward.clone()) {
|
if input.just_active(explore_forward) {
|
||||||
exploring.1 += 1.;
|
exploring.1 += 1.;
|
||||||
} else if input.just_active(explore_backward.clone()) {
|
} else if input.just_active(explore_backward) {
|
||||||
exploring.1 -= 1.;
|
exploring.1 -= 1.;
|
||||||
} else if input.just_active(explore_left.clone()) {
|
} else if input.just_active(explore_left) {
|
||||||
exploring.0 -= 1.;
|
exploring.0 -= 1.;
|
||||||
} else if input.just_active(explore_right.clone()) {
|
} else if input.just_active(explore_right) {
|
||||||
exploring.0 += 1.;
|
exploring.0 += 1.;
|
||||||
}
|
}
|
||||||
if orig != exploring
|
let dimensions = if let Ok(map) = map.get_single() {
|
||||||
&& exploring.0 >= 0.
|
Some((map.width as f32, map.height as f32))
|
||||||
&& exploring.0 < map.width as f32
|
} else {
|
||||||
&& exploring.1 >= 0.
|
None
|
||||||
&& exploring.1 < map.height as f32
|
};
|
||||||
{
|
if let Some((width, height)) = dimensions {
|
||||||
commands.entity(entity).insert(Exploring(exploring));
|
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() {
|
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 idx = point.to_index(map.width);
|
|
||||||
let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON);
|
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 visible = viewshed.is_point_visible(exploring);
|
||||||
let fog_of_war = known && !visible;
|
let fog_of_war = !visible && known;
|
||||||
let description = if known {
|
let description: String = if known || visible {
|
||||||
let mut tokens: Vec<String> = vec![];
|
let mut tokens: Vec<String> = vec![];
|
||||||
for entity in focused.iter() {
|
for entity in focused.iter() {
|
||||||
commands.entity(entity).remove::<ExplorationFocused>();
|
commands.entity(entity).remove::<ExplorationFocused>();
|
||||||
|
@ -339,27 +345,31 @@ where
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if tokens.is_empty() {
|
if tokens.is_empty() {
|
||||||
|
if let Some(idx) = idx {
|
||||||
|
if let Ok((map, _)) = map.get_single() {
|
||||||
let tile = map.tiles[idx];
|
let tile = map.tiles[idx];
|
||||||
if tile.is_blocked() {
|
if tile.is_blocked() {
|
||||||
"wall".to_string()
|
tokens.push("wall".to_string());
|
||||||
} else {
|
} else {
|
||||||
"floor".to_string()
|
tokens.push("floor".to_string());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokens.first().cloned().unwrap_or_default()
|
||||||
} else {
|
} else {
|
||||||
tokens.join(": ")
|
tokens.join(": ")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
"Unknown".to_string()
|
"Unknown".to_string()
|
||||||
};
|
};
|
||||||
let mut tokens: Vec<String> = vec![
|
let mut tokens = vec![
|
||||||
description,
|
description,
|
||||||
coordinates.direction_and_distance(exploring, None),
|
coordinates.direction_and_distance(exploring, None),
|
||||||
];
|
];
|
||||||
if fog_of_war {
|
if fog_of_war {
|
||||||
tokens.push("in the fog of war".into());
|
tokens.push("in the fog of war".to_string());
|
||||||
}
|
|
||||||
tts.speak(tokens.join(", ").to_string(), true)?;
|
|
||||||
}
|
}
|
||||||
|
tts.speak(tokens.join(", "), true)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
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 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>,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user