mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix airwing config not properly saving or loading (#437)
* fix airwing config not properly saving or loading * add helper message to save function * bugfixes * remove unnecessary import used during testing * yet another forgotten import * change raise error to log warning
This commit is contained in:
parent
164873d3b1
commit
dd408f392b
@ -1,5 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Optional, TYPE_CHECKING, Union
|
from typing import Any, Optional, TYPE_CHECKING, Union
|
||||||
@ -71,13 +73,31 @@ class CampaignAirWingConfig:
|
|||||||
cls, data: dict[Union[str, int], Any], theater: ConflictTheater
|
cls, data: dict[Union[str, int], Any], theater: ConflictTheater
|
||||||
) -> CampaignAirWingConfig:
|
) -> CampaignAirWingConfig:
|
||||||
by_location: dict[ControlPoint, list[SquadronConfig]] = defaultdict(list)
|
by_location: dict[ControlPoint, list[SquadronConfig]] = defaultdict(list)
|
||||||
|
carriers = theater.find_carriers()
|
||||||
|
lhas = theater.find_lhas()
|
||||||
for base_id, squadron_configs in data.items():
|
for base_id, squadron_configs in data.items():
|
||||||
|
base: Optional[ControlPoint] = None
|
||||||
if isinstance(base_id, int):
|
if isinstance(base_id, int):
|
||||||
base = theater.find_control_point_by_airport_id(base_id)
|
base = theater.find_control_point_by_airport_id(base_id)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
base = theater.control_point_named(base_id)
|
base = theater.control_point_named(base_id)
|
||||||
|
except:
|
||||||
|
if base_id == "Red CV":
|
||||||
|
base = next((c for c in carriers if not c.captured), None)
|
||||||
|
elif base_id == "Blue CV":
|
||||||
|
base = next((c for c in carriers if c.captured), None)
|
||||||
|
elif base_id == "Red LHA":
|
||||||
|
base = next((l for l in lhas if not l.captured), None)
|
||||||
|
elif base_id == "Blue LHA":
|
||||||
|
base = next((l for l in lhas if l.captured), None)
|
||||||
|
|
||||||
for squadron_data in squadron_configs:
|
for squadron_data in squadron_configs:
|
||||||
|
if base is None:
|
||||||
|
logging.warning(
|
||||||
|
f"Skipping squadron config for unknown base: {base_id}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
by_location[base].append(SquadronConfig.from_data(squadron_data))
|
by_location[base].append(SquadronConfig.from_data(squadron_data))
|
||||||
|
|
||||||
return CampaignAirWingConfig(by_location)
|
return CampaignAirWingConfig(by_location)
|
||||||
|
|||||||
@ -271,6 +271,20 @@ class ConflictTheater:
|
|||||||
return cp
|
return cp
|
||||||
raise KeyError(f"Cannot find ControlPoint named {name}")
|
raise KeyError(f"Cannot find ControlPoint named {name}")
|
||||||
|
|
||||||
|
def find_carriers(self) -> List[ControlPoint]:
|
||||||
|
try:
|
||||||
|
carriers = [cp for cp in self.controlpoints if cp.is_carrier]
|
||||||
|
return carriers
|
||||||
|
except:
|
||||||
|
return []
|
||||||
|
|
||||||
|
def find_lhas(self) -> List[ControlPoint]:
|
||||||
|
try:
|
||||||
|
lhas = [cp for cp in self.controlpoints if cp.is_lha]
|
||||||
|
return lhas
|
||||||
|
except:
|
||||||
|
return []
|
||||||
|
|
||||||
def heading_to_conflict_from(self, position: Point) -> Optional[Heading]:
|
def heading_to_conflict_from(self, position: Point) -> Optional[Heading]:
|
||||||
# Heading for a Group to the enemy.
|
# Heading for a Group to the enemy.
|
||||||
# Should be the point between the nearest and the most distant conflict
|
# Should be the point between the nearest and the most distant conflict
|
||||||
|
|||||||
@ -817,12 +817,25 @@ class AirWingConfigurationDialog(QDialog):
|
|||||||
layout.addLayout(buttons_layout)
|
layout.addLayout(buttons_layout)
|
||||||
|
|
||||||
def save_config(self) -> None:
|
def save_config(self) -> None:
|
||||||
|
result = QMessageBox.information(
|
||||||
|
None,
|
||||||
|
"Save Air Wing?",
|
||||||
|
"Revert will not be possible after saving a different Air Wing.<br />"
|
||||||
|
"Are you sure you want to continue?",
|
||||||
|
QMessageBox.StandardButton.Yes,
|
||||||
|
QMessageBox.StandardButton.No,
|
||||||
|
)
|
||||||
|
if result == QMessageBox.StandardButton.No:
|
||||||
|
return
|
||||||
|
|
||||||
awd = airwing_dir()
|
awd = airwing_dir()
|
||||||
fd = QFileDialog(
|
fd = QFileDialog(
|
||||||
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
||||||
)
|
)
|
||||||
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
||||||
if fd.exec_():
|
if fd.exec_():
|
||||||
|
for tab in self.tabs:
|
||||||
|
tab.apply()
|
||||||
airwing = self._build_air_wing()
|
airwing = self._build_air_wing()
|
||||||
filename = fd.selectedFiles()[0]
|
filename = fd.selectedFiles()[0]
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w") as f:
|
||||||
@ -836,7 +849,7 @@ class AirWingConfigurationDialog(QDialog):
|
|||||||
for s in sqs:
|
for s in sqs:
|
||||||
cp = s.location.at
|
cp = s.location.at
|
||||||
if isinstance(cp, Point):
|
if isinstance(cp, Point):
|
||||||
key = s.location.name
|
key = s.location.full_name
|
||||||
else:
|
else:
|
||||||
key = cp.id
|
key = cp.id
|
||||||
name = (
|
name = (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user