Fix invalid weapons fallback names

Also add logging to detect invalid fallback names more easily
This commit is contained in:
Raffson 2023-02-25 19:13:12 +01:00
parent 60de35ddf3
commit 9ffaec6d16
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 18 additions and 2 deletions

View File

@ -173,16 +173,21 @@ class WeaponGroup:
@classmethod
def _each_weapon_group(cls) -> Iterator[WeaponGroup]:
names = []
links = []
for group_file_path in Path("resources/weapons").glob("**/*.yaml"):
with group_file_path.open(encoding="utf8") as group_file:
data = yaml.safe_load(group_file)
name = data["name"]
names.append(name)
try:
weapon_type = WeaponType(data["type"])
except KeyError:
weapon_type = WeaponType.UNKNOWN
year = data.get("year")
fallback_name = data.get("fallback")
if fallback_name:
links.append((name, fallback_name))
group = WeaponGroup(name, weapon_type, year, fallback_name)
for clsid in data["clsids"]:
weapon = Weapon(clsid, group)
@ -190,6 +195,17 @@ class WeaponGroup:
group.weapons.append(weapon)
yield group
for name, fb in links:
if fb not in names:
sn = "Unknown"
for n in names:
if fb in n:
sn = n
break
logging.error(
f"Weapon '{name}' has invalid fallback '{fb}': suggested = {sn}"
)
@classmethod
def register_clean_pylon(cls) -> None:
group = WeaponGroup(

View File

@ -1,5 +1,5 @@
name: R-24R
year: 1981
fallback: R-3R
fallback: R-3R - AAM, radar guided
clsids:
- "{CCF898C9-5BC7-49A4-9D1E-C3ED3D5166A1}"

View File

@ -1,6 +1,6 @@
name: 2xGBU-10
type: LGB
year: 1976
fallback: 2xMk 84
fallback: Mk 84
clsids:
- "{62BE78B1-9258-48AE-B882-279534C0D278}"