From 62c01f4cada875b456d785229c8f6bb12a067711 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Fri, 23 Jun 2023 14:34:15 -0400 Subject: [PATCH] Add walkable neighbors to selection details (#978) --- emergence_lib/src/geometry/indexing.rs | 16 ++++++++++++++ emergence_lib/src/ui/selection_details.rs | 27 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/emergence_lib/src/geometry/indexing.rs b/emergence_lib/src/geometry/indexing.rs index 14fc39602..281d6cf59 100644 --- a/emergence_lib/src/geometry/indexing.rs +++ b/emergence_lib/src/geometry/indexing.rs @@ -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)] @@ -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::>() + .join(", "); + + write!(f, "[{}]", string) + } +} + /// An iterator over the neighbors of a voxel position. struct NeighborIter<'a> { /// A reference to the data diff --git a/emergence_lib/src/ui/selection_details.rs b/emergence_lib/src/ui/selection_details.rs index a57a222e9..1e3966d33 100644 --- a/emergence_lib/src/ui/selection_details.rs +++ b/emergence_lib/src/ui/selection_details.rs @@ -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 @@ -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, @@ -833,6 +840,8 @@ Output: {output}" pub(super) zoning: Zoning, /// The details about the terraforming process, if any pub(super) maybe_terraforming_details: Option, + /// The neighbors connected to the tile above this terrain + pub(super) walkable_neighbors: Vec, } impl TerrainDetails { @@ -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::>() + .join("\n "); let base_string = format!( "Entity: {entity:?} @@ -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 { @@ -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, } impl UnitDetails { @@ -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::>() + .join("\n "); format!( "Entity: {entity:?} Unit type: {unit_name} Tile: {voxel_pos} +Walkable Neighbors: {walkable_neighbors} Diet: {diet} Holding: {held_item} Goal: {goal}