From 3f9af5012cba5c155305720eae058b4fe727ac8c Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sun, 19 Dec 2021 13:02:58 -0500 Subject: [PATCH 01/18] Cross-platform basics on capturing the game screen to a PIL image. --- main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ba9eccf --- /dev/null +++ b/main.py @@ -0,0 +1,24 @@ +import pyautogui +import os + +if os.name == 'windows': + import d3dshot + +class AutomatableGame: + def __init__(self): + self.loc = pyautogui.locateOnScreen("images/app.png") + + def fetch_sshot(self): + return pyautogui.screenshot(region=self.loc) + + def send_key(self, key): + pass + + +class AutomatableGame__Windows(AutomatableGame): + def __init__(self): + super().__init__(self) + self.d = d3dshot.create() + + def fetch_sshot(self): + return d.screenshot() # Cut this to self.loc(x, y, w, h) From 555ecfa7a3ffde05ff60223b77a4b221359905c0 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 20:18:07 +0200 Subject: [PATCH 02/18] Added newlines and sorted imports Added newlines and sorted imports according to PEP-8. --- main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index ba9eccf..f3b3cbe 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,15 @@ -import pyautogui import os -if os.name == 'windows': +import pyautogui + +if os.name == "windows": import d3dshot + class AutomatableGame: def __init__(self): self.loc = pyautogui.locateOnScreen("images/app.png") - + def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) @@ -19,6 +21,6 @@ class AutomatableGame__Windows(AutomatableGame): def __init__(self): super().__init__(self) self.d = d3dshot.create() - + def fetch_sshot(self): - return d.screenshot() # Cut this to self.loc(x, y, w, h) + return d.screenshot() # Cut this to self.loc(x, y, w, h) From b5c4bbcdd9ef46af7dfa19ebb09fb29f4e5b4782 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 20:26:08 +0200 Subject: [PATCH 03/18] Added simple documentation and a shebang Added simple documentation and a shebang and fixed a simple error at line 32. --- main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index f3b3cbe..cff6b9c 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python3 +"""Main asteroid-automator script.""" + import os import pyautogui @@ -7,10 +10,13 @@ if os.name == "windows": class AutomatableGame: + """Base class for each platform.""" + def __init__(self): self.loc = pyautogui.locateOnScreen("images/app.png") def fetch_sshot(self): + """Creates a screenshot, and returns it in Pillow format.""" return pyautogui.screenshot(region=self.loc) def send_key(self, key): @@ -23,4 +29,4 @@ class AutomatableGame__Windows(AutomatableGame): self.d = d3dshot.create() def fetch_sshot(self): - return d.screenshot() # Cut this to self.loc(x, y, w, h) + return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) From bfcb0650e673ccf3c5a35719a19d1c0be9d9c72f Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 20:29:38 +0200 Subject: [PATCH 04/18] Changed os.name to platform.system() Changed os.name to platform.system() because platform.system() is much more reliable, and is easy to check for different system. Also added a check for linux. --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index cff6b9c..9234962 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,14 @@ #!/usr/bin/env python3 """Main asteroid-automator script.""" -import os +import platform -import pyautogui +PLATFORM_SYS = platform.system() -if os.name == "windows": +if PLATFORM_SYS == "Windows": import d3dshot +elif PLATFORM_SYS == "Linux": + import pyautogui class AutomatableGame: 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 05/18] 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 From 9eb29fc7cc7aa942fad977d213da63526ca72a33 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:05:25 +0200 Subject: [PATCH 06/18] Changed the naming a bit Changed the naming a bit --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 1f1ce76..bb97a64 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ if PLATFORM_SYS == "Windows": import d3dshot -class AbstractAutomatableGame(ABC): +class AbstractGameIO(ABC): """Base class for each platform.""" @abstractmethod @@ -31,7 +31,7 @@ class AbstractAutomatableGame(ABC): pass -class AutomatableGame__Windows(AbstractAutomatableGame): +class WindowsGameIO(AbstractGameIO): def __init__(self): super().__init__(self) self.d = d3dshot.create() @@ -43,7 +43,7 @@ class AutomatableGame__Windows(AbstractAutomatableGame): pass # TODO: Add send_key method -class AutomatableGame__Linux(AbstractAutomatableGame): +class LinuxGameIO(AbstractAutomatableGame): """Base class for each platform.""" def __init__(self): From 1720ee3bbca9581e77a51a155f00707c7902d2fc Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sun, 19 Dec 2021 14:11:20 -0500 Subject: [PATCH 07/18] remove behavior from abstract base method --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index bb97a64..a13fbaa 100644 --- a/main.py +++ b/main.py @@ -23,7 +23,7 @@ class AbstractGameIO(ABC): @abstractmethod def fetch_sshot(self): """Creates a screenshot, and returns it in Pillow format.""" - return pyautogui.screenshot(region=self.loc) + pass @abstractmethod def send_key(self, key: str): From 30a45e6b4799e60b41ccbcfd1bb07ebe0bff1558 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sun, 19 Dec 2021 14:11:55 -0500 Subject: [PATCH 08/18] Application screenshot used for window location --- images/app.png | Bin 0 -> 19618 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 images/app.png diff --git a/images/app.png b/images/app.png new file mode 100644 index 0000000000000000000000000000000000000000..dafa656cd3c0d6481d9b6f0a2b5b379dfc2e05e8 GIT binary patch literal 19618 zcmeFXRa9GF_$>;hNQ*;(;uLpx32m|B?q1y8t;L~8ad&r@0D5dCJ&3Yvq$U=Qr05Q;?HD{YdZ;1_lOI@`tDr3=A9@49q)qq<6qK+uw^WVPMe9 zJXJKDl?>g;>>ce)Ev!w*oIUJK$V}WVOkrT$7b{Y%Vu`@0fp2qk-tXU0{@CR87QaUT zwF^&Qn^X1nEuz^;Ppv4UgMNvc=I-*nJ?{Cub~4=M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;*R~*MnyrvNsm7&sDYEv8%1)$KSg2+phO6e3f|8H_vnN)um}!U))YN zT&xtI>+6+r`+MqkA1U^RbB{Id-&UKRd4J(g?tPLo7OXXm3}WwnU3_*w%jU?m<;ov_>)*Z9j$zSsyP~Rp zt=CJ-b*qHd?_F7Tx$913IGa2$0wQ)W~J+iBu+({gTe~DWM4fXbuuV literal 0 HcmV?d00001 From 1a1e8efef87f22aa5e01dc4189980fc037391b48 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:16:34 +0200 Subject: [PATCH 09/18] Moved module to a different file Moved module to a different file and created a main script. --- gameio.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 54 ++--------------------------------------------------- 2 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 gameio.py diff --git a/gameio.py b/gameio.py new file mode 100644 index 0000000..7368aab --- /dev/null +++ b/gameio.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Module to interact with the game.""" + +import platform +from abc import ABC, abstractmethod + +import pyautogui + +PLATFORM_SYS = platform.system() + +if PLATFORM_SYS == "Windows": + import d3dshot + + +class AbstractGameIO(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.""" + pass + + @abstractmethod + def send_key(self, key: str): + """Presses a key on a virtual keyboard.""" + pass + + +class WindowsGameIO(AbstractGameIO): + 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 LinuxGameIO(AbstractGameIO): + """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 diff --git a/main.py b/main.py index a13fbaa..6524515 100644 --- a/main.py +++ b/main.py @@ -1,56 +1,6 @@ #!/usr/bin/env python3 """Main asteroid-automator script.""" -import platform -from abc import ABC, abstractmethod +import gameio -import pyautogui - -PLATFORM_SYS = platform.system() - -if PLATFORM_SYS == "Windows": - import d3dshot - - -class AbstractGameIO(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.""" - pass - - @abstractmethod - def send_key(self, key: str): - """Presses a key on a virtual keyboard.""" - pass - - -class WindowsGameIO(AbstractGameIO): - 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 LinuxGameIO(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 +# TODO: Add the main script itself From d04a0b172c6d6785c5e239d6d107358afa0eb4e0 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:33:57 +0200 Subject: [PATCH 10/18] Add key_up and key_down methods in GameIO Add key_up() and key_down() methods in GameIO. key_press() does the aforementioned two functions one after the other. --- gameio.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/gameio.py b/gameio.py index 7368aab..0ac2584 100644 --- a/gameio.py +++ b/gameio.py @@ -25,10 +25,22 @@ class AbstractGameIO(ABC): """Creates a screenshot, and returns it in Pillow format.""" pass + # TODO: Implement the following two functions in descendants. + @abstractmethod + def key_up(self, key: str): + """Holds a key on a virtual keyboard.""" + pass + + @abstractmethod + def key_up(self, key: str): + """Lets go of a key on a virtual keyboard.""" + pass + def send_key(self, key: str): """Presses a key on a virtual keyboard.""" - pass + self.key_up(key) + self.key_down(key) class WindowsGameIO(AbstractGameIO): @@ -39,8 +51,11 @@ class WindowsGameIO(AbstractGameIO): 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 + def key_up(self, key: str): + pass + + def key_up(self, key: str): + pass class LinuxGameIO(AbstractGameIO): @@ -52,5 +67,8 @@ class LinuxGameIO(AbstractGameIO): def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) - def send_key(self, key: str): - pass # TODO: Add send_key method + def key_up(self, key: str): + pass + + def key_up(self, key: str): + pass From d55ecef95355fd342a8fcc9befb4b32b819430ec Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:34:29 +0200 Subject: [PATCH 11/18] Fix naming oversight --- gameio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gameio.py b/gameio.py index 0ac2584..4a8cf34 100644 --- a/gameio.py +++ b/gameio.py @@ -33,7 +33,7 @@ class AbstractGameIO(ABC): pass @abstractmethod - def key_up(self, key: str): + def key_down(self, key: str): """Lets go of a key on a virtual keyboard.""" pass @@ -54,7 +54,7 @@ class WindowsGameIO(AbstractGameIO): def key_up(self, key: str): pass - def key_up(self, key: str): + def key_down(self, key: str): pass @@ -70,5 +70,5 @@ class LinuxGameIO(AbstractGameIO): def key_up(self, key: str): pass - def key_up(self, key: str): + def key_down(self, key: str): pass From 207761d498826ea09f6cca3b314d9172aff1ee44 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 07:32:56 +0200 Subject: [PATCH 12/18] Removed invalid documentation from LinuxGameIO --- gameio.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gameio.py b/gameio.py index 4a8cf34..e80b32c 100644 --- a/gameio.py +++ b/gameio.py @@ -59,8 +59,6 @@ class WindowsGameIO(AbstractGameIO): class LinuxGameIO(AbstractGameIO): - """Base class for each platform.""" - def __init__(self): super().__init__(self) From d7584421904da5da85adfdb6e289e0488fafc109 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 07:43:07 +0200 Subject: [PATCH 13/18] Create .gitignore with the Asteroids folder Create .gitignore with the Asteroids folder, for the ease of contributing. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87bebcf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +asteroids-master/ From cd91488a1b0f2a64364db9a26cb44414d79ace2a Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:15:41 +0200 Subject: [PATCH 14/18] Ignoring __pycache__/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 87bebcf..02b8935 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ asteroids-master/ +__pycache__/ From 82186e4a3a7c3a5a95c4da20753e0d3359699e27 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:16:09 +0200 Subject: [PATCH 15/18] Removed self from super().__init__(self) Removed self from super().__init__(self) in WindowsGameIO --- gameio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gameio.py b/gameio.py index e80b32c..32d70b3 100644 --- a/gameio.py +++ b/gameio.py @@ -45,7 +45,7 @@ class AbstractGameIO(ABC): class WindowsGameIO(AbstractGameIO): def __init__(self): - super().__init__(self) + super().__init__() self.d = d3dshot.create() def fetch_sshot(self): From 113d93773e33e01146755a79f9a444f6a372455c Mon Sep 17 00:00:00 2001 From: John McCardle Date: Mon, 20 Dec 2021 04:39:49 -0500 Subject: [PATCH 16/18] Removed self from super().__init__(self) in LinuxGameIO --- gameio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gameio.py b/gameio.py index 32d70b3..b1fad9e 100644 --- a/gameio.py +++ b/gameio.py @@ -60,7 +60,7 @@ class WindowsGameIO(AbstractGameIO): class LinuxGameIO(AbstractGameIO): def __init__(self): - super().__init__(self) + super().__init__() def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) From 05c29e7e7243d49f37cc916c8384d63d0f9666c6 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:12:34 +0200 Subject: [PATCH 17/18] Implemented key_up and key_down methods Implemented key_up and key_down methods in GameIO --- gameio.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/gameio.py b/gameio.py index b1fad9e..c18a035 100644 --- a/gameio.py +++ b/gameio.py @@ -25,17 +25,17 @@ class AbstractGameIO(ABC): """Creates a screenshot, and returns it in Pillow format.""" pass - # TODO: Implement the following two functions in descendants. + # feel free to change these two functions in the descendants @abstractmethod def key_up(self, key: str): """Holds a key on a virtual keyboard.""" - pass + pyautogui.keyUp(key) @abstractmethod def key_down(self, key: str): """Lets go of a key on a virtual keyboard.""" - pass + pyautogui.keyDown(key) def send_key(self, key: str): """Presses a key on a virtual keyboard.""" @@ -52,10 +52,10 @@ class WindowsGameIO(AbstractGameIO): return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) def key_up(self, key: str): - pass + pyautogui.keyUp(key) def key_down(self, key: str): - pass + pyautogui.keyDown(key) class LinuxGameIO(AbstractGameIO): @@ -64,9 +64,3 @@ class LinuxGameIO(AbstractGameIO): def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) - - def key_up(self, key: str): - pass - - def key_down(self, key: str): - pass From 7d0771832658d9eb17c7f60d47b6b527732d1e77 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Tue, 21 Dec 2021 00:58:59 -0500 Subject: [PATCH 18/18] Inheriting cross-platform keyboard methods (non-abstract) --- gameio.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/gameio.py b/gameio.py index c18a035..4b0602e 100644 --- a/gameio.py +++ b/gameio.py @@ -27,20 +27,17 @@ class AbstractGameIO(ABC): # feel free to change these two functions in the descendants - @abstractmethod def key_up(self, key: str): """Holds a key on a virtual keyboard.""" pyautogui.keyUp(key) - @abstractmethod def key_down(self, key: str): """Lets go of a key on a virtual keyboard.""" pyautogui.keyDown(key) def send_key(self, key: str): """Presses a key on a virtual keyboard.""" - self.key_up(key) - self.key_down(key) + pyautogui.press(key) class WindowsGameIO(AbstractGameIO): @@ -51,12 +48,6 @@ class WindowsGameIO(AbstractGameIO): def fetch_sshot(self): return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) - def key_up(self, key: str): - pyautogui.keyUp(key) - - def key_down(self, key: str): - pyautogui.keyDown(key) - class LinuxGameIO(AbstractGameIO): def __init__(self):