fix(simulation): Clippy cleanup and CI enforcement (#635)
Fix all Clippy warnings across the server codebase (2411 insertions, 1341 deletions). Raise type-complexity-threshold to 750 and too-many-arguments to 12 in .clippy.toml for idiomatic Bevy ECS system signatures. The server now passes `cargo clippy -- --deny warnings` cleanly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
use rand::Rng;
|
||||
use std::cmp::Reverse;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::knowledge::registry::StableEntityId;
|
||||
@@ -30,8 +31,8 @@ use crate::npc::Npc;
|
||||
use crate::simulation::conversation::NpcConversation;
|
||||
use crate::simulation::movement::{PlayerCharacter, TilePosition};
|
||||
use crate::simulation::rng::SimRng;
|
||||
use crate::simulation::time::SimulationTime;
|
||||
use crate::simulation::tier::ActiveSim;
|
||||
use crate::simulation::time::SimulationTime;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
@@ -123,7 +124,12 @@ pub fn transfer_npc_knowledge(
|
||||
mut event_queue: ResMut<KnowledgeEventQueue>,
|
||||
// NPCs that just started a conversation — Added fires once per conversation.
|
||||
new_conv_query: Query<
|
||||
(Entity, &NpcConversation, &TilePosition, Option<&StableEntityId>),
|
||||
(
|
||||
Entity,
|
||||
&NpcConversation,
|
||||
&TilePosition,
|
||||
Option<&StableEntityId>,
|
||||
),
|
||||
(With<Npc>, With<ActiveSim>, Added<NpcConversation>),
|
||||
>,
|
||||
// Read-only StableEntityId on NPC partner (distinct query, no KG conflict).
|
||||
@@ -267,7 +273,7 @@ pub fn transfer_npc_knowledge(
|
||||
}
|
||||
|
||||
// Sort by most recently updated (deterministic: descending tick, stable by BTreeMap key order)
|
||||
candidates.sort_by(|a, b| b.sort_key().cmp(&a.sort_key()));
|
||||
candidates.sort_by_key(|c| Reverse(c.sort_key()));
|
||||
|
||||
// Take top 1–3 entries by recency (random count, deterministic selection).
|
||||
// The random element is HOW MANY facts transfer, not WHICH ones.
|
||||
@@ -327,13 +333,10 @@ pub fn transfer_npc_knowledge(
|
||||
let capped = ek.confidence.min(KnowledgeConfidence::KnowsOf);
|
||||
|
||||
// Preserve existing relationship state if the partner already knows this entity.
|
||||
let (should_write, existing_relationship) =
|
||||
match partner_kg.entities.get(&id) {
|
||||
None => (true, RelationshipState::Unknown),
|
||||
Some(existing) => {
|
||||
(existing.confidence < capped, existing.relationship)
|
||||
}
|
||||
};
|
||||
let (should_write, existing_relationship) = match partner_kg.entities.get(&id) {
|
||||
None => (true, RelationshipState::Unknown),
|
||||
Some(existing) => (existing.confidence < capped, existing.relationship),
|
||||
};
|
||||
|
||||
if should_write {
|
||||
partner_kg.entities.insert(
|
||||
@@ -438,8 +441,8 @@ mod tests {
|
||||
use crate::simulation::conversation::NpcConversation;
|
||||
use crate::simulation::movement::TilePosition;
|
||||
use crate::simulation::rng::SimRng;
|
||||
use crate::simulation::time::SimulationTime;
|
||||
use crate::simulation::tier::ActiveSim;
|
||||
use crate::simulation::time::SimulationTime;
|
||||
|
||||
fn build_test_world() -> App {
|
||||
let mut app = App::new();
|
||||
@@ -551,12 +554,14 @@ mod tests {
|
||||
}
|
||||
|
||||
// Start conversation — tick 0, so started_tick == 0
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
@@ -599,12 +604,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
@@ -645,12 +652,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
@@ -703,12 +712,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
@@ -750,12 +761,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
@@ -815,12 +828,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut().entity_mut(entity_a).insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
app.world_mut()
|
||||
.entity_mut(entity_a)
|
||||
.insert(NpcConversation {
|
||||
partner: entity_b,
|
||||
started_tick: 0,
|
||||
end_tick: 100,
|
||||
ticks_since_last_line: 0,
|
||||
});
|
||||
|
||||
app.update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user