Show live Horizon terrain and radar views in the web panel
This commit is contained in:
@@ -57,6 +57,23 @@ fn configs() -> Value {
|
||||
})
|
||||
}
|
||||
|
||||
fn class_symbol(class: sim::Class) -> &'static str {
|
||||
match class {
|
||||
sim::Class::Drone => "drone",
|
||||
sim::Class::Jet => "jet",
|
||||
sim::Class::Cruise => "cruise",
|
||||
sim::Class::Supersonic => "supersonic",
|
||||
sim::Class::Ballistic => "ballistic",
|
||||
}
|
||||
}
|
||||
|
||||
fn contact_symbol(estimate: sim::ClassEst) -> &'static str {
|
||||
match estimate {
|
||||
sim::ClassEst::Firm(class) => class_symbol(class),
|
||||
_ => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn public_live(sim: &sim::Sim) -> Value {
|
||||
let now = sim.tick;
|
||||
let picture = sim.air_picture();
|
||||
@@ -69,6 +86,7 @@ fn public_live(sim: &sim::Sim) -> Value {
|
||||
"status": if t.forecast(now) { "Оценка положения" } else { "Измерено" },
|
||||
"source": (t.source != 0).then_some(t.source), "age": t.age(now),
|
||||
"quality": t.quality, "confidence": t.ident().name(), "radius": t.uncertainty(now),
|
||||
"symbol": contact_symbol(t.class),
|
||||
"vx": t.vel.x * 20.0, "vz": t.vel.z * 20.0,
|
||||
}));
|
||||
row
|
||||
@@ -80,11 +98,15 @@ fn public_live(sim: &sim::Sim) -> Value {
|
||||
.enumerate()
|
||||
.map(|(i, s)| {
|
||||
let mut row = position(s.id, format!("№{} {}", i + 1, s.kind.name()), s.pos);
|
||||
let emitting = s.radar_up();
|
||||
let radar_range = emitting.then(|| s.kind.spec().sensor * s.radar_profile().reach);
|
||||
merge(
|
||||
&mut row,
|
||||
json!({
|
||||
"status": post::state(s), "details": battery_view::sam_status(s, now),
|
||||
"health": s.health, "rounds": s.missiles, "bursts": s.bursts,
|
||||
"symbol": if s.kind == sim::SamKind::Radar { "radar" } else { "unit" },
|
||||
"radarRange": radar_range,
|
||||
"target": s.target.or(s.gun_target).filter(|id| known.contains(id)),
|
||||
}),
|
||||
);
|
||||
@@ -145,7 +167,7 @@ fn perspectives(sim: &sim::Sim, debug: bool) -> (Value, Value) {
|
||||
let mut row = position(d.id, d.kind.spec().name, d.pos);
|
||||
merge(
|
||||
&mut row,
|
||||
json!({"status": "Истина", "vx": d.vel.x * 20.0, "vz": d.vel.z * 20.0}),
|
||||
json!({"status": "Истина", "symbol": class_symbol(d.kind.spec().class), "vx": d.vel.x * 20.0, "vz": d.vel.z * 20.0}),
|
||||
);
|
||||
row
|
||||
})
|
||||
@@ -302,9 +324,7 @@ impl AirDef {
|
||||
["snapshot", nonce, privacy, raw]
|
||||
if token(nonce) && matches!(*privacy, "public" | "debug") =>
|
||||
{
|
||||
if self.world.is_none() || player().is_none() {
|
||||
return Err("Откройте игровой мир".into());
|
||||
}
|
||||
let player = player().filter(|_| self.world.is_some()).ok_or("Откройте игровой мир")?;
|
||||
if self.web.session.is_empty() {
|
||||
self.web.session = nonce.to_string();
|
||||
}
|
||||
@@ -324,7 +344,8 @@ impl AirDef {
|
||||
})
|
||||
});
|
||||
let content = json!({
|
||||
"version": 1, "nonce": nonce, "session": session, "world": self.state_key(), "tick": self.sim.tick,
|
||||
"version": 1, "nonce": nonce, "session": session, "world": self.state_key(), "terrainWorld": self.world, "tick": self.sim.tick,
|
||||
"terrainDimension": player.dimension, "mapCenter": [player.x, player.z],
|
||||
"live": public_live(&self.sim), "enemy": enemy, "truth": truth, "raids": raids, "catalog": configs(),
|
||||
"selected": selected, "canLaunch": !self.sim.planning() && !self.village_active() && self.presentation.is_live(),
|
||||
});
|
||||
@@ -402,6 +423,17 @@ mod tests {
|
||||
assert!(perspectives(&sim, false).1.is_null());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contact_symbol_requires_a_confirmed_class() {
|
||||
use sim::{Class, ClassEst};
|
||||
|
||||
assert_eq!(contact_symbol(ClassEst::Unknown), "unknown");
|
||||
assert_eq!(contact_symbol(ClassEst::Probable(Class::Cruise)), "unknown");
|
||||
assert_eq!(contact_symbol(ClassEst::Firm(Class::Drone)), "drone");
|
||||
assert_eq!(contact_symbol(ClassEst::Firm(Class::Cruise)), "cruise");
|
||||
assert_eq!(contact_symbol(ClassEst::Firm(Class::Ballistic)), "ballistic");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_wave_as_data_and_resets_cursors_between_game_sessions() {
|
||||
let mut counts = vec!["0"; wave::KINDS.len()];
|
||||
|
||||
Reference in New Issue
Block a user