Export airfield data to yaml, switch to ID keys.

This exports all the old AIRFIELD_DATA to yaml files. It's easier for
users to send fixes if it's defined this way, and they can also fix it
in their install without having to wait for a new release.

This also switches the indexes from the unstable DCS airfield names to
airfield IDs, so this fixes another case of DCS updates occasionally
breaking Liberation.

I also ended up finding quite a few typos in airfield names, and
incorrect theater names in the process. Those have been fixed.
This commit is contained in:
Dan Albert
2022-02-11 01:35:03 -08:00
parent 079f19a66e
commit 011d8a4e12
181 changed files with 2673 additions and 1547 deletions

View File

@@ -1,6 +1,9 @@
"""Radio frequency types and allocators."""
from __future__ import annotations
import itertools
import logging
import re
from dataclasses import dataclass
from typing import Dict, FrozenSet, Iterator, List, Set, Tuple
@@ -35,13 +38,37 @@ class RadioFrequency:
"""
return self.hertz / 1000000
@classmethod
def parse(cls, text: str) -> RadioFrequency:
match = re.match(r"""^(\d+)(?:\.(\d{1,3}))? (MHz|kHz)$""", text)
if match is None:
raise ValueError(f"Could not parse radio frequency from {text}")
whole = int(match.group(1))
partial_str = match.group(2)
units = match.group(3)
partial = 0
if partial_str is not None:
partial = int(partial_str)
if len(partial_str) == 1:
partial *= 100
elif len(partial_str) == 2:
partial *= 10
if units == "MHz":
return MHz(whole, partial)
if units == "kHz":
return kHz(whole, partial)
raise ValueError(f"Unexpected units in radio frequency: {units}")
def MHz(num: int, khz: int = 0) -> RadioFrequency:
return RadioFrequency(num * 1000000 + khz * 1000)
def kHz(num: int) -> RadioFrequency:
return RadioFrequency(num * 1000)
def kHz(num: int, hz: int = 0) -> RadioFrequency:
return RadioFrequency(num * 1000 + hz)
@dataclass(frozen=True)

View File

@@ -1,4 +1,7 @@
"""TACAN channel handling."""
from __future__ import annotations
import re
from dataclasses import dataclass
from enum import Enum
from typing import Dict, Iterator, Set
@@ -45,6 +48,16 @@ class TacanChannel:
def __str__(self) -> str:
return f"{self.number}{self.band.value}"
@classmethod
def parse(cls, text: str) -> TacanChannel:
match = re.match(r"""^(\d{1,3})([XY])$""", text)
if match is None:
raise ValueError(f"Could not parse TACAN from {text}")
number = int(match.group(1))
if not number:
raise ValueError("TACAN channel cannot be 0")
return TacanChannel(number, TacanBand(match.group(2)))
class OutOfTacanChannelsError(RuntimeError):
"""Raised when all channels in this band have been allocated."""