def test__get_count_interactive(self):
        prompt("Please connect at least one controller "
               "before the test for controller.get_count() starts")

        # Reset the number of joysticks counted
        controller.quit()
        controller.init()

        joystick_num = controller.get_count()
        ans = question("get_count() thinks there are {} joysticks "
                       "connected. Is that correct?".format(joystick_num))

        self.assertTrue(ans)
示例#2
0
    def __init__(self, game=None):
        """
        Manage controllers.
        ConrollerManager manages controller events.
        Args:
        ----
        game -
        """
        super().__init__(game=game)
        self.controllers = {}
        self.proxies = []
        self.game = game

        # This must be called before other controller methods,
        # and is safe to call more than once.
        pygame._sdl2.controller.init()

        self.log.debug(
            f'Controller Module Inited: {pygame._sdl2.controller.get_init()}')

        # Controller Setup
        self.log.debug(
            f'Controller Count: {pygame._sdl2.controller.get_count()}')

        if pygame._sdl2.controller.get_count():
            controllers = [
                pygame._sdl2.controller.Controller(x)
                for x in range(pygame._sdl2.controller.get_count())
            ]

            for controller in controllers:
                controller.init()
                controller_proxy = ControllerManager.ControllerProxy(
                    controller_id=controller.get_id(), game=game)
                self.controllers.append(controller_proxy)

                # The controller proxy overrides the controller object
                self.log.debug(controller_proxy)

        self.proxies = [self.game]
 def setUp(self):
     controller.init()
 def test_init__multiple(self):
     controller.init()
     controller.init()
     self.assertTrue(controller.get_init())
 def test_init(self):
     controller.quit()
     controller.init()
     self.assertTrue(controller.get_init())