def test_extending_all_events(): def all_extension(event): event.test_value = "pursuedpybear" @dataclasses.dataclass class TestEvent: pass class TestScene(BaseScene): def on_update(self, event, signal): assert event.test_value == "pursuedpybear" def on_mouse_motion(self, event, signal): assert event.test_value == "pursuedpybear" def on_test_event(self, event, signal): assert event.test_value == "pursuedpybear" ge = GameEngine(TestScene) ge.start() # We need test scene instantiated. ge.register(..., all_extension) ge.signal(events.Update(0.01)) ge.publish() ge.signal(events.MouseMotion(Vector(0, 0), Vector(0, 0), Vector(0, 1), [])) ge.publish() ge.signal(TestEvent()) ge.publish()
def mouse_motion(self, event, scene): screen_position = Vector(*event.pos) camera = scene.main_camera game_position = camera.translate_to_frame(screen_position) delta = Vector(*event.rel) * (1/camera.pixel_ratio) buttons = [bool(x) for x in event.buttons] return events.MouseMotion(game_position, screen_position, delta, buttons)
def mouse_motion(self, event, scene): screen_position = Vector(*event.pos) camera = scene.main_camera scene_position = camera.translate_to_frame(screen_position) delta = Vector(*event.rel) * (1 / camera.pixel_ratio) buttons = { self.button_map[btn + 1] for btn, value in enumerate(event.buttons) if value } return events.MouseMotion(position=scene_position, screen_position=screen_position, delta=delta, buttons=buttons)
def mouse_motion(self, event, scene): motion = event.motion screen_position = Vector(motion.x, motion.y) camera = scene.main_camera scene_position = camera.translate_point_to_game_space(screen_position) delta = Vector(motion.xrel, motion.yrel) * (1 / camera.pixel_ratio) buttons = { value for btn, value in self.button_mask_map.items() if motion.state & btn } return events.MouseMotion( position=scene_position, delta=delta, buttons=buttons, # timestamp=motion.timestamp )