mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Fix TACAN beacon type import.
The dataclass contructor will not automatically convert the int in the JSON file to the enum type, so our enum equivalence check was not actually working, and could result in us re-allocating a TACAN channel that was used by the map. Fixing this problem surfaces a latent bug, where we can't actually treat duplicate map TACAN channels as a bug because some channels are used by multiple airports in PG.
This commit is contained in:
parent
2461a66ad8
commit
08abe36443
@ -84,7 +84,13 @@ class Beacons:
|
||||
|
||||
beacons = {}
|
||||
for bid, beacon in json.loads(beacons_file.read_text()).items():
|
||||
beacons[bid] = Beacon(**beacon)
|
||||
beacons[bid] = Beacon(
|
||||
name=beacon["name"],
|
||||
callsign=beacon["callsign"],
|
||||
beacon_type=BeaconType(beacon["beacon_type"]),
|
||||
hertz=beacon["hertz"],
|
||||
channel=beacon["channel"],
|
||||
)
|
||||
cls._by_terrain[theater.terrain.name] = beacons
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -66,13 +66,6 @@ class OutOfTacanChannelsError(RuntimeError):
|
||||
super().__init__(f"No available channels in TACAN {band.value} band")
|
||||
|
||||
|
||||
class TacanChannelInUseError(RuntimeError):
|
||||
"""Raised when attempting to reserve an in-use channel."""
|
||||
|
||||
def __init__(self, channel: TacanChannel) -> None:
|
||||
super().__init__(f"{channel} is already in use")
|
||||
|
||||
|
||||
class TacanRegistry:
|
||||
"""Manages allocation of TACAN channels."""
|
||||
|
||||
@ -116,10 +109,5 @@ class TacanRegistry:
|
||||
|
||||
Args:
|
||||
channel: The channel to reserve.
|
||||
|
||||
Raises:
|
||||
TacanChannelInUseError: The given channel is already in use.
|
||||
"""
|
||||
if channel in self.allocated_channels:
|
||||
raise TacanChannelInUseError(channel)
|
||||
self.allocated_channels.add(channel)
|
||||
|
||||
@ -4,7 +4,6 @@ from game.radio.tacan import (
|
||||
OutOfTacanChannelsError,
|
||||
TacanBand,
|
||||
TacanChannel,
|
||||
TacanChannelInUseError,
|
||||
TacanRegistry,
|
||||
TacanUsage,
|
||||
)
|
||||
@ -72,7 +71,6 @@ def test_reserve_all_valid_a2a() -> None:
|
||||
|
||||
def test_reserve_again() -> None:
|
||||
registry = TacanRegistry()
|
||||
with pytest.raises(TacanChannelInUseError):
|
||||
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
|
||||
registry.mark_unavailable(TacanChannel(1, TacanBand.X))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user