Share stable content IDs across raids, inventory and item dispatch (#91)
Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
+61
-14
@@ -2,20 +2,8 @@
|
||||
//! where, how far out and at what; and ready-made raids to start from.
|
||||
use crate::sim::{Aim, Approach, DroneKind, RaidOrder};
|
||||
|
||||
/// The kinds a raid can have, in the menu's order.
|
||||
pub const KINDS: [DroneKind; 11] = [
|
||||
DroneKind::Gerbera,
|
||||
DroneKind::Shahed,
|
||||
DroneKind::Geran3,
|
||||
DroneKind::Lancet,
|
||||
DroneKind::Kh101,
|
||||
DroneKind::Kalibr,
|
||||
DroneKind::Kh22,
|
||||
DroneKind::Zircon,
|
||||
DroneKind::Iskander,
|
||||
DroneKind::Kinzhal,
|
||||
DroneKind::Oreshnik,
|
||||
];
|
||||
/// The historical raid order is owned by the shared content catalog.
|
||||
pub use crate::sim::catalog::RAID_KINDS as KINDS;
|
||||
|
||||
/// What a click on a kind's row steps its number through.
|
||||
const STEPS: [u32; 12] = [0, 1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40];
|
||||
@@ -180,3 +168,62 @@ impl WaveConfig {
|
||||
RaidOrder::mix(n, dist)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod catalog_tests {
|
||||
use super::*;
|
||||
use crate::sim::catalog::{AIRCRAFT, UNITS};
|
||||
|
||||
fn assets() -> std::path::PathBuf {
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets/airdef")
|
||||
}
|
||||
fn item_exists(item: &str) {
|
||||
let name = item.strip_prefix("airdef:").expect("item namespace");
|
||||
for path in [format!("items/{name}.json"), format!("models/item/{name}.json"), format!("textures/item/{name}.png")] {
|
||||
assert!(assets().join(&path).is_file(), "{item}: missing {path}");
|
||||
}
|
||||
let definition = std::fs::read_to_string(assets().join(format!("items/{name}.json"))).unwrap();
|
||||
assert!(definition.contains(&format!("airdef:item/{name}")), "{item}: wrong item model");
|
||||
let model = std::fs::read_to_string(assets().join(format!("models/item/{name}.json"))).unwrap();
|
||||
assert!(model.contains(&format!("airdef:item/{name}")), "{item}: wrong icon reference");
|
||||
let png = std::fs::read(assets().join(format!("textures/item/{name}.png"))).unwrap();
|
||||
assert!(png.starts_with(b"\x89PNG\r\n\x1a\n"), "{item}: invalid PNG signature");
|
||||
}
|
||||
fn model_exists(model: &str) {
|
||||
let name = model.strip_prefix("airdef:").expect("model namespace");
|
||||
let path = assets().join(format!("models/block/{name}.json"));
|
||||
assert!(path.is_file(), "missing model {}", path.display());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn catalog_resources_exist() {
|
||||
for aircraft in AIRCRAFT {
|
||||
model_exists(aircraft.kind.spec().model());
|
||||
if let Some(item) = aircraft.launch_item { item_exists(item); }
|
||||
}
|
||||
for unit in UNITS {
|
||||
item_exists(unit.deploy_item);
|
||||
let p = &unit.kind.spec().parts;
|
||||
model_exists(p.body);
|
||||
for model in [p.launcher, p.pack, p.dish.map(|v| v.0), p.spinner.map(|v| v.0)].into_iter().flatten() { model_exists(model); }
|
||||
for (model, _, _) in p.fixed { model_exists(model); }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inventory_entries_match_catalog_and_scenario_order_round_trips() {
|
||||
for item in AIRCRAFT.iter().filter_map(|a| a.launch_item).chain(UNITS.iter().map(|u| u.deploy_item)) {
|
||||
assert_eq!(crate::ITEMS.iter().filter(|i| **i == item).count(), 1, "{item}");
|
||||
}
|
||||
for item in crate::ITEMS.iter().filter(|i| i.starts_with("airdef:launch_") || i.starts_with("airdef:deploy_")) {
|
||||
assert!(AIRCRAFT.iter().any(|a| a.launch_item == Some(*item)) || UNITS.iter().any(|u| u.deploy_item == *item), "uncatalogued item {item}");
|
||||
}
|
||||
let mut wave = WaveConfig::default();
|
||||
for (i, count) in wave.counts.iter_mut().enumerate() { *count = i as u32; }
|
||||
let text = wave.text();
|
||||
let mut restored = WaveConfig::default();
|
||||
restored.parse(&text.split_whitespace().collect::<Vec<_>>());
|
||||
assert_eq!(restored.counts, wave.counts);
|
||||
assert_eq!(restored.order().kinds, KINDS.iter().copied().zip(wave.counts).filter(|(_, n)| *n > 0).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user