MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / _parse_events

Method _parse_events

scenario_runner/no_rendering_mode.py:1264–1325  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1262 self.parse_input(clock)
1263
1264 def _parse_events(self):
1265 self.mouse_pos = pygame.mouse.get_pos()
1266 for event in pygame.event.get():
1267 if event.type == pygame.QUIT:
1268 exit_game()
1269 elif event.type == pygame.KEYUP:
1270 if self._is_quit_shortcut(event.key):
1271 exit_game()
1272 elif event.key == K_h or (event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT):
1273 module_hud = module_manager.get_module(MODULE_HUD)
1274 module_hud.help.toggle()
1275 elif event.key == K_TAB:
1276 module_world = module_manager.get_module(MODULE_WORLD)
1277 module_hud = module_manager.get_module(MODULE_HUD)
1278 if module_world.hero_actor is None:
1279 module_world.select_hero_actor()
1280 self.wheel_offset = HERO_DEFAULT_SCALE
1281 self.control = carla.VehicleControl()
1282 module_hud.notification('Hero Mode')
1283 else:
1284 self.wheel_offset = MAP_DEFAULT_SCALE
1285 self.mouse_offset = [0, 0]
1286 self.mouse_pos = [0, 0]
1287 module_world.scale_offset = [0, 0]
1288 module_world.hero_actor = None
1289 module_hud.notification('Map Mode')
1290 elif event.key == K_F1:
1291 module_hud = module_manager.get_module(MODULE_HUD)
1292 module_hud.show_info = not module_hud.show_info
1293 elif event.key == K_i:
1294 module_hud = module_manager.get_module(MODULE_HUD)
1295 module_hud.show_actor_ids = not module_hud.show_actor_ids
1296 elif isinstance(self.control, carla.VehicleControl):
1297 if event.key == K_q:
1298 self.control.gear = 1 if self.control.reverse else -1
1299 elif event.key == K_m:
1300 self.control.manual_gear_shift = not self.control.manual_gear_shift
1301 world = module_manager.get_module(MODULE_WORLD)
1302 self.control.gear = world.hero_actor.get_control().gear
1303 module_hud = module_manager.get_module(MODULE_HUD)
1304 module_hud.notification('%s Transmission' % (
1305 'Manual' if self.control.manual_gear_shift else 'Automatic'))
1306 elif self.control.manual_gear_shift and event.key == K_COMMA:
1307 self.control.gear = max(-1, self.control.gear - 1)
1308 elif self.control.manual_gear_shift and event.key == K_PERIOD:
1309 self.control.gear = self.control.gear + 1
1310 elif event.key == K_p:
1311 world = module_manager.get_module(MODULE_WORLD)
1312 if world.hero_actor is not None:
1313 self._autopilot_enabled = not self._autopilot_enabled
1314 world.hero_actor.set_autopilot(self._autopilot_enabled)
1315 module_hud = module_manager.get_module(MODULE_HUD)
1316 module_hud.notification('Autopilot %s' % ('On' if self._autopilot_enabled else 'Off'))
1317 elif event.type == pygame.MOUSEBUTTONDOWN:
1318 if event.button == 4:
1319 self.wheel_offset += self.wheel_amount
1320 if self.wheel_offset >= 1.0:
1321 self.wheel_offset = 1.0

Callers 1

parse_inputMethod · 0.95

Calls 7

_is_quit_shortcutMethod · 0.95
exit_gameFunction · 0.85
getMethod · 0.80
get_moduleMethod · 0.80
toggleMethod · 0.80
select_hero_actorMethod · 0.80
notificationMethod · 0.80

Tested by

no test coverage detected