Skip to content

Commit

Permalink
corrected call argument get_instance keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
DorskFR committed Aug 13, 2021
1 parent 9ca9906 commit 331d50b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LPBv2/LPBv2/controller/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Action:
def __init__(self, mouse=Mouse(), keyboard=Keyboard(), *args, **kwargs):
def __init__(self, mouse=Mouse.get_instance(), keyboard=Keyboard.get_instance(), *args, **kwargs):
self.mouse = mouse
self.keyboard = keyboard
self.hotkeys = kwargs.get("hotkeys")
Expand Down
2 changes: 1 addition & 1 deletion LPBv2/LPBv2/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def __init__(self, *args, **kwargs):
self.combat = Combat(*args, **kwargs)
self.movement = Movement(*args, **kwargs)
self.usable = Usable(*args, **kwargs)
self.shop = Shop(keyboard=Keyboard(sleep=0.1), *args, **kwargs)
self.shop = Shop(keyboard=Keyboard().get_instance(sleep=0.01), *args, **kwargs)
self.listener = KeyboardListener()
17 changes: 14 additions & 3 deletions LPBv2/LPBv2/controller/devices/keyboard.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from time import sleep
import os
from .keyboard_pynput import KeyboardPynput
from .keyboard_pydirectinput import KeyboardPyDirectInput



class Keyboard:
__instance = None

@staticmethod
def get_instance(*args, **kwargs):
if Keyboard.__instance is None:
Keyboard(*args, **kwargs)
return Keyboard.__instance

def __init__(self, sleep=0):
if Keyboard.__instance is not None:
raise Exception("This class is a Singleton")
else:
Keyboard.__instance = self
if os.name == "nt":
from .keyboard_pydirectinput import KeyboardPyDirectInput
self.keyboard = KeyboardPyDirectInput()
else:
from .keyboard_pynput import KeyboardPynput
self.keyboard = KeyboardPynput()
self.sleep=sleep

Expand Down
12 changes: 12 additions & 0 deletions LPBv2/LPBv2/controller/devices/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@


class Mouse:
__instance = None

@staticmethod
def get_instance(*args, **kwargs):
if Mouse.__instance is None:
Mouse(*args, **kwargs)
return Mouse.__instance

def __init__(self, sleep=0):
if Mouse.__instance is not None:
raise Exception("This class is a Singleton")
else:
Mouse.__instance = self
self.mouse = Controller()
self.sleep = sleep

Expand Down

0 comments on commit 331d50b

Please sign in to comment.