Finish AirDef catalog, route, stock and observation fixes
build / mod (push) Successful in 30m46s

Refs #91, #114, #118, #135. Show the latest recorded unit decision in the native card (#153).
This commit is contained in:
2026-12-02 18:22:22 +03:00
parent 9e0cec13f2
commit 7612d15963
38 changed files with 942 additions and 737 deletions
+26 -8
View File
@@ -4,7 +4,7 @@ import argparse
from pathlib import Path
import re
from airdef_assets.catalog import load, load_specs, load_sounds
from airdef_assets.catalog import GROUND_STRIKES, load, load_specs, load_sounds
OUTPUT = Path(__file__).resolve().parents[1] / "airdef-mod/src/sim/catalog_entries.rs"
SPEC_OUTPUT = OUTPUT.with_name("specs_generated.rs")
@@ -20,7 +20,7 @@ SOUND_PREFIX = "sound::"
def generate(data):
lines = ["// Generated by tools/gen_catalog.py from catalog/content.json. Do not edit.",
lines = ["// Generated by tools/gen_catalog.py from catalog/specs.json. Do not edit.",
"pub const AIRCRAFT: &[Aircraft] = &["]
for entry in data["aircraft"]:
kind, item = entry["kind"], entry["item"]
@@ -147,6 +147,7 @@ def drone_profile(entry):
f" clearance: {num(entry['clearance'])},",
f" dive: {num(entry['dive'])},",
f" warhead: {integer(entry['warhead'])},",
f" accuracy: ({num(entry['accuracy'][0])}, {num(entry['accuracy'][1])}),",
f" scale: {num(entry['scale'])},",
f" engine: {motor},",
f" decoy: {str(entry['decoy']).lower()},",
@@ -164,6 +165,7 @@ def missile_profile(entry):
voice = entry["voice"]
lines = [f"const MISSILE_SPEC_{entry['kind'].upper()}: MissileSpec = MissileSpec {{",
f" model: {text(entry['model'])},",
f" launcher_blast: {num(entry['launcher_blast'])},",
f" speed: {num(entry['speed'])},",
f" accel: {num(entry['accel'])},",
f" turn: {num(entry['turn'])},",
@@ -198,10 +200,14 @@ def unit_profile(entry):
gun_expr = (f"Some(GunSpec {{ range: {num(gun['range'])}, track: {num(gun['track'])}, p: {num(gun['p'])}, "
f"bursts: {integer(gun['bursts'])}, shell: {num(gun['shell'])}, "
f"slew: ({num(gun['slew'][0])}, {num(gun['slew'][1])}) }})")
ground = entry.get("ground_strike")
ground_expr = f"Some(catalog::GroundStrike::{GROUND_STRIKES[ground][0]})" if ground is not None else "None"
lines = [f"const UNIT_SPEC_{entry['kind'].upper()}: SamSpec = SamSpec {{",
f" name: {text(entry['name'])},",
f" key: {text(entry['key'])},",
f" village_cost: {integer(entry['village_cost'])},",
f" missile: {missile_expr},",
f" ground_strike: {ground_expr},",
f" gun: {gun_expr},",
f" reload: {integer(entry['reload'])},",
f" scale: {num(entry['scale'])},",
@@ -218,6 +224,11 @@ def unit_profile(entry):
return "\n".join(lines)
def kind_enum(name, entries):
return ["#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]", f"pub enum {name} {{",
*(f" {entry['kind']}," for entry in entries), "}", ""]
def generate_specs(data):
"""The simulation's numeric rows, generated for both the mod and airdef-core."""
shared = data["shared"]
@@ -243,12 +254,15 @@ def generate_specs(data):
f"const TRUCK_LOAD: u32 = {integer(shared['logistics']['truck_load'])};",
f"const STOCK_LIMIT: u32 = {integer(shared['logistics']['stock_limit'])};",
""]
lines += kind_enum("DroneKind", data["drones"])
lines += kind_enum("MissileKind", data["missiles"])
for entry in data["drones"]:
lines += [drone_profile(entry), ""]
for entry in data["missiles"]:
lines += [missile_profile(entry), ""]
lines += ["impl DroneKind {",
" /// Its row of numbers from `catalog/specs.json`.",
lines += ["impl DroneKind {", f" pub const ALL: [DroneKind; {len(data['drones'])}] = ["]
lines += [f" DroneKind::{entry['kind']}," for entry in data["drones"]]
lines += [" ];", "", " /// Its row of numbers from `catalog/specs.json`.",
" pub fn spec(self) -> &'static DroneSpec {",
" match self {"]
for entry in data["drones"]:
@@ -289,10 +303,13 @@ def generate_unit_specs(data):
else:
lines.append(f"const NAMED_{name.upper()}: DVec3 = DVec3::new({', '.join(num(v) for v in value)});")
lines.append("")
lines += kind_enum("SamKind", data["units"])
for entry in data["units"]:
lines += [unit_profile(entry), ""]
lines += ["impl SamKind {",
" /// Its row of numbers from `catalog/specs.json`.",
armed = [entry for entry in data["units"] if entry["gun"] is not None or entry["missile"] is not None]
lines += ["impl SamKind {", f" pub const ARMED: [SamKind; {len(armed)}] = ["]
lines += [f" SamKind::{entry['kind']}," for entry in armed]
lines += [" ];", "", " /// Its row of numbers from `catalog/specs.json`.",
" pub fn spec(self) -> &'static SamSpec {",
" match self {"]
for entry in data["units"]:
@@ -332,11 +349,12 @@ def main():
sound_output = OUTPUT.with_name("catalog_sound_ids.rs")
variant_output = OUTPUT.with_name("unit_variants_generated.rs")
specs = load_specs()
outputs = ((OUTPUT, generate(load())),
content = load(specs)
outputs = ((OUTPUT, generate(content)),
(sound_output, generate_sound_ids(load_sounds())),
(SPEC_OUTPUT, generate_specs(specs)),
(UNIT_SPEC_OUTPUT, generate_unit_specs(specs)),
(variant_output, generate_variants(load())))
(variant_output, generate_variants(content)))
for path, generated in outputs:
if args.check:
if not path.exists() or path.read_text(encoding="utf-8") != generated: