Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
* comma at the end of task_maps
* None check for group_id
* WWIIBigFormationPosition class name changed to Vector3
  • Loading branch information
332fg-raven committed Jan 12, 2024
1 parent 6c2794e commit ee1430a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
9 changes: 2 additions & 7 deletions dcs/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 10 additions & 6 deletions dcs/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -1100,7 +1104,7 @@ def __eq__(self, other) -> bool:
AttackUnit.Id: AttackUnit,
AttackMapObject.Id: AttackMapObject,
EngageTargets.Id: EngageTargets,
WWIIFollowBigFormation.Id: WWIIFollowBigFormation
WWIIFollowBigFormation.Id: WWIIFollowBigFormation,
}


Expand Down
9 changes: 4 additions & 5 deletions tests/test_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee1430a

Please sign in to comment.