Skip to content

Commit

Permalink
Use Display for printing entities
Browse files Browse the repository at this point in the history
Looks much less verbose:
`Entity { index: 71, generation: 4 }` comparing to just `71v4`.
  • Loading branch information
Shatur committed Jul 21, 2024
1 parent e169ae7 commit a89b153
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 71 deletions.
10 changes: 5 additions & 5 deletions base/src/game_world/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub const ACTOR_RADIUS: f32 = 0.3;
impl ActorPlugin {
fn init(mut commands: Commands, actors: Query<Entity, Added<Actor>>) {
for entity in &actors {
debug!("initializing actor `{entity:?}`");
debug!("initializing actor `{entity}`");
commands
.entity(entity)
.insert((
Expand Down Expand Up @@ -98,7 +98,7 @@ impl ActorPlugin {
children: Query<&Children>,
) {
for actor_entity in actors.iter_many(ready_events.read().map(|event| event.parent)) {
debug!("initializing outline for `{actor_entity:?}`");
debug!("initializing outline for `{actor_entity}`");
for child_entity in children.iter_descendants(actor_entity) {
commands
.entity(child_entity)
Expand All @@ -115,15 +115,15 @@ impl ActorPlugin {
>,
) {
for (entity, first_name, last_name) in &mut changed_names {
debug!("updating full name for `{entity:?}`");
debug!("updating full name for `{entity}`");
let mut entity = commands.entity(entity);
entity.insert(Name::new(format!("{} {}", first_name.0, last_name.0)));
}
}

fn remove_selection(mut commands: Commands, actors: Query<Entity, With<SelectedActor>>) {
if let Ok(entity) = actors.get_single() {
info!("deselecting actor `{entity:?}`");
info!("deselecting actor `{entity}`");
commands.entity(entity).remove::<SelectedActor>();
}
}
Expand All @@ -135,7 +135,7 @@ impl ActorPlugin {
) {
if let Some(activated_entity) = just_selected_actors.iter().last() {
for actor_entity in actors.iter().filter(|&entity| entity != activated_entity) {
debug!("deselecting previous actor `{actor_entity:?}`");
debug!("deselecting previous actor `{actor_entity}`");
commands.entity(actor_entity).remove::<SelectedActor>();
}
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/game_world/actor/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl HumanPlugin {
.next()
.is_none()
{
debug!("initializing human `{entity:?}`");
debug!("initializing human `{entity}`");
commands.entity(entity).with_children(|parent| {
parent.spawn(NeedBundle::<Bladder>::default());
parent.spawn(NeedBundle::<Energy>::default());
Expand All @@ -74,7 +74,7 @@ impl HumanPlugin {
actors: Query<(Entity, &Sex), (Changed<Sex>, With<Human>)>,
) {
for (entity, &sex) in &actors {
debug!("initializing sex for human `{entity:?}`");
debug!("initializing sex for human `{entity}`");
commands
.entity(entity)
.insert(human_scenes.handle(sex.into()));
Expand Down
12 changes: 6 additions & 6 deletions base/src/game_world/actor/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Plugin for NeedsPlugin {
impl NeedsPlugin {
fn init_hunger(mut commands: Commands, needs: Query<Entity, Added<Hunger>>) {
for entity in &needs {
trace!("initializing hunger need for `{entity:?}`");
trace!("initializing hunger need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("🍴"), NeedRate(-0.4)));
Expand All @@ -58,7 +58,7 @@ impl NeedsPlugin {

fn init_social(mut commands: Commands, needs: Query<Entity, Added<Social>>) {
for entity in &needs {
trace!("initializing social need for `{entity:?}`");
trace!("initializing social need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("💬"), NeedRate(-0.1)));
Expand All @@ -67,7 +67,7 @@ impl NeedsPlugin {

fn init_hygiene(mut commands: Commands, needs: Query<Entity, Added<Hygiene>>) {
for entity in &needs {
trace!("initializing hygiene need for `{entity:?}`");
trace!("initializing hygiene need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("🚿"), NeedRate(-0.3)));
Expand All @@ -76,7 +76,7 @@ impl NeedsPlugin {

fn init_fun(mut commands: Commands, needs: Query<Entity, Added<Fun>>) {
for entity in &needs {
trace!("initializing fun need for `{entity:?}`");
trace!("initializing fun need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("🎉"), NeedRate(-0.1)));
Expand All @@ -85,7 +85,7 @@ impl NeedsPlugin {

fn init_energy(mut commands: Commands, needs: Query<Entity, Added<Energy>>) {
for entity in &needs {
trace!("initializing energy need for `{entity:?}`");
trace!("initializing energy need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("🔋"), NeedRate(-0.2)));
Expand All @@ -94,7 +94,7 @@ impl NeedsPlugin {

fn init_bladder(mut commands: Commands, needs: Query<Entity, Added<Bladder>>) {
for entity in &needs {
trace!("initializing bladder need for `{entity:?}`");
trace!("initializing bladder need for `{entity}`");
commands
.entity(entity)
.insert((NeedGlyph("🚽"), NeedRate(-0.5)));
Expand Down
4 changes: 2 additions & 2 deletions base/src/game_world/actor/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TaskPlugin {
while let Some((entity, groups, mut task_state)) = iter.fetch_next() {
if *task_state == TaskState::Queued && !groups.intersects(current_groups) {
*task_state = TaskState::Active;
debug!("setting `{task_state:?}` for `{entity:?}`");
debug!("setting `{task_state:?}` for `{entity}`");
break;
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ impl TaskPlugin {
) {
for (entity, parent, groups, &task_state) in &tasks {
if task_state == TaskState::Cancelled {
debug!("despawning cancelled task `{entity:?}`");
debug!("despawning cancelled task `{entity}`");
let (mut nav_path, mut animation_state) = actors
.get_mut(**parent)
.expect("actor should have animaition state");
Expand Down
2 changes: 1 addition & 1 deletion base/src/game_world/actor/task/buy_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl BuyLotPlugin {
if lots.get(buy.0).is_ok() {
commands.entity(buy.0).insert(LotFamily(family.0));
} else {
error!("{buy:?} from actor {entity:?} points to not a lot");
error!("`{buy:?}` from actor `{entity}` points to not a lot");
}
commands.entity(entity).despawn();
}
Expand Down
2 changes: 1 addition & 1 deletion base/src/game_world/building/lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Plugin for LotPlugin {
impl LotPlugin {
fn init(mut commands: Commands, spawned_lots: Query<Entity, Added<LotVertices>>) {
for entity in &spawned_lots {
debug!("initializing log `{entity:?}`");
debug!("initializing log `{entity}`");
commands.entity(entity).insert(SpatialBundle::default());
}
}
Expand Down
2 changes: 1 addition & 1 deletion base/src/game_world/building/lot/moving_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl MovingLotPlugin {
.iter()
.find(|(.., vertices)| vertices.contains_point(point.xz()))
{
info!("picking lot `{entity:?}`");
info!("picking lot `{entity}`");
commands.entity(**parent).with_children(|parent| {
parent.spawn((
vertices.clone(),
Expand Down
16 changes: 6 additions & 10 deletions base/src/game_world/building/wall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl WallPlugin {
walls: Query<(Entity, Has<CreatingWall>), Added<Wall>>,
) {
for (entity, creating_wall) in &walls {
debug!("initializing wall `{entity:?}`");
debug!("initializing wall `{entity}`");
let mesh = Mesh::new(PrimitiveTopology::TriangleList, Default::default())
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, Vec::<Vec3>::new())
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, Vec::<Vec2>::new())
Expand Down Expand Up @@ -92,7 +92,7 @@ impl WallPlugin {
mut walls: Query<&mut WallConnections>,
) {
for entity in removed_walls.read() {
debug!("removing connections for despawned wall `{entity:?}`");
debug!("removing connections for despawned wall `{entity}`");
for mut connections in &mut walls {
if let Some((point_kind, index)) = connections.position(entity) {
connections.remove(point_kind, index);
Expand Down Expand Up @@ -139,7 +139,7 @@ impl WallPlugin {
{
if wall.start == other_wall.start {
trace!(
"connecting start of {wall_entity:?} with start of `{other_entity:?}`"
"connecting start of `{wall_entity}` with start of `{other_entity}`"
);
connections.start.push(WallConnection {
entity: other_entity,
Expand All @@ -152,9 +152,7 @@ impl WallPlugin {
point_kind: PointKind::Start,
});
} else if wall.start == other_wall.end {
trace!(
"connecting start of {wall_entity:?} with end of `{other_entity:?}`"
);
trace!("connecting start of `{wall_entity}` with end of `{other_entity}`");
connections.start.push(WallConnection {
entity: other_entity,
segment: *other_wall,
Expand All @@ -166,7 +164,7 @@ impl WallPlugin {
point_kind: PointKind::Start,
});
} else if wall.end == other_wall.end {
trace!("connecting end of {wall_entity:?} with end of `{other_entity:?}`");
trace!("connecting end of `{wall_entity}` with end of `{other_entity}`");
connections.end.push(WallConnection {
entity: other_entity,
segment: *other_wall,
Expand All @@ -178,9 +176,7 @@ impl WallPlugin {
point_kind: PointKind::End,
});
} else if wall.end == other_wall.start {
trace!(
"connecting end of {wall_entity:?} with start of `{other_entity:?}`"
);
trace!("connecting end of `{wall_entity}` with start of `{other_entity}`");
connections.end.push(WallConnection {
entity: other_entity,
segment: *other_wall,
Expand Down
8 changes: 4 additions & 4 deletions base/src/game_world/city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl CityPlugin {
added_cities: Query<Entity, Added<City>>,
) {
for entity in &added_cities {
debug!("initializing city `{entity:?}`");
debug!("initializing city `{entity}`");

let transform =
Transform::from_translation(Vec3::X * CITY_SIZE * placed_citites.0 as f32);
Expand Down Expand Up @@ -82,7 +82,7 @@ impl CityPlugin {

fn activate(mut commands: Commands, actors: Query<&Parent, With<SelectedActor>>) {
let entity = actors.single().get();
info!("activating city `{entity:?}`");
info!("activating city `{entity}`");
commands.entity(entity).insert(ActiveCity);
}

Expand All @@ -91,7 +91,7 @@ impl CityPlugin {
mut activated_cities: Query<(Entity, &mut Visibility), Added<ActiveCity>>,
) {
let (entity, mut visibility) = activated_cities.single_mut();
debug!("initializing activated city `{entity:?}`");
debug!("initializing activated city `{entity}`");
*visibility = Visibility::Visible;
commands.entity(entity).with_children(|parent| {
parent.spawn((
Expand All @@ -116,7 +116,7 @@ impl CityPlugin {
lights: Query<Entity, With<Sun>>,
) {
if let Ok((entity, mut visibility)) = active_cities.get_single_mut() {
info!("deactivating city `{entity:?}`");
info!("deactivating city `{entity}`");
*visibility = Visibility::Hidden;
commands.entity(entity).remove::<ActiveCity>();
commands.entity(cameras.single()).despawn();
Expand Down
4 changes: 2 additions & 2 deletions base/src/game_world/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl FamilyPlugin {
) {
let mut new_families = HashMap::<_, Vec<_>>::new();
for (actor_entity, family) in &actors {
debug!("updating family for actor `{actor_entity:?}`");
debug!("updating family for actor `{actor_entity}`");

// Remove previous.
for mut members in &mut families {
Expand Down Expand Up @@ -142,7 +142,7 @@ impl FamilyPlugin {
for family_entity in delete_events.read().map(|event| event.event.0) {
match families.get(family_entity) {
Ok(members) => {
info!("deleting family `{family_entity:?}`");
info!("deleting family `{family_entity}`");
commands.entity(family_entity).despawn();
for &entity in &members.0 {
commands.entity(entity).despawn_recursive();
Expand Down
6 changes: 3 additions & 3 deletions base/src/game_world/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ impl HoverPlugin {
) {
match (hit, hovered.get_single().ok()) {
(Some((hit_entity, point)), None) => {
debug!("hovered `{hit_entity:?}`");
debug!("hovered `{hit_entity}`");
commands.entity(hit_entity).insert(Hovered(point));
}
(None, Some(previous_entity)) => {
debug!("unhovered `{previous_entity:?}`");
debug!("unhovered `{previous_entity}`");
commands.entity(previous_entity).remove::<Hovered>();
}
(Some((hit_entity, point)), Some(previous_entity)) => {
commands.entity(hit_entity).insert(Hovered(point));
if hit_entity != previous_entity {
debug!("changing hover from `{previous_entity:?}` to `{hit_entity:?}`");
debug!("changing hover from `{previous_entity}` to `{hit_entity}`");
commands.entity(previous_entity).remove::<Hovered>();
}
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/game_world/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ObjectPlugin {
.unwrap_or_else(|| panic!("{object_path:?} should correspond to metadata"));

let scene_path = metadata::gltf_asset(&object_path.0, GltfAssetLabel::Scene(0));
debug!("initializing object `{entity:?}` for '{scene_path:?}'");
debug!("initializing object `{entity}` for '{scene_path}'");

let scene_handle: Handle<Scene> = asset_server.load(scene_path);
let mut entity = commands.entity(entity);
Expand Down Expand Up @@ -137,7 +137,7 @@ impl ObjectPlugin {
let collider = Collider::convex_hull_from_mesh(&merged_mesh)
.expect("object mesh should be in compatible format");

debug!("inserting collider for `{object_entity:?}`");
debug!("inserting collider for `{object_entity}`");
commands.entity(object_entity).insert(collider);
}
}
Expand Down
6 changes: 3 additions & 3 deletions base/src/game_world/object/door.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Plugin for DoorPlugin {
impl DoorPlugin {
fn init(mut commands: Commands, objects: Query<Entity, Added<Door>>) {
for entity in &objects {
debug!("initializing door for {entity:?}");
debug!("initializing door for `{entity}`");
commands.entity(entity).insert(DoorState::default());
}
}
Expand All @@ -55,7 +55,7 @@ impl DoorPlugin {
let door_end = door_transform.transform_point(-door_point).xz();
let door_segment = Segment::new(door_start, door_end);
if nav_segment.intersects(door_segment) {
debug!("marking path of actor `{actor_entity:?}` as passing");
debug!("marking path of actor `{actor_entity}` as passing");
door_state.passing_actors.push(actor_entity);
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl DoorPlugin {
) {
for entity in removed_actors.read() {
for mut door_state in &mut objects {
debug!("removing path of deleted actor `{entity:?}`");
debug!("removing path of deleted actor `{entity}`");
door_state.remove_passing(entity);
}
}
Expand Down
6 changes: 3 additions & 3 deletions base/src/game_world/object/placing_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl PlacingObjectPlugin {
hovered: Query<(Entity, &Parent), (With<ObjectPath>, With<Hovered>)>,
) {
if let Ok((object_entity, parent)) = hovered.get_single() {
info!("picking object `{object_entity:?}`");
info!("picking object `{object_entity}`");
commands.entity(**parent).with_children(|parent| {
parent.spawn(PlacingObject::Moving(object_entity));
});
Expand All @@ -105,7 +105,7 @@ impl PlacingObjectPlugin {
return;
};

debug!("initializing placing object `{placing_entity:?}` for `{placing_object:?}`");
debug!("initializing placing object `{placing_entity}` for `{placing_object:?}`");
match placing_object {
PlacingObject::Spawning(id) => {
let metadata_path = asset_server
Expand Down Expand Up @@ -311,7 +311,7 @@ impl PlacingObjectPlugin {
if let Some(new_entity) = new_placing_objects.iter().last() {
for placing_entity in &placing_objects {
if placing_entity != new_entity {
debug!("removing previous placing object `{placing_entity:?}`");
debug!("removing previous placing object `{placing_entity}`");
commands.entity(placing_entity).despawn_recursive();
}
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/game_world/object/placing_object/side_snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Plugin for SideSnapPlugin {
impl SideSnapPlugin {
fn init(mut commands: Commands, objects: Query<Entity, Added<SideSnap>>) {
for entity in &objects {
debug!("initializing side snapping for `{entity:?}`");
debug!("initializing side snapping for `{entity}`");
commands.entity(entity).insert(SideSnapNodes::default());
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl SideSnapPlugin {
}

fn connect_nodes(nodes: &mut Query<&mut SideSnapNodes>, left_entity: Entity, right_entity: Entity) {
debug!("connecting `{left_entity:?}` with `{right_entity:?}`");
debug!("connecting `{left_entity}` with `{right_entity}`");
let mut left_nodes = nodes
.get_mut(left_entity)
.expect("left side snap entity should have nodes");
Expand Down
Loading

0 comments on commit a89b153

Please sign in to comment.