From fab550157a7d5b255792e2320f40257a4f46f722 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 19 Jul 2021 20:07:58 -0700 Subject: [PATCH] Add a per-aircraft weapon linter. Run with `main.py lint-weapons $AIRCRAFT` to show all the weapons the aircraft can carry that do not have data. --- qt_ui/main.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/qt_ui/main.py b/qt_ui/main.py index 28288c43..70d4dd5b 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -13,8 +13,9 @@ from PySide2.QtWidgets import QApplication, QSplashScreen from dcs.payloads import PayloadDirectories from game import Game, VERSION, persistency -from game.data.weapons import WeaponGroup +from game.data.weapons import WeaponGroup, Pylon, Weapon from game.db import FACTIONS +from game.dcs.aircrafttype import AircraftType from game.profiling import logged_duration from game.settings import Settings from game.theater.start_generator import GameGenerator, GeneratorSettings, ModSettings @@ -198,6 +199,9 @@ def parse_args() -> argparse.Namespace: new_game.add_argument("--cheats", action="store_true", help="Enable cheats.") + lint_weapons = subparsers.add_parser("lint-weapons") + lint_weapons.add_argument("aircraft", help="Name of the aircraft variant to lint.") + return parser.parse_args() @@ -267,11 +271,21 @@ def create_game( return game -def lint_weapon_data() -> None: +def lint_all_weapon_data() -> None: for weapon in WeaponGroup.named("Unknown").weapons: logging.warning(f"No weapon data for {weapon}: {weapon.clsid}") +def lint_weapon_data_for_aircraft(aircraft: AircraftType) -> None: + all_weapons: set[Weapon] = set() + for pylon in Pylon.iter_pylons(aircraft): + all_weapons |= pylon.allowed + + for weapon in all_weapons: + if weapon.weapon_group.name == "Unknown": + logging.warning(f'{weapon.clsid} "{weapon.name}" has no weapon data') + + def main(): logging_config.init_logging(VERSION) @@ -283,7 +297,7 @@ def main(): # TODO: Flesh out data and then make unconditional. if args.warn_missing_weapon_data: - lint_weapon_data() + lint_all_weapon_data() if args.subcommand == "new-game": with logged_duration("New game creation"): @@ -298,6 +312,9 @@ def main(): args.date, args.restrict_weapons_by_date, ) + if args.subcommand == "lint-weapons": + lint_weapon_data_for_aircraft(AircraftType.named(args.aircraft)) + return run_ui(game)