Weapons data migration (changing names)

This commit is contained in:
Raffson 2023-02-18 18:41:13 +01:00
parent 80a7d7da2d
commit bb629a7be2
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
5 changed files with 17 additions and 5 deletions

View File

@ -19,6 +19,18 @@ PydcsWeapon = Any
PydcsWeaponAssignment = tuple[int, PydcsWeapon] PydcsWeaponAssignment = tuple[int, PydcsWeapon]
def weapons_migrator(name: str) -> str:
migration_map = {
"AGM-88C HARM - High Speed Anti-Radiation Missile": "AGM-88C HARM",
"Kh-25MPU (Updated AS-12 Kegler) - 320kg, ARM, IN & Pas Rdr": "Kh-25MPU",
"Kh-31P (AS-17 Krypton) - 600kg, ARM, IN & Pas Rdr": "Kh-31P",
"Kh-58U (AS-11 Kilter) - 640kg, ARM, IN & Pas Rdr": "Kh-58U",
}
while name in migration_map:
name = migration_map[name]
return name
@dataclass(frozen=True) @dataclass(frozen=True)
class Weapon: class Weapon:
"""Wrapper for DCS weapons.""" """Wrapper for DCS weapons."""
@ -139,7 +151,7 @@ class WeaponGroup:
def __setstate__(self, state: dict[str, Any]) -> None: def __setstate__(self, state: dict[str, Any]) -> None:
# Update any existing models with new data on load. # Update any existing models with new data on load.
updated = WeaponGroup.named(state["name"]) updated = WeaponGroup.named(weapons_migrator(state["name"]))
state.update(updated.__dict__) state.update(updated.__dict__)
self.__dict__.update(state) self.__dict__.update(state)

View File

@ -1,4 +1,4 @@
name: AGM-88C HARM - High Speed Anti-Radiation Missile name: AGM-88C HARM
type: ARM type: ARM
# https://www.af.mil/About-Us/Fact-Sheets/Display/Article/104574/agm-88-harm/ # https://www.af.mil/About-Us/Fact-Sheets/Display/Article/104574/agm-88-harm/
# 1984 is the date for the A variant but as we do not have that one we use it for C # 1984 is the date for the A variant but as we do not have that one we use it for C

View File

@ -1,4 +1,4 @@
name: Kh-25MPU (Updated AS-12 Kegler) - 320kg, ARM, IN & Pas Rdr name: Kh-25MPU
type: ARM type: ARM
clsids: clsids:
- "{E86C5AA5-6D49-4F00-AD2E-79A62D6DDE26}" - "{E86C5AA5-6D49-4F00-AD2E-79A62D6DDE26}"

View File

@ -1,4 +1,4 @@
name: Kh-31P (AS-17 Krypton) - 600kg, ARM, IN & Pas Rdr name: Kh-31P
type: ARM type: ARM
clsids: clsids:
- "{D8F2C90B-887B-4B9E-9FE2-996BC9E9AF03}" - "{D8F2C90B-887B-4B9E-9FE2-996BC9E9AF03}"

View File

@ -1,4 +1,4 @@
name: Kh-58U (AS-11 Kilter) - 640kg, ARM, IN & Pas Rdr name: Kh-58U
type: ARM type: ARM
clsids: clsids:
- "{FE382A68-8620-4AC0-BDF5-709BFE3977D7}" - "{FE382A68-8620-4AC0-BDF5-709BFE3977D7}"