Catalog typed battery variants (#91)
The battery deploy pieces (s400_launcher, s500_launcher, radar_search/ track/height) were described three times: the menu table and the configuration match in lib.rs, and a chained id list in commands.rs. One catalog decision instead: catalog/content.json gains a variants section (mode/role reuse the existing SamMode/RadarRole save keys), gen_catalog.py generates catalog::UnitVariant rows, and the loader rejects duplicates, unknown kinds/modes and id collisions with kinds or items. The battery menu, its click handler and the deploy completion read the generated table; the historical row order and labels are unchanged. No variant carries its own balance: per-variant ammo profiles stay open pending a confirmed profile and an explicitly labelled game abstraction (PAC-3 note on #91), so no new specs, no new matches and no save/replay change - a variant is only a deploy key over the same kind. Checks: gen_catalog.py --check and gen_models.py --check clean, the python catalog/asset and sound tests pass, airdef-core 234 unit + 8 scenarios, airdef-mod 69 unit + 1 boundary + 5 scenarios (save/load and state round trips included), zero failures. Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -14,7 +14,7 @@ fn on_off() -> Value {
|
||||
/// `/airdef ...` as `lib.rs` accepts it.
|
||||
pub fn tree() -> Tree {
|
||||
let wave_kinds: Vec<&str> = DroneKind::ALL.iter().map(|k| k.spec().key).chain(["mix"]).collect();
|
||||
let deploy_kinds: Vec<&str> = SamKind::ALL.iter().map(|k| k.key()).chain(["s400_launcher", "s500_launcher", "radar_search", "radar_track", "radar_height"]).collect();
|
||||
let deploy_kinds: Vec<&str> = SamKind::ALL.iter().map(|k| k.key()).chain(crate::sim::catalog::VARIANTS.iter().map(|v| v.id)).collect();
|
||||
let armed: Vec<&str> = SamKind::ARMED.iter().map(|k| k.key()).chain(["all"]).collect();
|
||||
let toggle = |word: &str| Node::lit(word).then(Node::arg("on/off", on_off()).runs());
|
||||
Tree::new("airdef").runs().with([
|
||||
|
||||
+14
-21
@@ -206,27 +206,19 @@ enum Page {
|
||||
}
|
||||
|
||||
const MENU_KINDS: u32 = 1;
|
||||
const BATTERY_ROWS: u32 = 5;
|
||||
const BTN_BATTERY: u32 = 22;
|
||||
const BATTERY_DEPLOY: [(&str, &str); 5] = [
|
||||
("s400_launcher", "С-400 — отдельная пусковая"),
|
||||
("s500_launcher", "С-500 — отдельная пусковая"),
|
||||
("radar_search", "РЛС обзора"),
|
||||
("radar_track", "РЛС сопровождения"),
|
||||
("radar_height", "Мачтовая РЛС"),
|
||||
];
|
||||
const BATTERY_ROWS: u32 = sim::catalog::VARIANTS.len() as u32;
|
||||
|
||||
/// A battery deploy piece from the catalog: a unit kind or one of its variants.
|
||||
fn deploy_configuration(key: &str) -> Option<(SamKind, sim::battery::SamMode, sim::battery::RadarRole)> {
|
||||
use sim::battery::{RadarRole as R, SamMode as M};
|
||||
Some(match key {
|
||||
"s400_launcher" => (SamKind::S400, M::LauncherOnly, R::Multifunction),
|
||||
"s500_launcher" => (SamKind::S500, M::LauncherOnly, R::Multifunction),
|
||||
"radar_search" => (SamKind::Radar, M::Integrated, R::Search),
|
||||
"radar_track" => (SamKind::Radar, M::Integrated, R::Engagement),
|
||||
"radar_height" => (SamKind::Radar, M::Integrated, R::Height),
|
||||
_ => (SamKind::from_key(key)?, M::Integrated, R::Multifunction),
|
||||
})
|
||||
match sim::catalog::variant(key) {
|
||||
Some(v) => Some((v.kind, v.mode, v.role)),
|
||||
// A bare kind deploys its ordinary integrated configuration.
|
||||
None => Some((SamKind::from_key(key)?, M::Integrated, R::Multifunction)),
|
||||
}
|
||||
}
|
||||
|
||||
const BTN_HOLD: u32 = 10;
|
||||
const BTN_SHADER: u32 = 11;
|
||||
const BTN_DAMAGE: u32 = 12;
|
||||
@@ -1590,7 +1582,7 @@ impl AirDef {
|
||||
}
|
||||
Page::BatteryDeploy => {
|
||||
title = "Размещение батареи — клик создаёт технику перед игроком".into();
|
||||
widgets.push(Widget::List(ListWidget { id: BATTERY_ROWS, rows: BATTERY_DEPLOY.iter().map(|(_, name)| (*name).to_string()).collect(), selected: None }));
|
||||
widgets.push(Widget::List(ListWidget { id: BATTERY_ROWS, rows: sim::catalog::VARIANTS.iter().map(|v| v.label.to_string()).collect(), selected: None }));
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_BACK, label: "← Назад".into() }));
|
||||
}
|
||||
Page::Replays => {
|
||||
@@ -2116,8 +2108,8 @@ impl Mod for AirDef {
|
||||
return;
|
||||
}
|
||||
(Page::BatteryDeploy, BATTERY_ROWS) => {
|
||||
if let Some((key, _)) = BATTERY_DEPLOY.get(row as usize) {
|
||||
match self.deploy_configured(key) {
|
||||
if let Some(v) = sim::catalog::VARIANTS.get(row as usize) {
|
||||
match self.deploy_configured(v.id) {
|
||||
Ok(message) => say(&message),
|
||||
Err(error) => say(&error),
|
||||
}
|
||||
@@ -2621,8 +2613,9 @@ mod tests {
|
||||
assert_eq!(sim::catalog::UNITS[3].kind, SamKind::S400);
|
||||
assert_eq!(sim::catalog::UNITS[4].kind, SamKind::S500);
|
||||
assert_eq!(sim::catalog::UNITS[10].kind, SamKind::Radar);
|
||||
for (key, _) in BATTERY_DEPLOY {
|
||||
assert!(deploy_configuration(key).is_some());
|
||||
for v in sim::catalog::VARIANTS {
|
||||
let (actual, mode, role) = deploy_configuration(v.id).unwrap();
|
||||
assert_eq!((actual, mode, role), (v.kind, v.mode, v.role));
|
||||
}
|
||||
for kind in SamKind::ALL {
|
||||
let (actual, mode, role) = deploy_configuration(kind.key()).unwrap();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! Balance and rendering remain in `DroneSpec` and `SamSpec`: the catalog
|
||||
//! refers to those typed definitions instead of copying their values. The
|
||||
//! first eleven drone entries retain the historical positional wave-save order.
|
||||
use super::{DroneKind, SamKind};
|
||||
use super::{battery::RadarRole, battery::SamMode, DroneKind, SamKind};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Aircraft {
|
||||
@@ -19,6 +19,19 @@ impl Aircraft {
|
||||
pub fn id(self) -> &'static str { self.kind.spec().key }
|
||||
}
|
||||
|
||||
/// A variant of a complex: a configuration over an existing kind, deployed
|
||||
/// under its own command/menu id. Not new balance.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct UnitVariant {
|
||||
/// Existing command/menu key; changing it requires an explicit migration.
|
||||
pub id: &'static str,
|
||||
pub kind: SamKind,
|
||||
pub mode: SamMode,
|
||||
pub role: RadarRole,
|
||||
/// The deploy menu's row.
|
||||
pub label: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum GroundStrike {
|
||||
/// Game-only RM48U coordinate-strike profile for S-400. Evidence: official agency report,
|
||||
@@ -59,6 +72,7 @@ pub mod sound {
|
||||
|
||||
// Generated entries keep the historical raid and unit ordering.
|
||||
include!("catalog_entries.rs");
|
||||
include!("unit_variants_generated.rs");
|
||||
|
||||
/// Existing positional serialization makes the first entries' order part of the save format.
|
||||
const fn raid_count() -> usize {
|
||||
@@ -132,6 +146,10 @@ pub fn deploy_item(id: &str) -> Option<SamKind> {
|
||||
UNITS.iter().find(|entry| entry.deploy_item == id).map(|entry| entry.kind)
|
||||
}
|
||||
|
||||
pub fn variant(id: &str) -> Option<&'static UnitVariant> {
|
||||
VARIANTS.iter().find(|variant| variant.id == id)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -173,6 +191,26 @@ mod tests {
|
||||
assert_eq!(&RAID_KINDS[..11], &[Gerbera, Shahed, Geran3, Lancet, Kh101, Kalibr, Kh22, Zircon, Iskander, Kinzhal, Oreshnik]);
|
||||
}
|
||||
|
||||
/// A variant is a configuration of an existing kind, one row in the catalog,
|
||||
/// under an id that stays out of the other identities' keys; the battery-menu
|
||||
/// order is part of the UI's tested behaviour.
|
||||
#[test]
|
||||
fn variants_configure_existing_units_under_free_ids() {
|
||||
let ids: Vec<&str> = VARIANTS.iter().map(|v| v.id).collect();
|
||||
assert_eq!(ids, ["s400_launcher", "s500_launcher", "radar_search", "radar_track", "radar_height"]);
|
||||
for v in VARIANTS {
|
||||
assert!(UNITS.iter().any(|unit| unit.kind == v.kind), "{} configures an unknown kind", v.id);
|
||||
assert!(SamKind::from_key(v.id).is_none(), "{} shadows a unit kind", v.id);
|
||||
assert!(!INVENTORY.contains(&format!("airdef:{}", v.id).as_str()), "{} doubles an item", v.id);
|
||||
assert!(!v.label.is_empty());
|
||||
assert_eq!(variant(v.id).map(|u| (u.kind, u.mode, u.role)), Some((v.kind, v.mode, v.role)));
|
||||
}
|
||||
let launcher = variant("s400_launcher").unwrap();
|
||||
assert_eq!((launcher.kind, launcher.mode, launcher.role), (SamKind::S400, SamMode::LauncherOnly, RadarRole::Multifunction));
|
||||
assert_eq!(VARIANTS[4].id, "radar_height");
|
||||
assert!(variant("miss").is_none() && variant("s400").is_none());
|
||||
}
|
||||
|
||||
/// The catalog is the only copy of the numbers: a kind without a row, or a row under
|
||||
/// another kind, would be a silent balance change.
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Generated by tools/gen_catalog.py from catalog/content.json. Do not edit.
|
||||
pub const VARIANTS: &[UnitVariant] = &[
|
||||
UnitVariant { id: "s400_launcher", kind: SamKind::S400, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-400 — отдельная пусковая" },
|
||||
UnitVariant { id: "s500_launcher", kind: SamKind::S500, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-500 — отдельная пусковая" },
|
||||
UnitVariant { id: "radar_search", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Search, label: "РЛС обзора" },
|
||||
UnitVariant { id: "radar_track", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Engagement, label: "РЛС сопровождения" },
|
||||
UnitVariant { id: "radar_height", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Height, label: "Мачтовая РЛС" },
|
||||
];
|
||||
Reference in New Issue
Block a user