Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make payload directory loading lazy. #298

Merged
merged 1 commit into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions dcs/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,33 @@ def _find_mod_payload_paths() -> List[Path]:

class PayloadDirectories:
fallback: Optional[Path] = None
dcs: List[Path] = _find_dcs_payload_paths()
mod: List[Path] = _find_mod_payload_paths()
user: Path = (
Path(installation.get_dcs_saved_games_directory()) / "MissionEditor" / "UnitPayloads"
)
_dcs: Optional[List[Path]] = None
_mod: Optional[List[Path]] = None
_user: Optional[Path] = None
preferred: Optional[Path] = None

@classmethod
def dcs(cls) -> List[Path]:
if cls._dcs is None:
cls._dcs = _find_dcs_payload_paths()
return cls._dcs

@classmethod
def mod(cls) -> List[Path]:
if cls._mod is None:
cls._mod = _find_mod_payload_paths()
return cls._mod

@classmethod
def user(cls) -> Path:
if cls._user is None:
cls._user = (
Path(installation.get_dcs_saved_games_directory())
/ "MissionEditor"
/ "UnitPayloads"
)
return cls._user

@classmethod
def set_fallback(cls, path: Path) -> None:
cls.fallback = path
Expand All @@ -56,8 +76,8 @@ def payload_dirs(cls) -> Iterator[Path]:
# These are iterated in order of decreasing order of preference.
if cls.preferred is not None:
yield cls.preferred
yield cls.user
yield from cls.dcs
yield from cls.mod
yield cls.user()
yield from cls.dcs()
yield from cls.mod()
if cls.fallback:
yield cls.fallback