refactor(server): apply rustfmt and clippy suggestions
Formatting pass across simulation, perception, knowledge, NPC, and test modules. Includes two clippy fixes in monologue.rs (.values() instead of for (_, v) pattern). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -52,30 +52,100 @@ impl ObjectType {
|
||||
pub fn verb_set(&self) -> &'static [VerbDef] {
|
||||
match self {
|
||||
Self::Readable => &[
|
||||
VerbDef { kind: VerbKind::Read, label: "Read", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 2, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Read,
|
||||
label: "Read",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 2,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
Self::Container => &[
|
||||
VerbDef { kind: VerbKind::Open, label: "Open", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Search, label: "Search", priority: 2, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 3, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Open,
|
||||
label: "Open",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Search,
|
||||
label: "Search",
|
||||
priority: 2,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 3,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
Self::Terminal => &[
|
||||
VerbDef { kind: VerbKind::Use, label: "Use", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 2, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Use,
|
||||
label: "Use",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 2,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
Self::Door => &[
|
||||
VerbDef { kind: VerbKind::Open, label: "Open", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Close, label: "Close", priority: 2, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 3, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Open,
|
||||
label: "Open",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Close,
|
||||
label: "Close",
|
||||
priority: 2,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 3,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
Self::Pickup => &[
|
||||
VerbDef { kind: VerbKind::Take, label: "Take", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 2, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Take,
|
||||
label: "Take",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 2,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
Self::Furniture => &[
|
||||
VerbDef { kind: VerbKind::Sit, label: "Sit", priority: 1, close_only: true },
|
||||
VerbDef { kind: VerbKind::Observe, label: "Observe", priority: 2, close_only: false },
|
||||
VerbDef {
|
||||
kind: VerbKind::Sit,
|
||||
label: "Sit",
|
||||
priority: 1,
|
||||
close_only: true,
|
||||
},
|
||||
VerbDef {
|
||||
kind: VerbKind::Observe,
|
||||
label: "Observe",
|
||||
priority: 2,
|
||||
close_only: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -201,7 +271,10 @@ pub fn compute_nearby_interactions(
|
||||
.to_stable(entity)
|
||||
.map(|sid| sid.0)
|
||||
.unwrap_or_else(|| {
|
||||
tracing::error!(?entity, "entity in interaction range but not in EntityRegistry");
|
||||
tracing::error!(
|
||||
?entity,
|
||||
"entity in interaction range but not in EntityRegistry"
|
||||
);
|
||||
entity.to_bits()
|
||||
});
|
||||
|
||||
@@ -216,9 +289,7 @@ pub fn compute_nearby_interactions(
|
||||
}
|
||||
|
||||
// Sort interactions by distance (nearest first)
|
||||
buffer
|
||||
.interactions
|
||||
.sort_by_key(|a| a.distance);
|
||||
buffer.interactions.sort_by_key(|a| a.distance);
|
||||
}
|
||||
|
||||
/// Buffer for nearby interaction results, consumed by snapshot generation.
|
||||
@@ -417,11 +488,7 @@ mod tests {
|
||||
fn door_close_range_gets_open_close_observe() {
|
||||
let mut world = setup_world();
|
||||
spawn_player(&mut world, 5, 5);
|
||||
world.spawn((
|
||||
TilePosition::new(5, 6, 0),
|
||||
Interactable,
|
||||
ObjectType::Door,
|
||||
));
|
||||
world.spawn((TilePosition::new(5, 6, 0), Interactable, ObjectType::Door));
|
||||
|
||||
let mut schedule = bevy_ecs::schedule::Schedule::default();
|
||||
schedule.add_systems(compute_nearby_interactions);
|
||||
@@ -439,11 +506,7 @@ mod tests {
|
||||
fn pickup_close_range_gets_take_and_observe() {
|
||||
let mut world = setup_world();
|
||||
spawn_player(&mut world, 5, 5);
|
||||
world.spawn((
|
||||
TilePosition::new(5, 6, 0),
|
||||
Interactable,
|
||||
ObjectType::Pickup,
|
||||
));
|
||||
world.spawn((TilePosition::new(5, 6, 0), Interactable, ObjectType::Pickup));
|
||||
|
||||
let mut schedule = bevy_ecs::schedule::Schedule::default();
|
||||
schedule.add_systems(compute_nearby_interactions);
|
||||
@@ -514,7 +577,10 @@ mod tests {
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 1);
|
||||
assert_eq!(buffer.interactions[0].verbs.len(), 1);
|
||||
assert_eq!(buffer.interactions[0].verbs[0].kind, VerbKind::ExamineObject);
|
||||
assert_eq!(
|
||||
buffer.interactions[0].verbs[0].kind,
|
||||
VerbKind::ExamineObject
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -593,7 +659,10 @@ mod tests {
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 2);
|
||||
assert_eq!(buffer.interactions[0].distance, buffer.interactions[1].distance);
|
||||
assert_eq!(
|
||||
buffer.interactions[0].distance,
|
||||
buffer.interactions[1].distance
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -708,11 +777,7 @@ mod tests {
|
||||
let mut world = setup_world();
|
||||
spawn_player(&mut world, 5, 5);
|
||||
// Distance 4 = mid range (> CLOSE_RANGE=2, <= MID_RANGE=5)
|
||||
world.spawn((
|
||||
TilePosition::new(5, 9, 0),
|
||||
Interactable,
|
||||
obj_type,
|
||||
));
|
||||
world.spawn((TilePosition::new(5, 9, 0), Interactable, obj_type));
|
||||
|
||||
let mut schedule = bevy_ecs::schedule::Schedule::default();
|
||||
schedule.add_systems(compute_nearby_interactions);
|
||||
@@ -720,16 +785,22 @@ mod tests {
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(
|
||||
buffer.interactions.len(), 1,
|
||||
"{:?} at mid range should produce 1 interaction", obj_type
|
||||
buffer.interactions.len(),
|
||||
1,
|
||||
"{:?} at mid range should produce 1 interaction",
|
||||
obj_type
|
||||
);
|
||||
assert_eq!(
|
||||
buffer.interactions[0].verbs.len(), 1,
|
||||
"{:?} at mid range should have exactly 1 verb (Observe)", obj_type
|
||||
buffer.interactions[0].verbs.len(),
|
||||
1,
|
||||
"{:?} at mid range should have exactly 1 verb (Observe)",
|
||||
obj_type
|
||||
);
|
||||
assert_eq!(
|
||||
buffer.interactions[0].verbs[0].kind, VerbKind::Observe,
|
||||
"{:?} at mid range verb should be Observe", obj_type
|
||||
buffer.interactions[0].verbs[0].kind,
|
||||
VerbKind::Observe,
|
||||
"{:?} at mid range verb should be Observe",
|
||||
obj_type
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -795,11 +866,16 @@ mod tests {
|
||||
for obj_type in types {
|
||||
for def in obj_type.verb_set() {
|
||||
if def.kind == VerbKind::Observe {
|
||||
assert!(!def.close_only, "{:?} Observe should be mid-range", obj_type);
|
||||
assert!(
|
||||
!def.close_only,
|
||||
"{:?} Observe should be mid-range",
|
||||
obj_type
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
def.close_only,
|
||||
"{:?} {:?} should be close-only", obj_type, def.kind
|
||||
"{:?} {:?} should be close-only",
|
||||
obj_type, def.kind
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -822,7 +898,9 @@ mod tests {
|
||||
let verbs = obj_type.verb_set();
|
||||
assert!(
|
||||
verbs.len() <= 4,
|
||||
"{:?} has {} verbs, D-057 max is 4", obj_type, verbs.len()
|
||||
"{:?} has {} verbs, D-057 max is 4",
|
||||
obj_type,
|
||||
verbs.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -832,7 +910,12 @@ mod tests {
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/// Spawn player with Stance component for sprint suppression tests.
|
||||
fn spawn_player_with_stance(world: &mut World, x: i32, y: i32, stance: MovementStance) -> Entity {
|
||||
fn spawn_player_with_stance(
|
||||
world: &mut World,
|
||||
x: i32,
|
||||
y: i32,
|
||||
stance: MovementStance,
|
||||
) -> Entity {
|
||||
world
|
||||
.spawn((
|
||||
PlayerCharacter,
|
||||
@@ -854,21 +937,31 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert!(buffer.interactions.is_empty(), "sprint should suppress all interactions");
|
||||
assert!(
|
||||
buffer.interactions.is_empty(),
|
||||
"sprint should suppress all interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sprint_suppresses_object_interactions() {
|
||||
let mut world = setup_world();
|
||||
spawn_player_with_stance(&mut world, 5, 5, MovementStance::Sprint);
|
||||
world.spawn((TilePosition::new(5, 6, 0), Interactable, ObjectType::Terminal));
|
||||
world.spawn((
|
||||
TilePosition::new(5, 6, 0),
|
||||
Interactable,
|
||||
ObjectType::Terminal,
|
||||
));
|
||||
|
||||
let mut schedule = bevy_ecs::schedule::Schedule::default();
|
||||
schedule.add_systems(compute_nearby_interactions);
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert!(buffer.interactions.is_empty(), "sprint should suppress object interactions");
|
||||
assert!(
|
||||
buffer.interactions.is_empty(),
|
||||
"sprint should suppress object interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -882,7 +975,11 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 1, "Walk should allow interactions");
|
||||
assert_eq!(
|
||||
buffer.interactions.len(),
|
||||
1,
|
||||
"Walk should allow interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -896,7 +993,11 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 1, "Careful should allow interactions");
|
||||
assert_eq!(
|
||||
buffer.interactions.len(),
|
||||
1,
|
||||
"Careful should allow interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -910,7 +1011,11 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 1, "Crouch should allow interactions");
|
||||
assert_eq!(
|
||||
buffer.interactions.len(),
|
||||
1,
|
||||
"Crouch should allow interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -925,7 +1030,11 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert_eq!(buffer.interactions.len(), 1, "no Stance component should allow interactions");
|
||||
assert_eq!(
|
||||
buffer.interactions.len(),
|
||||
1,
|
||||
"no Stance component should allow interactions"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -933,7 +1042,11 @@ mod tests {
|
||||
let mut world = setup_world();
|
||||
spawn_player_with_stance(&mut world, 5, 5, MovementStance::Sprint);
|
||||
world.spawn((Npc, TilePosition::new(5, 6, 0), Interactable));
|
||||
world.spawn((TilePosition::new(6, 5, 0), Interactable, ObjectType::Container));
|
||||
world.spawn((
|
||||
TilePosition::new(6, 5, 0),
|
||||
Interactable,
|
||||
ObjectType::Container,
|
||||
));
|
||||
world.spawn((TilePosition::new(4, 5, 0), Interactable));
|
||||
|
||||
let mut schedule = bevy_ecs::schedule::Schedule::default();
|
||||
@@ -941,6 +1054,9 @@ mod tests {
|
||||
schedule.run(&mut world);
|
||||
|
||||
let buffer = read_buffer(&mut world);
|
||||
assert!(buffer.interactions.is_empty(), "sprint should suppress all 3 nearby entities");
|
||||
assert!(
|
||||
buffer.interactions.is_empty(),
|
||||
"sprint should suppress all 3 nearby entities"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user