mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Correct type annotations.
This commit is contained in:
parent
8c5b808eba
commit
0d95716545
@ -1244,7 +1244,7 @@ def unit_type_name_2(unit_type) -> str:
|
|||||||
return unit_type.name and unit_type.name or unit_type.id
|
return unit_type.name and unit_type.name or unit_type.id
|
||||||
|
|
||||||
|
|
||||||
def unit_type_from_name(name: str) -> Optional[UnitType]:
|
def unit_type_from_name(name: str) -> Optional[Type[UnitType]]:
|
||||||
if name in vehicle_map:
|
if name in vehicle_map:
|
||||||
return vehicle_map[name]
|
return vehicle_map[name]
|
||||||
elif name in plane_map:
|
elif name in plane_map:
|
||||||
|
|||||||
@ -107,14 +107,16 @@ class Event:
|
|||||||
for destroyed_aircraft in debriefing.killed_aircrafts:
|
for destroyed_aircraft in debriefing.killed_aircrafts:
|
||||||
try:
|
try:
|
||||||
cpid = int(destroyed_aircraft.split("|")[3])
|
cpid = int(destroyed_aircraft.split("|")[3])
|
||||||
type = db.unit_type_from_name(destroyed_aircraft.split("|")[4])
|
aircraft = db.unit_type_from_name(
|
||||||
if cpid in cp_map.keys():
|
destroyed_aircraft.split("|")[4])
|
||||||
|
if cpid in cp_map:
|
||||||
cp = cp_map[cpid]
|
cp = cp_map[cpid]
|
||||||
if type in cp.base.aircraft.keys():
|
if aircraft in cp.base.aircraft:
|
||||||
logging.info("Aircraft destroyed : " + str(type))
|
logging.info(f"Aircraft destroyed: {aircraft}")
|
||||||
cp.base.aircraft[type] = max(0, cp.base.aircraft[type]-1)
|
cp.base.aircraft[aircraft] = max(
|
||||||
except Exception as e:
|
0, cp.base.aircraft[aircraft] - 1)
|
||||||
print(e)
|
except Exception:
|
||||||
|
logging.exception("Failed to commit destroyed aircraft")
|
||||||
|
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
# Destroyed ground units
|
# Destroyed ground units
|
||||||
@ -123,13 +125,13 @@ class Event:
|
|||||||
for killed_ground_unit in debriefing.killed_ground_units:
|
for killed_ground_unit in debriefing.killed_ground_units:
|
||||||
try:
|
try:
|
||||||
cpid = int(killed_ground_unit.split("|")[3])
|
cpid = int(killed_ground_unit.split("|")[3])
|
||||||
type = db.unit_type_from_name(killed_ground_unit.split("|")[4])
|
aircraft = db.unit_type_from_name(killed_ground_unit.split("|")[4])
|
||||||
if cpid in cp_map.keys():
|
if cpid in cp_map.keys():
|
||||||
killed_unit_count_by_cp[cpid] = killed_unit_count_by_cp[cpid] + 1
|
killed_unit_count_by_cp[cpid] = killed_unit_count_by_cp[cpid] + 1
|
||||||
cp = cp_map[cpid]
|
cp = cp_map[cpid]
|
||||||
if type in cp.base.armor.keys():
|
if aircraft in cp.base.armor.keys():
|
||||||
logging.info("Ground unit destroyed : " + str(type))
|
logging.info("Ground unit destroyed : " + str(aircraft))
|
||||||
cp.base.armor[type] = max(0, cp.base.armor[type] - 1)
|
cp.base.armor[aircraft] = max(0, cp.base.armor[aircraft] - 1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Dict, Iterable, Iterator, Set, Tuple, TYPE_CHECKING
|
from typing import Dict, Iterable, Iterator, Set, Tuple, TYPE_CHECKING, Type
|
||||||
|
|
||||||
from dcs.unittype import FlyingType
|
from dcs.unittype import FlyingType
|
||||||
|
|
||||||
@ -17,9 +17,9 @@ class ControlPointAircraftInventory:
|
|||||||
|
|
||||||
def __init__(self, control_point: ControlPoint) -> None:
|
def __init__(self, control_point: ControlPoint) -> None:
|
||||||
self.control_point = control_point
|
self.control_point = control_point
|
||||||
self.inventory: Dict[FlyingType, int] = defaultdict(int)
|
self.inventory: Dict[Type[FlyingType], int] = defaultdict(int)
|
||||||
|
|
||||||
def add_aircraft(self, aircraft: FlyingType, count: int) -> None:
|
def add_aircraft(self, aircraft: Type[FlyingType], count: int) -> None:
|
||||||
"""Adds aircraft to the inventory.
|
"""Adds aircraft to the inventory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -28,7 +28,7 @@ class ControlPointAircraftInventory:
|
|||||||
"""
|
"""
|
||||||
self.inventory[aircraft] += count
|
self.inventory[aircraft] += count
|
||||||
|
|
||||||
def remove_aircraft(self, aircraft: FlyingType, count: int) -> None:
|
def remove_aircraft(self, aircraft: Type[FlyingType], count: int) -> None:
|
||||||
"""Removes aircraft from the inventory.
|
"""Removes aircraft from the inventory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -47,7 +47,7 @@ class ControlPointAircraftInventory:
|
|||||||
)
|
)
|
||||||
self.inventory[aircraft] -= count
|
self.inventory[aircraft] -= count
|
||||||
|
|
||||||
def available(self, aircraft: FlyingType) -> int:
|
def available(self, aircraft: Type[FlyingType]) -> int:
|
||||||
"""Returns the number of available aircraft of the given type.
|
"""Returns the number of available aircraft of the given type.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@ -22,7 +22,7 @@ BASE_MIN_STRENGTH = 0
|
|||||||
class Base:
|
class Base:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.aircraft: Dict[FlyingType, int] = {}
|
self.aircraft: Dict[Type[FlyingType], int] = {}
|
||||||
self.armor: Dict[VehicleType, int] = {}
|
self.armor: Dict[VehicleType, int] = {}
|
||||||
self.aa: Dict[AirDefence, int] = {}
|
self.aa: Dict[AirDefence, int] = {}
|
||||||
self.commision_points: Dict[Type, float] = {}
|
self.commision_points: Dict[Type, float] = {}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Dict, List, Optional, TYPE_CHECKING
|
from typing import Dict, List, Optional, TYPE_CHECKING, Type
|
||||||
|
|
||||||
from dcs.mapping import Point
|
from dcs.mapping import Point
|
||||||
from dcs.point import MovingPoint, PointAction
|
from dcs.point import MovingPoint, PointAction
|
||||||
@ -133,8 +133,8 @@ class FlightWaypoint:
|
|||||||
|
|
||||||
class Flight:
|
class Flight:
|
||||||
|
|
||||||
def __init__(self, package: Package, unit_type: FlyingType, count: int,
|
def __init__(self, package: Package, unit_type: Type[FlyingType],
|
||||||
flight_type: FlightType, start_type: str,
|
count: int, flight_type: FlightType, start_type: str,
|
||||||
departure: ControlPoint, arrival: ControlPoint,
|
departure: ControlPoint, arrival: ControlPoint,
|
||||||
divert: Optional[ControlPoint]) -> None:
|
divert: Optional[ControlPoint]) -> None:
|
||||||
self.package = package
|
self.package = package
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
from PySide2.QtWidgets import (
|
from PySide2.QtWidgets import (
|
||||||
QGroupBox,
|
QGroupBox,
|
||||||
@ -106,7 +107,7 @@ class QRecruitBehaviour:
|
|||||||
|
|
||||||
return row + 1
|
return row + 1
|
||||||
|
|
||||||
def _update_count_label(self, unit_type: UnitType):
|
def _update_count_label(self, unit_type: Type[UnitType]):
|
||||||
|
|
||||||
self.bought_amount_labels[unit_type].setText("<b>{}</b>".format(
|
self.bought_amount_labels[unit_type].setText("<b>{}</b>".format(
|
||||||
unit_type in self.pending_deliveries.units and "{}".format(self.pending_deliveries.units[unit_type]) or "0"
|
unit_type in self.pending_deliveries.units and "{}".format(self.pending_deliveries.units[unit_type]) or "0"
|
||||||
@ -125,7 +126,7 @@ class QRecruitBehaviour:
|
|||||||
child.setText(
|
child.setText(
|
||||||
QRecruitBehaviour.BUDGET_FORMAT.format(self.budget))
|
QRecruitBehaviour.BUDGET_FORMAT.format(self.budget))
|
||||||
|
|
||||||
def buy(self, unit_type):
|
def buy(self, unit_type: Type[UnitType]):
|
||||||
price = db.PRICES[unit_type]
|
price = db.PRICES[unit_type]
|
||||||
if self.budget >= price:
|
if self.budget >= price:
|
||||||
self.pending_deliveries.deliver({unit_type: 1})
|
self.pending_deliveries.deliver({unit_type: 1})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user