(self, index, notify=True, force_respawn=False)
| 925 | self.set_sensor(self.index, notify=False, force_respawn=True) |
| 926 | |
| 927 | def set_sensor(self, index, notify=True, force_respawn=False): |
| 928 | index = index % len(self.sensors) |
| 929 | needs_respawn = True if self.index is None else \ |
| 930 | (force_respawn or (self.sensors[index][2] != self.sensors[self.index][2])) |
| 931 | if needs_respawn: |
| 932 | if self.sensor is not None: |
| 933 | self.sensor.destroy() |
| 934 | self.surface = None |
| 935 | self.sensor = self._parent.get_world().spawn_actor( |
| 936 | self.sensors[index][-1], |
| 937 | self._camera_transforms[self.transform_index][0], |
| 938 | attach_to=self._parent, |
| 939 | attachment_type=self._camera_transforms[self.transform_index][1]) |
| 940 | # We need to pass the lambda a weak reference to self to avoid |
| 941 | # circular reference. |
| 942 | weak_self = weakref.ref(self) |
| 943 | self.sensor.listen(lambda image: CameraManager._parse_image(weak_self, image)) |
| 944 | if notify: |
| 945 | self.hud.notification(self.sensors[index][2]) |
| 946 | self.index = index |
| 947 | |
| 948 | def next_sensor(self): |
| 949 | self.set_sensor(self.index + 1) |
no test coverage detected