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
|
||||
|
||||
import logging
|
||||
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional, TYPE_CHECKING, Union
|
||||
@ -71,13 +73,31 @@ class CampaignAirWingConfig:
|
||||
cls, data: dict[Union[str, int], Any], theater: ConflictTheater
|
||||
) -> CampaignAirWingConfig:
|
||||
by_location: dict[ControlPoint, list[SquadronConfig]] = defaultdict(list)
|
||||
carriers = theater.find_carriers()
|
||||
lhas = theater.find_lhas()
|
||||
for base_id, squadron_configs in data.items():
|
||||
base: Optional[ControlPoint] = None
|
||||
if isinstance(base_id, int):
|
||||
base = theater.find_control_point_by_airport_id(base_id)
|
||||
else:
|
||||
base = theater.control_point_named(base_id)
|
||||
try:
|
||||
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:
|
||||
by_location[base].append(SquadronConfig.from_data(squadron_data))
|
||||
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))
|
||||
|
||||
return CampaignAirWingConfig(by_location)
|
||||
|
||||
@ -271,6 +271,20 @@ class ConflictTheater:
|
||||
return cp
|
||||
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]:
|
||||
# Heading for a Group to the enemy.
|
||||
# Should be the point between the nearest and the most distant conflict
|
||||
|
||||
@ -817,12 +817,25 @@ class AirWingConfigurationDialog(QDialog):
|
||||
layout.addLayout(buttons_layout)
|
||||
|
||||
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()
|
||||
fd = QFileDialog(
|
||||
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
||||
)
|
||||
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
||||
if fd.exec_():
|
||||
for tab in self.tabs:
|
||||
tab.apply()
|
||||
airwing = self._build_air_wing()
|
||||
filename = fd.selectedFiles()[0]
|
||||
with open(filename, "w") as f:
|
||||
@ -836,7 +849,7 @@ class AirWingConfigurationDialog(QDialog):
|
||||
for s in sqs:
|
||||
cp = s.location.at
|
||||
if isinstance(cp, Point):
|
||||
key = s.location.name
|
||||
key = s.location.full_name
|
||||
else:
|
||||
key = cp.id
|
||||
name = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user