Moved module to a different file
Moved module to a different file and created a main script.
This commit is contained in:
parent
30a45e6b47
commit
1a1e8efef8
|
@ -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
|
54
main.py
54
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
|
||||
|
|
Loading…
Reference in New Issue