mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Add debug command to dump aircraft priorities.
https://github.com/dcs-liberation/dcs_liberation/issues/2809
This commit is contained in:
parent
6df83485e1
commit
b69def652e
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property
|
||||
from functools import cache, cached_property
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar, Dict, Iterator, Optional, TYPE_CHECKING, Type
|
||||
|
||||
@ -350,6 +350,15 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
||||
cls._load_all()
|
||||
yield from cls._by_name.values()
|
||||
|
||||
@classmethod
|
||||
@cache
|
||||
def priority_list_for_task(cls, task: FlightType) -> list[AircraftType]:
|
||||
capable = []
|
||||
for aircraft in cls.iter_all():
|
||||
if aircraft.capable_of(task):
|
||||
capable.append(aircraft)
|
||||
return list(reversed(sorted(capable, key=lambda a: a.task_priority(task))))
|
||||
|
||||
@staticmethod
|
||||
def each_dcs_type() -> Iterator[Type[FlyingType]]:
|
||||
yield from helicopter_map.values()
|
||||
|
||||
@ -7,6 +7,7 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import yaml
|
||||
from PySide6 import QtWidgets
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QPixmap
|
||||
@ -14,10 +15,12 @@ from PySide6.QtWidgets import QApplication, QCheckBox, QSplashScreen
|
||||
from dcs.payloads import PayloadDirectories
|
||||
|
||||
from game import Game, VERSION, logging_config, persistence
|
||||
from game.ato import FlightType
|
||||
from game.campaignloader.campaign import Campaign, DEFAULT_BUDGET
|
||||
from game.data.weapons import Pylon, Weapon, WeaponGroup
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from game.factions.factions import Factions
|
||||
from game.persistence.paths import liberation_user_dir
|
||||
from game.profiling import logged_duration
|
||||
from game.server import EventStream, Server
|
||||
from game.settings import Settings
|
||||
@ -243,6 +246,8 @@ def parse_args() -> argparse.Namespace:
|
||||
lint_weapons = subparsers.add_parser("lint-weapons")
|
||||
lint_weapons.add_argument("aircraft", help="Name of the aircraft variant to lint.")
|
||||
|
||||
subparsers.add_parser("dump-task-priorities")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -352,6 +357,27 @@ def fix_pycharm_debugger_if_needed() -> None:
|
||||
ntpath.sep = "\\"
|
||||
|
||||
|
||||
def dump_task_priorities() -> None:
|
||||
first_start = liberation_install.init()
|
||||
if first_start:
|
||||
sys.exit(
|
||||
"Cannot dump task priorities without configuring DCS Liberation. Start the"
|
||||
"UI for the first run configuration."
|
||||
)
|
||||
|
||||
data: dict[str, dict[str, int]] = {}
|
||||
for task in FlightType:
|
||||
data[task.value] = {
|
||||
a.name: a.task_priority(task)
|
||||
for a in AircraftType.priority_list_for_task(task)
|
||||
}
|
||||
|
||||
debug_path = liberation_user_dir() / "Debug" / "priorities.yaml"
|
||||
debug_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with debug_path.open("w", encoding="utf-8") as output:
|
||||
yaml.dump(data, output, sort_keys=False, allow_unicode=True)
|
||||
|
||||
|
||||
def main():
|
||||
logging_config.init_logging(VERSION)
|
||||
|
||||
@ -391,6 +417,9 @@ def main():
|
||||
if args.subcommand == "lint-weapons":
|
||||
lint_weapon_data_for_aircraft(AircraftType.named(args.aircraft))
|
||||
return
|
||||
if args.subcommand == "dump-task-priorities":
|
||||
dump_task_priorities()
|
||||
return
|
||||
|
||||
with Server().run_in_thread():
|
||||
run_ui(game, UiFlags(args.dev, args.show_sim_speed_controls))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user