From 2b2c2d946a3e73fa7057b029cc42eef915cb5206 Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Sat, 13 May 2023 10:48:59 -0400 Subject: [PATCH] added a bool to disable tick checking if needed --- pocket_friends/game_files/io/input_handler.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pocket_friends/game_files/io/input_handler.py b/pocket_friends/game_files/io/input_handler.py index 926ab48..e04f7f0 100644 --- a/pocket_friends/game_files/io/input_handler.py +++ b/pocket_friends/game_files/io/input_handler.py @@ -1,5 +1,6 @@ import pygame + class InputHandler: """ Class that is implemented into surfaces in order to control the @@ -11,15 +12,17 @@ class InputHandler: """ - def __init__(self, pygame_clock): + def __init__(self, pygame_clock, tick_check=True): """ Create a InputHandler object using a given Pygame clock. Args: - pygame_clock (pygame.time.Clock): A pygame clock to use as the clock for input time calculations. + pygame_clock (:obj:`pygame.time.Clock`): A pygame clock to use as the clock for input time calculations. + tick_check (bool, optional): Bool to ignore inputs that happen to quickly after another. Defaults to True. """ self.clock = pygame_clock + self.tick_check = tick_check self.last_input_tick = 0 def create_event(self, pressed_button): @@ -30,7 +33,11 @@ class InputHandler: """ # Register a button click so long as the last button click happened no less than two frames ago - if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2 or not gpio_handler.ON_HARDWARE: + if self.tick_check: + if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2: + pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button})) + pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button})) + else: pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button})) pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button})) self.last_input_tick = pygame.time.get_ticks()