Add debug command to dump aircraft priorities.

https://github.com/dcs-liberation/dcs_liberation/issues/2809
This commit is contained in:
Dan Albert
2023-04-26 20:03:07 -07:00
committed by Raffson
parent 016a9b5762
commit 9ebbe11d83
8 changed files with 69 additions and 16 deletions

View File

@@ -183,7 +183,7 @@ class Campaign:
@classmethod
def iter_campaign_defs(cls) -> Iterator[Path]:
yield from cls.iter_campaigns_in_dir(
Path(persistency.base_path()) / "Retribution/Campaigns"
persistency.base_path() / "Retribution/Campaigns"
)
yield from cls.iter_campaigns_in_dir(Path("resources/campaigns"))

View File

@@ -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
@@ -355,6 +355,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()

View File

@@ -31,7 +31,7 @@ class FactionLoader:
@classmethod
def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]:
user_faction_path = Path(persistency.base_path()) / "Retribution/Factions"
user_faction_path = persistency.base_path() / "Retribution/Factions"
files = cls.find_faction_files_in(
FACTION_DIRECTORY
) + cls.find_faction_files_in(user_faction_path)

View File

@@ -63,7 +63,7 @@ class LayoutLoader:
"""This will load all pre-loaded layouts from a pickle file.
If pickle can not be loaded it will import and dump the layouts"""
# We use a pickle for performance reasons. Importing takes many seconds
file = Path(persistency.base_path()) / LAYOUT_DUMP
file = persistency.base_path() / LAYOUT_DUMP
if file.is_file():
# Load from pickle if existing
with file.open("rb") as f:
@@ -106,7 +106,7 @@ class LayoutLoader:
self._dump_templates()
def _dump_templates(self) -> None:
file = Path(persistency.base_path()) / LAYOUT_DUMP
file = persistency.base_path() / LAYOUT_DUMP
dump = (VERSION, self._layouts)
with file.open("wb") as fdata:
pickle.dump(dump, fdata)

View File

@@ -21,18 +21,18 @@ def setup(user_folder: str) -> None:
save_dir().mkdir(parents=True)
def base_path() -> str:
def base_path() -> Path:
global _dcs_saved_game_folder
assert _dcs_saved_game_folder
return _dcs_saved_game_folder
return Path(_dcs_saved_game_folder)
def settings_dir() -> Path:
return Path(base_path()) / "Retribution" / "Settings"
return base_path() / "Retribution" / "Settings"
def save_dir() -> Path:
return Path(base_path()) / "Retribution" / "Saves"
return base_path() / "Retribution" / "Saves"
def _temporary_save_file() -> str:
@@ -44,7 +44,7 @@ def _autosave_path() -> str:
def mission_path_for(name: str) -> Path:
return Path(base_path()) / "Missions" / name
return base_path() / "Missions" / name
def load_game(path: str) -> Optional[Game]:

View File

@@ -22,7 +22,7 @@ class SquadronDefLoader:
def squadron_directories() -> Iterator[Path]:
from game import persistency
yield Path(persistency.base_path()) / "Retribution/Squadrons"
yield persistency.base_path() / "Retribution/Squadrons"
yield Path("resources/squadrons")
def load(self) -> dict[AircraftType, list[SquadronDef]]: