Separate battery status from player-facing text
Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
//! Player-facing labels for battery configuration snapshots.
|
||||
use crate::sim::battery::{BatteryStatus, RadarRole, SamMode};
|
||||
|
||||
pub fn radar_role_name(role: RadarRole) -> &'static str {
|
||||
match role {
|
||||
RadarRole::Multifunction => "многофункциональная",
|
||||
RadarRole::Search => "обзорная",
|
||||
RadarRole::Engagement => "сопровождения",
|
||||
RadarRole::Height => "мачтовая",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status(status: BatteryStatus) -> String {
|
||||
match status {
|
||||
BatteryStatus::Radar { index, role, emitting, operational } => format!(
|
||||
"№{} РЛС: {}, излучение {}, {}", index + 1, radar_role_name(role),
|
||||
if emitting { "вкл" } else { "выкл" },
|
||||
if operational { "работает" } else { "нет связи или РЛС не работает" }
|
||||
),
|
||||
BatteryStatus::Launcher { index, kind, mode, linked } => format!(
|
||||
"№{} {}: {}{}", index + 1, kind.name(), mode.key(),
|
||||
if mode == SamMode::LauncherOnly {
|
||||
if linked { ", РЛС связана" } else { ", нет связанной РЛС сопровождения" }
|
||||
} else { "" }
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sim::SamKind;
|
||||
|
||||
#[test]
|
||||
fn renders_battery_status_in_existing_format() {
|
||||
assert_eq!(status(BatteryStatus::Radar { index: 0, role: RadarRole::Search, emitting: false, operational: false }), "№1 РЛС: обзорная, излучение выкл, нет связи или РЛС не работает");
|
||||
assert_eq!(status(BatteryStatus::Radar { index: 1, role: RadarRole::Engagement, emitting: true, operational: true }), "№2 РЛС: сопровождения, излучение вкл, работает");
|
||||
assert_eq!(status(BatteryStatus::Launcher { index: 2, kind: SamKind::S400, mode: SamMode::LauncherOnly, linked: true }), "№3 С-400: launcher, РЛС связана");
|
||||
assert_eq!(status(BatteryStatus::Launcher { index: 3, kind: SamKind::S500, mode: SamMode::LauncherOnly, linked: false }), "№4 С-500: launcher, нет связанной РЛС сопровождения");
|
||||
assert_eq!(status(BatteryStatus::Launcher { index: 4, kind: SamKind::S400, mode: SamMode::Integrated, linked: false }), "№5 С-400: integrated");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user