mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user