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
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import cached_property
|
from functools import cache, cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, ClassVar, Dict, Iterator, Optional, TYPE_CHECKING, Type
|
from typing import Any, ClassVar, Dict, Iterator, Optional, TYPE_CHECKING, Type
|
||||||
|
|
||||||
@ -350,6 +350,15 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
cls._load_all()
|
cls._load_all()
|
||||||
yield from cls._by_name.values()
|
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
|
@staticmethod
|
||||||
def each_dcs_type() -> Iterator[Type[FlyingType]]:
|
def each_dcs_type() -> Iterator[Type[FlyingType]]:
|
||||||
yield from helicopter_map.values()
|
yield from helicopter_map.values()
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import yaml
|
||||||
from PySide6 import QtWidgets
|
from PySide6 import QtWidgets
|
||||||
from PySide6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
from PySide6.QtGui import QPixmap
|
from PySide6.QtGui import QPixmap
|
||||||
@ -14,10 +15,12 @@ from PySide6.QtWidgets import QApplication, QCheckBox, QSplashScreen
|
|||||||
from dcs.payloads import PayloadDirectories
|
from dcs.payloads import PayloadDirectories
|
||||||
|
|
||||||
from game import Game, VERSION, logging_config, persistence
|
from game import Game, VERSION, logging_config, persistence
|
||||||
|
from game.ato import FlightType
|
||||||
from game.campaignloader.campaign import Campaign, DEFAULT_BUDGET
|
from game.campaignloader.campaign import Campaign, DEFAULT_BUDGET
|
||||||
from game.data.weapons import Pylon, Weapon, WeaponGroup
|
from game.data.weapons import Pylon, Weapon, WeaponGroup
|
||||||
from game.dcs.aircrafttype import AircraftType
|
from game.dcs.aircrafttype import AircraftType
|
||||||
from game.factions.factions import Factions
|
from game.factions.factions import Factions
|
||||||
|
from game.persistence.paths import liberation_user_dir
|
||||||
from game.profiling import logged_duration
|
from game.profiling import logged_duration
|
||||||
from game.server import EventStream, Server
|
from game.server import EventStream, Server
|
||||||
from game.settings import Settings
|
from game.settings import Settings
|
||||||
@ -243,6 +246,8 @@ def parse_args() -> argparse.Namespace:
|
|||||||
lint_weapons = subparsers.add_parser("lint-weapons")
|
lint_weapons = subparsers.add_parser("lint-weapons")
|
||||||
lint_weapons.add_argument("aircraft", help="Name of the aircraft variant to lint.")
|
lint_weapons.add_argument("aircraft", help="Name of the aircraft variant to lint.")
|
||||||
|
|
||||||
|
subparsers.add_parser("dump-task-priorities")
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -352,6 +357,27 @@ def fix_pycharm_debugger_if_needed() -> None:
|
|||||||
ntpath.sep = "\\"
|
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():
|
def main():
|
||||||
logging_config.init_logging(VERSION)
|
logging_config.init_logging(VERSION)
|
||||||
|
|
||||||
@ -391,6 +417,9 @@ def main():
|
|||||||
if args.subcommand == "lint-weapons":
|
if args.subcommand == "lint-weapons":
|
||||||
lint_weapon_data_for_aircraft(AircraftType.named(args.aircraft))
|
lint_weapon_data_for_aircraft(AircraftType.named(args.aircraft))
|
||||||
return
|
return
|
||||||
|
if args.subcommand == "dump-task-priorities":
|
||||||
|
dump_task_priorities()
|
||||||
|
return
|
||||||
|
|
||||||
with Server().run_in_thread():
|
with Server().run_in_thread():
|
||||||
run_ui(game, UiFlags(args.dev, args.show_sim_speed_controls))
|
run_ui(game, UiFlags(args.dev, args.show_sim_speed_controls))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user