Better save-compat w.r.t. changes in AC's yaml

This commit is contained in:
Raffson
2024-08-03 16:32:38 +02:00
parent f79e96a474
commit 532515fad7
2 changed files with 10 additions and 12 deletions

View File

@@ -239,6 +239,16 @@ class AircraftType(UnitType[Type[FlyingType]]):
list
)
def __setstate__(self, state: dict[str, Any]) -> None:
# Save compat: the `name` field has been renamed `variant_id`.
if "name" in state:
state["variant_id"] = state.pop("name")
# Update any existing models with new data on load.
updated = AircraftType.named(state["variant_id"])
updated.__dict__.update(state)
self.__dict__.update(updated.__dict__)
def __post_init__(self) -> None:
enrich = {}
if FlightType.SEAD_SWEEP not in self.task_priorities:
@@ -419,16 +429,6 @@ class AircraftType(UnitType[Type[FlyingType]]):
def task_priority(self, task: FlightType) -> int:
return self.task_priorities[task]
def __setstate__(self, state: dict[str, Any]) -> None:
# Save compat: the `name` field has been renamed `variant_id`.
if "name" in state:
state["variant_id"] = state.pop("name")
# Update any existing models with new data on load.
updated = AircraftType.named(state["variant_id"])
state.update(updated.__dict__)
self.__dict__.update(state)
@staticmethod
def _migrator() -> Dict[str, str]:
return {"F-15E Strike Eagle (AI)": "F-15E Strike Eagle"}