From 6e5dd7eab4bb3d31c5100c1965da1fa5daeb2c94 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:01:11 +0200 Subject: [PATCH] Introduced Abstract Base Classes Introduced Abstract Base Classes to ease the process of adding another platform. Also some minor documentation. --- main.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 9234962..1f1ce76 100644 --- a/main.py +++ b/main.py @@ -2,33 +2,55 @@ """Main asteroid-automator script.""" import platform +from abc import ABC, abstractmethod + +import pyautogui PLATFORM_SYS = platform.system() if PLATFORM_SYS == "Windows": import d3dshot -elif PLATFORM_SYS == "Linux": - import pyautogui -class AutomatableGame: +class AbstractAutomatableGame(ABC): """Base class for each platform.""" + @abstractmethod def __init__(self): + """Initializes components needed for the I/O to operate.""" self.loc = pyautogui.locateOnScreen("images/app.png") + @abstractmethod def fetch_sshot(self): """Creates a screenshot, and returns it in Pillow format.""" return pyautogui.screenshot(region=self.loc) - def send_key(self, key): + @abstractmethod + def send_key(self, key: str): + """Presses a key on a virtual keyboard.""" pass -class AutomatableGame__Windows(AutomatableGame): +class AutomatableGame__Windows(AbstractAutomatableGame): def __init__(self): super().__init__(self) self.d = d3dshot.create() def fetch_sshot(self): return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) + + def send_key(self, key: str): + pass # TODO: Add send_key method + + +class AutomatableGame__Linux(AbstractAutomatableGame): + """Base class for each platform.""" + + def __init__(self): + super().__init__(self) + + def fetch_sshot(self): + return pyautogui.screenshot(region=self.loc) + + def send_key(self, key: str): + pass # TODO: Add send_key method