Temporary Workaround for weapon save compat

Adds a temporary workaround for save game loading when weapon data got removed and can not be updated anymore.

This can lead to some unexpected behaviour especially when generating the next turn miz as pydcs will most likely crash. This could be solved by just changing the loadout (not tested yet)
This commit is contained in:
RndName 2022-03-20 19:49:58 +01:00
parent 26f3bf5827
commit d23b1fbb2c
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0

View File

@ -52,8 +52,13 @@ class Weapon:
def __setstate__(self, state: dict[str, Any]) -> None:
# Update any existing models with new data on load.
updated = Weapon.with_clsid(state["clsid"])
state.update(updated.__dict__)
try:
updated = Weapon.with_clsid(state["clsid"])
state.update(updated.__dict__)
except KeyError:
logging.exception(
f'CLSID {state["clsid"]} is not available anymore. This could potentially lead to some unexpected results when generating the next turn miz. To solve this issue it is recommended to update the loadout of all affected flights.'
)
self.__dict__.update(state)
@classmethod