refactor(simulation): apply rustfmt formatting

Formatting-only changes across server source and test files.
No logic changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 01:39:44 +01:00
co-authored by Claude Opus 4.6
parent 1da81a21ea
commit d5a1f6dadb
16 changed files with 169 additions and 105 deletions
+42 -20
View File
@@ -19,7 +19,9 @@ use bevy_ecs::prelude::*;
use rand::Rng;
use crate::bridge::types::{DialogueResponseEvent, RelationshipState};
use crate::content::line_pool::{AccessTier, IndexedDialogueLine, Mood, Situation, Topic, TrustTier};
use crate::content::line_pool::{
AccessTier, IndexedDialogueLine, Mood, Situation, Topic, TrustTier,
};
use crate::content::LinePoolIndexResource;
use crate::knowledge::{EntityRegistry, KnowledgeGraph};
use crate::simulation::movement::PlayerCharacter;
@@ -219,7 +221,11 @@ pub fn derive_situations(
/// - Topic match: +2 per matching topic
///
/// Returns 0 only for lines on cooldown (caller handles).
pub fn score_line(line: &IndexedDialogueLine, npc_mood: Option<Mood>, active_topics: &[Topic]) -> u32 {
pub fn score_line(
line: &IndexedDialogueLine,
npc_mood: Option<Mood>,
active_topics: &[Topic],
) -> u32 {
let mut score: u32 = 1; // Base score — no line is excluded by Layer 4
// Mood match
@@ -318,8 +324,14 @@ pub fn process_talk_interaction(
return;
};
let Ok((player_entity, observer_kg, talk_request, mut response_buffer, mut cooldown, active_dialogue_opt)) =
player_query.single_mut()
let Ok((
player_entity,
observer_kg,
talk_request,
mut response_buffer,
mut cooldown,
active_dialogue_opt,
)) = player_query.single_mut()
else {
return;
};
@@ -784,9 +796,14 @@ mod tests {
let mut match_count = 0;
for seed in 0..100 {
let mut rng = rand_chacha::ChaCha20Rng::seed_from_u64(seed);
if let Some(line) =
select_dialogue_line(&candidates, Some(Mood::Worried), &[], &cooldown, 0, &mut rng)
{
if let Some(line) = select_dialogue_line(
&candidates,
Some(Mood::Worried),
&[],
&cooldown,
0,
&mut rng,
) {
if line.id == "matched" {
match_count += 1;
}
@@ -869,9 +886,10 @@ mod tests {
role: "dock-worker".to_string(),
lines,
};
index
.dialogue
.insert(("the-terminal".to_string(), "dock-worker".to_string()), pool);
index.dialogue.insert(
("the-terminal".to_string(), "dock-worker".to_string()),
pool,
);
index
}
@@ -1009,10 +1027,11 @@ mod tests {
let mut seen_ids: Vec<String> = Vec::new();
for seed in 0..20 {
// Reset for each iteration
world.get_mut::<DialogueResponseBuffer>(player).unwrap().response = None;
world
.entity_mut(player)
.insert(TalkRequest { target: npc });
.get_mut::<DialogueResponseBuffer>(player)
.unwrap()
.response = None;
world.entity_mut(player).insert(TalkRequest { target: npc });
world.insert_resource(SimRng::new(seed));
let mut schedule = bevy_ecs::schedule::Schedule::default();
@@ -1020,7 +1039,11 @@ mod tests {
schedule.run(&mut world);
world.flush();
if let Some(resp) = &world.get::<DialogueResponseBuffer>(player).unwrap().response {
if let Some(resp) = &world
.get::<DialogueResponseBuffer>(player)
.unwrap()
.response
{
if !seen_ids.contains(&resp.line_id) {
seen_ids.push(resp.line_id.clone());
}
@@ -1046,9 +1069,7 @@ mod tests {
world.insert_resource(LinePoolIndexResource(index));
// NPC without DialogueProfile
let npc = world
.spawn((Npc, TilePosition::new(5, 5, 0)))
.id();
let npc = world.spawn((Npc, TilePosition::new(5, 5, 0))).id();
world.resource_mut::<EntityRegistry>().register(npc);
let player = world
@@ -1142,10 +1163,11 @@ mod tests {
);
// Second talk — same tick, line on cooldown
world.get_mut::<DialogueResponseBuffer>(player).unwrap().response = None;
world
.entity_mut(player)
.insert(TalkRequest { target: npc });
.get_mut::<DialogueResponseBuffer>(player)
.unwrap()
.response = None;
world.entity_mut(player).insert(TalkRequest { target: npc });
let mut schedule2 = bevy_ecs::schedule::Schedule::default();
schedule2.add_systems(process_talk_interaction);
+16 -17
View File
@@ -102,12 +102,7 @@ pub fn process_player_input(
for input in inputs {
// Discard all gameplay actions while paused (D-052, R2-OQ-01).
// Only Pause/Unpause are processed — everything else is discarded.
if paused
&& !matches!(
input.action,
PlayerAction::Pause | PlayerAction::Unpause
)
{
if paused && !matches!(input.action, PlayerAction::Pause | PlayerAction::Unpause) {
continue;
}
match input.action {
@@ -190,14 +185,20 @@ pub fn process_player_input(
handle_place(&mut commands, &registry, &player_query, target_entity_id);
}
Some("Talk") => {
handle_talk(&mut commands, &registry, &player_query, &all_positions, target_entity_id);
handle_talk(
&mut commands,
&registry,
&player_query,
&all_positions,
target_entity_id,
);
}
_ => {
tracing::info!(
"Interact: target={:?}, verb={:?} — logged only",
target_entity_id,
verb,
);
"Interact: target={:?}, verb={:?} — logged only",
target_entity_id,
verb,
);
}
},
PlayerAction::WalkAway => {
@@ -363,7 +364,9 @@ fn handle_talk(
// Server-side range check: reject Talk if target is beyond close range
if let Ok(target_pos) = all_positions.get(target_entity) {
let distance = player_pos.manhattan_distance(target_pos).unwrap_or(u32::MAX);
let distance = player_pos
.manhattan_distance(target_pos)
.unwrap_or(u32::MAX);
if distance > crate::simulation::interaction::CLOSE_RANGE {
tracing::info!(
target_id,
@@ -1312,11 +1315,7 @@ mod tests {
);
let mut query = world.query::<&Stance>();
let stance = query.single(&world).unwrap();
assert_eq!(
stance.0,
MovementStance::Walk,
"Stance unchanged in batch"
);
assert_eq!(stance.0, MovementStance::Walk, "Stance unchanged in batch");
assert_eq!(
world.resource::<SimulationTime>().tick_rate,
TickRate::Paused,
+19 -17
View File
@@ -39,18 +39,12 @@ pub(crate) const ANOMALY_DELAY_TICKS: u64 = 90;
/// Fire DURING cognitive delay (when grey blob appears). Future: move to
/// content pools with trigger="observe_anomaly" + character match.
const RECOGNITION_LINES: &[(&str, &str)] = &[
(
"recognition_01",
"Wait \u{2014} I know that walk.",
),
("recognition_01", "Wait \u{2014} I know that walk."),
(
"recognition_02",
"Those footsteps... I've heard that pattern before.",
),
(
"recognition_03",
"Something about that silhouette...",
),
("recognition_03", "Something about that silhouette..."),
];
/// Hardcoded v0.1 sprint anomaly "double-take" lines.
@@ -258,9 +252,9 @@ pub fn trigger_recognition_monologue(
let pending = cognitive_delay.pending_mut();
let target_idx = {
// First pass: anomalous + unfired
let anomaly_idx = pending.iter().position(|p| {
!p.monologue_fired && anomaly_markers.get(p.target).is_ok()
});
let anomaly_idx = pending
.iter()
.position(|p| !p.monologue_fired && anomaly_markers.get(p.target).is_ok());
if let Some(idx) = anomaly_idx {
Some(idx)
} else {
@@ -872,10 +866,10 @@ mod tests {
// trigger_recognition_monologue tests (#451, D-060)
// -----------------------------------------------------------------------
use crate::knowledge::types::StableId;
use crate::perception::cognitive_delay::{
CognitiveDelay, PendingRecognition, RecognitionTrigger, NORMAL_DELAY_TICKS,
};
use crate::knowledge::types::StableId;
fn setup_recognition_world() -> World {
let mut world = World::new();
@@ -957,7 +951,12 @@ mod tests {
// First tick: fires
schedule.run(&mut world);
assert!(
world.query::<&MonologueBuffer>().single(&world).unwrap().event.is_some(),
world
.query::<&MonologueBuffer>()
.single(&world)
.unwrap()
.event
.is_some(),
"first tick should fire"
);
@@ -967,7 +966,12 @@ mod tests {
// Second tick: should NOT fire (monologue_fired = true)
schedule.run(&mut world);
assert!(
world.query::<&MonologueBuffer>().single(&world).unwrap().event.is_none(),
world
.query::<&MonologueBuffer>()
.single(&world)
.unwrap()
.event
.is_none(),
"second tick should not fire (already fired for this recognition)"
);
}
@@ -1053,9 +1057,7 @@ mod tests {
let mut world = setup_recognition_world();
let normal_target = world.spawn_empty().id();
let anomalous_target = world
.spawn(crate::perception::anomaly::AnomalyMarker)
.id();
let anomalous_target = world.spawn(crate::perception::anomaly::AnomalyMarker).id();
let mut cd = CognitiveDelay::default();
// Normal entity added first
+4 -2
View File
@@ -917,12 +917,14 @@ mod tests {
// Entity with lower bits processes first and claims the target
assert_eq!(
pos_lower, target,
pos_lower,
target,
"entity with lower Entity::to_bits() ({}) should win the tile",
lower.to_bits()
);
assert_eq!(
pos_higher, higher_origin,
pos_higher,
higher_origin,
"entity with higher Entity::to_bits() ({}) should stay at origin",
higher.to_bits()
);