Move world cache report to presentation adapter
Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -30,6 +30,7 @@ mod smoke;
|
||||
pub use airdef_core::sim;
|
||||
mod scenario;
|
||||
mod wave;
|
||||
mod world_view;
|
||||
use sim::{Class, DroneKind, Ground, Out, Sam, SamKind, Sim};
|
||||
|
||||
const ITEMS: [&str; sim::catalog::INVENTORY_COUNT] = sim::catalog::INVENTORY;
|
||||
@@ -2546,7 +2547,7 @@ impl Mod for AirDef {
|
||||
self.sim.strikes.stunned,
|
||||
self.sim.strikes.missed,
|
||||
self.sim.strikes.shot_down,
|
||||
self.ground.world.text()
|
||||
world_view::text(&self.ground.world)
|
||||
)),
|
||||
_ => return Err(help()),
|
||||
};
|
||||
|
||||
@@ -238,27 +238,6 @@ impl WorldCache {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.secs.is_empty()
|
||||
}
|
||||
/// One line for the report.
|
||||
pub fn text(&self) -> String {
|
||||
let s = &self.stats;
|
||||
format!(
|
||||
"мир: {} секций ({} КБ), запросов {}, неизвестно {}, лучей {} (ударов {}, неизв. {}), клеток {}; взрывы в блоках: {} (подтверждено {}, без перемен {}, нет чанка {}), чужих ответов {}",
|
||||
self.len(),
|
||||
self.bytes() / 1024,
|
||||
s.sections_asked,
|
||||
s.sections_unknown,
|
||||
s.sweeps,
|
||||
s.hits,
|
||||
s.unknown_sweeps,
|
||||
s.cells,
|
||||
s.blasts_asked,
|
||||
s.blasts_confirmed,
|
||||
s.blasts_unchanged,
|
||||
s.blasts_unloaded,
|
||||
s.late_dropped
|
||||
)
|
||||
}
|
||||
|
||||
/// The game's note of changes: another world voids everything; changed
|
||||
/// sections (or too many to say) are read again when next used.
|
||||
pub fn changed(&mut self, epoch: u32, overflow: bool, sections: &[Sec]) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//! Player-facing world-cache report, also used by the headless scenario driver.
|
||||
use airdef_core::sim::world::WorldCache;
|
||||
|
||||
pub fn text(world: &WorldCache) -> String {
|
||||
let s = &world.stats;
|
||||
format!(
|
||||
"мир: {} секций ({} КБ), запросов {}, неизвестно {}, лучей {} (ударов {}, неизв. {}), клеток {}; взрывы в блоках: {} (подтверждено {}, без перемен {}, нет чанка {}), чужих ответов {}",
|
||||
world.len(), world.bytes() / 1024, s.sections_asked, s.sections_unknown,
|
||||
s.sweeps, s.hits, s.unknown_sweeps, s.cells, s.blasts_asked,
|
||||
s.blasts_confirmed, s.blasts_unchanged, s.blasts_unloaded, s.late_dropped
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn reports_cache_counts_in_existing_format() {
|
||||
let mut world = WorldCache::default();
|
||||
world.stats.sections_asked = 1;
|
||||
world.stats.sections_unknown = 2;
|
||||
world.stats.sweeps = 3;
|
||||
world.stats.hits = 4;
|
||||
world.stats.unknown_sweeps = 5;
|
||||
world.stats.cells = 6;
|
||||
world.stats.blasts_asked = 7;
|
||||
world.stats.blasts_confirmed = 8;
|
||||
world.stats.blasts_unchanged = 9;
|
||||
world.stats.blasts_unloaded = 10;
|
||||
world.stats.late_dropped = 11;
|
||||
assert_eq!(text(&world), "мир: 0 секций (0 КБ), запросов 1, неизвестно 2, лучей 3 (ударов 4, неизв. 5), клеток 6; взрывы в блоках: 7 (подтверждено 8, без перемен 9, нет чанка 10), чужих ответов 11");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user