Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Add walkable neighbors to selection details (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile authored Jun 23, 2023
1 parent ff0c161 commit 62c01f4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
16 changes: 16 additions & 0 deletions emergence_lib/src/geometry/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};

use super::{DiscreteHeight, Facing, Height, VoxelKind, VoxelObject, VoxelPos};
use core::fmt::Display;

/// The overall size and arrangement of the map.
#[derive(Debug, Resource, Clone)]
Expand Down Expand Up @@ -66,6 +67,21 @@ impl Neighbors {
}
}

impl Display for Neighbors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let iter = NeighborIter {
neighbors: self,
index: 0,
};
let string = iter
.map(|neighbor| format!("{}", neighbor))
.collect::<Vec<_>>()
.join(", ");

write!(f, "[{}]", string)
}
}

/// An iterator over the neighbors of a voxel position.
struct NeighborIter<'a> {
/// A reference to the data
Expand Down
27 changes: 26 additions & 1 deletion emergence_lib/src/ui/selection_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ fn get_details(
output_inventory: q.2.clone(),
},
),
walkable_neighbors: map_geometry
// The terrain voxel itself cannot be walked through!
.walkable_neighbors(terrain_query_item.voxel_pos.above())
.collect(),
})
} else {
SelectionDetails::None
Expand Down Expand Up @@ -410,6 +414,9 @@ fn get_details(
impatience_pool: unit_query_item.impatience_pool.clone(),
age: unit_query_item.age.clone(),
organism_details,
walkable_neighbors: map_geometry
.walkable_neighbors(*unit_query_item.voxel_pos)
.collect(),
})
}
CurrentSelection::None => SelectionDetails::None,
Expand Down Expand Up @@ -833,6 +840,8 @@ Output: {output}"
pub(super) zoning: Zoning,
/// The details about the terraforming process, if any
pub(super) maybe_terraforming_details: Option<TerraformingDetails>,
/// The neighbors connected to the tile above this terrain
pub(super) walkable_neighbors: Vec<VoxelPos>,
}

impl TerrainDetails {
Expand All @@ -858,6 +867,12 @@ Output: {output}"
unit_manifest,
);
let zoning = self.zoning.display(structure_manifest, terrain_manifest);
let walkable_neighbors = self
.walkable_neighbors
.iter()
.map(|neighbor| format!("{}", neighbor))
.collect::<Vec<_>>()
.join("\n ");

let base_string = format!(
"Entity: {entity:?}
Expand All @@ -867,7 +882,8 @@ Height: {height}
Water Table: {depth_to_water_table}
Shade: {shade}
Current Light: {recieved_light}
Zoning: {zoning}"
Zoning: {zoning}
Walkable Neighbors: {walkable_neighbors}"
);

if let Some(terraforming_details) = &self.maybe_terraforming_details {
Expand Down Expand Up @@ -948,6 +964,8 @@ mod unit_details {
pub(super) impatience_pool: ImpatiencePool,
/// The current and max age of this unit.
pub(super) age: Age,
/// The set of voxels that this unit can walk to
pub(super) walkable_neighbors: Vec<VoxelPos>,
}

impl UnitDetails {
Expand Down Expand Up @@ -976,11 +994,18 @@ mod unit_details {
.organism_details
.display(structure_manifest, unit_manifest);
let age = &self.age;
let walkable_neighbors = self
.walkable_neighbors
.iter()
.map(|neighbor| format!("{}", neighbor))
.collect::<Vec<_>>()
.join("\n ");

format!(
"Entity: {entity:?}
Unit type: {unit_name}
Tile: {voxel_pos}
Walkable Neighbors: {walkable_neighbors}
Diet: {diet}
Holding: {held_item}
Goal: {goal}
Expand Down

0 comments on commit 62c01f4

Please sign in to comment.