From ee1430ac71fa3c35e4d6ef1a1c1e0a7555ee4f57 Mon Sep 17 00:00:00 2001 From: 332FG Raven <332fg.raven@gmail.com> Date: Thu, 11 Jan 2024 20:39:44 -0800 Subject: [PATCH] Addressed review comments * comma at the end of task_maps * None check for group_id * WWIIBigFormationPosition class name changed to Vector3 --- dcs/mapping.py | 9 ++------- dcs/task.py | 16 ++++++++++------ tests/test_mission.py | 9 ++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/dcs/mapping.py b/dcs/mapping.py index 171fc4fc..073370b7 100644 --- a/dcs/mapping.py +++ b/dcs/mapping.py @@ -98,17 +98,12 @@ class Vector2: y: float -@dataclass -class WWIIFollowBigFormationPosition: +@dataclass(frozen=True) +class Vector3: x: int y: int z: int - def __eq__(self, other): - if isinstance(other, dict): - return self.__dict__ == other - return self.__dict__ == other.__dict__ - class Point(Vector2): def __init__(self, x: float, y: float, terrain: Terrain) -> None: diff --git a/dcs/task.py b/dcs/task.py index b91e6765..be89cedd 100644 --- a/dcs/task.py +++ b/dcs/task.py @@ -9,7 +9,7 @@ """ from typing import List, Dict, Optional, Type, Any, Union from enum import Enum, IntEnum -from dcs.mapping import Vector2, WWIIFollowBigFormationPosition +from dcs.mapping import Vector2, Vector3 from dcs.unit import Unit @@ -531,7 +531,7 @@ def __init__(self, "targetTypes": {i: targets[i - 1] for i in range(1, len(targets) + 1)}, "pos": position } - if group_id: + if group_id is not None: self.params["groupId"] = group_id if lastwpt: self.params["lastWptIndexFlagChangedManually"] = True @@ -1037,7 +1037,7 @@ class FormationType(IntEnum): def __init__(self, group_id: Optional[int] = None, - position: WWIIFollowBigFormationPosition = WWIIFollowBigFormationPosition(0, 0, 0), + position: Vector3 = Vector3(0, 0, 0), last_wpt_index_flag: bool = False, last_wpt_index_flag_changed_manually: bool = False, formation_type: FormationType = FormationType.COMBAT_BOX_FOR_OPEN_FORMATION, @@ -1048,7 +1048,11 @@ def __init__(self, super().__init__(self.Id) self.params = { - "pos": position, + "pos": { + "x": position.x, + "y": position.y, + "z": position.z + }, "lastWptIndexFlag": last_wpt_index_flag, "lastWptIndexFlagChangedManually": last_wpt_index_flag_changed_manually, "lastWptIndex": last_wpt_index, @@ -1057,7 +1061,7 @@ def __init__(self, "posInGroup": pos_in_group, "posInWing": pos_in_wing } - if group_id: + if group_id is not None: self.params["groupId"] = group_id if last_wpt_index: self.params["lastWptIndex"] = last_wpt_index @@ -1100,7 +1104,7 @@ def __eq__(self, other) -> bool: AttackUnit.Id: AttackUnit, AttackMapObject.Id: AttackMapObject, EngageTargets.Id: EngageTargets, - WWIIFollowBigFormation.Id: WWIIFollowBigFormation + WWIIFollowBigFormation.Id: WWIIFollowBigFormation, } diff --git a/tests/test_mission.py b/tests/test_mission.py index 51bf3355..7c4cd0b6 100644 --- a/tests/test_mission.py +++ b/tests/test_mission.py @@ -12,7 +12,6 @@ from dcs.flyingunit import FlyingUnit from dcs.unit import Ship from dcs.task import WWIIFollowBigFormation -from dcs.mapping import WWIIFollowBigFormationPosition class BasicTests(unittest.TestCase): @@ -900,7 +899,7 @@ def test_big_formation_action_leader(self) -> None: self.assertNotIn("groupId", task.params) self.assertNotIn("lastWptIndex", task.params) self.assertEqual(task.params["formationType"], WWIIFollowBigFormation.FormationType.COMBAT_BOX_FOR_OPEN_FORMATION) - self.assertEqual(task.params["pos"], WWIIFollowBigFormationPosition(0, 0, 0)) + self.assertEqual(task.params["pos"], {"x": 0, "y": 0, "z": 0}) self.assertTrue(task.params["lastWptIndexFlagChangedManually"]) self.assertEqual(len(task.params), 7) @@ -926,7 +925,7 @@ def test_big_formation_action_left(self) -> None: task = m.coalition['blue'].country("Combined Joint Task Forces Blue").plane_group[1].points[0].tasks[5] self.assertEqual(task.params["formationType"], WWIIFollowBigFormation.FormationType.JAVELIN_DOWN) - self.assertEqual(task.params["pos"], WWIIFollowBigFormationPosition(-480, -70, -240)) + self.assertEqual(task.params["pos"], {"x": -480, "y": -70, "z": -240}) self.assertEqual(task.params["groupId"], 2) self.assertEqual(task.params["posInGroup"], 2) self.assertEqual(task.params["lastWptIndex"], 3) @@ -955,7 +954,7 @@ def test_big_formation_action_back(self) -> None: task = m.coalition['blue'].country("Combined Joint Task Forces Blue").plane_group[2].points[0].tasks[5] self.assertEqual(task.params["formationType"], WWIIFollowBigFormation.FormationType.COMBAT_BOX) - self.assertEqual(task.params["pos"], WWIIFollowBigFormationPosition(-320, -50, -0)) + self.assertEqual(task.params["pos"], {"x": -320, "y": -50, "z": -0}) self.assertEqual(task.params["groupId"], 2) self.assertEqual(task.params["posInBox"], 3) self.assertEqual(task.params["lastWptIndex"], 3) @@ -984,7 +983,7 @@ def test_big_formation_action_right(self) -> None: task = m.coalition['blue'].country("Combined Joint Task Forces Blue").plane_group[3].points[0].tasks[5] self.assertEqual(task.params["formationType"], WWIIFollowBigFormation.FormationType.COMBAT_BOX_FOR_OPEN_FORMATION) - self.assertEqual(task.params["pos"], WWIIFollowBigFormationPosition(-160, 50, 240)) + self.assertEqual(task.params["pos"], {"x": -160, "y": 50, "z": 240}) self.assertEqual(task.params["groupId"], 2) self.assertEqual(task.params["posInBox"], 1) self.assertEqual(task.params["lastWptIndex"], 3)