diff --git a/Pipfile b/Pipfile index 72acfa84..037f084a 100644 --- a/Pipfile +++ b/Pipfile @@ -5,9 +5,8 @@ name = "pypi" [packages] scrap-engine = ">=1.2.0" -pynput = {version = ">=1.7.6", sys_platform = "!= 'linux'"} -playsound = "*" -pygobject = "*" +playsound = "1.2.2" +pygobject = {version = "*", sys_platform = "== 'linux'"} [dev-packages] pylint = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 3268f0f4..2e9dc313 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8561aacc14033bb3586b5cf62752463bd8fd8cde03e97cadb445e69eda8e6639" + "sha256": "bbffb8ad1c59b9c0759afd52651d68f10b82019575a4795fc34dc1247b6c2b84" }, "pipfile-spec": 6, "requires": { @@ -23,37 +23,6 @@ "index": "pypi", "version": "==1.3.0" }, - "pycairo": { - "hashes": [ - "sha256:251907f18a552df938aa3386657ff4b5a4937dde70e11aa042bc297957f4b74b", - "sha256:26b72b813c6f9d495f71057eab89c13e70a21c92360e9265abc049e0a931fa39", - "sha256:31e1c4850db03201d33929cbe1905ce1b33202683ebda7bb0d4dba489115066b", - "sha256:4357f20a6b1de8f1e8072a74ff68ab4c9a0ae698cd9f5c0f2b2cdd9b28b635f6", - "sha256:44a2ecf34968de07b3b9dfdcdbccbd25aa3cab267200f234f84e81481a73bbf6", - "sha256:6d37375aab9f2bb6136f076c19815d72108383baae89fbc0d6cb8e5092217d02", - "sha256:70936b19f967fa3cb3cd200c2608911227fa5d09dae21c166f64bc15e714ee41", - "sha256:dace6b356c476de27f8e1522428ac21a799c225703f746e2957d441f885dcb6c", - "sha256:f63c153a9ea3d21aff85e2caeee4b0c5d566b2368b4ed64826020d12953d76a4" - ], - "markers": "python_version >= '3.7'", - "version": "==1.21.0" - }, - "pygobject": { - "hashes": [ - "sha256:80d6a3ad1630e9d1edf31b9e9fad9a894c57e18545a3c95ef0044ac4042b8620" - ], - "index": "pypi", - "version": "==3.42.1" - }, - "pynput": { - "hashes": [ - "sha256:19861b2a0c430d646489852f89500e0c9332e295f2c020e7c2775e7046aa2e2f", - "sha256:264429fbe676e98e9050ad26a7017453bdd08768adb25cafb918347cf9f1eb4a", - "sha256:3a5726546da54116b687785d38b1db56997ce1d28e53e8d22fc656d8b92e533c" - ], - "markers": "sys_platform != 'linux'", - "version": "==1.7.6" - }, "scrap-engine": { "hashes": [ "sha256:767ffdc312b550777771cdc9a350a9f6dca73855259dd1fe7197c8736e38cac1" @@ -65,11 +34,11 @@ "develop": { "astroid": { "hashes": [ - "sha256:4f933d0bf5e408b03a6feb5d23793740c27e07340605f236496cd6ce552043d6", - "sha256:ba33a82a9a9c06a5ceed98180c5aab16e29c285b828d94696bf32d6015ea82a9" + "sha256:86b0a340a512c65abf4368b80252754cda17c02cdbbd3f587dddf98112233e7b", + "sha256:bb24615c77f4837c707669d16907331374ae8a964650a66999da3f5ca68dc946" ], "markers": "python_full_version >= '3.6.2'", - "version": "==2.11.6" + "version": "==2.11.7" }, "dill": { "hashes": [ @@ -148,19 +117,19 @@ }, "pylint": { "hashes": [ - "sha256:482f1329d4b6b9e52599754a2e502c0ed91ebdfd0992a2299b7fa136a6c12349", - "sha256:592d0a4d2ffa8e33020209d255827c5a310499cdc023d156187bc677d86bd495" + "sha256:487ce2192eee48211269a0e976421f334cf94de1806ca9d0a99449adcdf0285e", + "sha256:fabe30000de7d07636d2e82c9a518ad5ad7908590fe135ace169b44839c15f90" ], "index": "pypi", - "version": "==2.14.2" + "version": "==2.14.5" }, "setuptools": { "hashes": [ - "sha256:5a844ad6e190dccc67d6d7411d119c5152ce01f7c76be4d8a1eaa314501bba77", - "sha256:bf8a748ac98b09d32c9a64a995a6b25921c96cc5743c1efa82763ba80ff54e91" + "sha256:0d33c374d41c7863419fc8f6c10bfe25b7b498aa34164d135c622e52580c6b16", + "sha256:c04b44a57a6265fe34a4a444e965884716d34bae963119a76353434d6f18e450" ], "markers": "python_version >= '3.7'", - "version": "==62.4.0" + "version": "==63.2.0" }, "tomli": { "hashes": [ @@ -172,11 +141,11 @@ }, "tomlkit": { "hashes": [ - "sha256:0f4050db66fd445b885778900ce4dd9aea8c90c4721141fde0d6ade893820ef1", - "sha256:71ceb10c0eefd8b8f11fe34e8a51ad07812cb1dc3de23247425fbc9ddc47b9dd" + "sha256:1c5bebdf19d5051e2e1de6cf70adfc5948d47221f097fcff7a3ffc91e953eaf5", + "sha256:61901f81ff4017951119cd0d1ed9b7af31c821d6845c8c477587bbdcd5e5854e" ], "markers": "python_version >= '3.6' and python_version < '4.0'", - "version": "==0.11.0" + "version": "==0.11.1" }, "wrapt": { "hashes": [ diff --git a/README.md b/README.md index 43223dd0..246392bb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Pokete is a small terminal based game in the style of a very popular and old game by Gamefreak. ## Installation -For Linux, run this: +For Linux, BSD etc. just do this: ```shell # pip install scrap_engine playsound pygobject $ git clone https://github.com/lxgr-linux/pokete.git @@ -38,11 +38,17 @@ Or you can just run the AppImage from the release page. NOTE: In that case you first have to create the `~/.cache/pokete/` folder. -For Windows and OS X: +For OSX: +```shell +# pip install scrap_engine playsound pyobjc +$ git clone https://github.com/lxgr-linux/pokete.git +$ ./pokete/pokete.py +``` +For Windows: ```shell git clone https://github.com/lxgr-linux/pokete.git -pip install scrap_engine pynput playsound pygobject +pip install scrap_engine playsound==1.2.2 ``` To run just execute `pokete.py`. diff --git a/pokete.py b/pokete.py index 3c556f7f..dbd20ed8 100755 --- a/pokete.py +++ b/pokete.py @@ -811,16 +811,9 @@ def read_save(): return _si -def on_press(key): - """Sets the input to either a character like 'a' or '1', or Key.enter, Key.backspace, Key.space, Key.esc, exit - ARGS: - key: Key object _ev is set from""" - _ev.set(str(key).strip("'")) - - def reset_terminal(): """Resets the terminals state""" - if sys.platform == "linux" and not force_pynput: + if sys.platform == "linux": termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) @@ -1389,9 +1382,30 @@ def map_additions(): # Actual code execution ####################### if __name__ == "__main__": - do_logging, load_mods, force_pynput = parse_args(sys.argv) + do_logging, load_mods = parse_args(sys.argv) # deciding on wich input to use - if sys.platform == "linux" and not force_pynput: + if sys.platform == "win32": + import msvcrt + + + def recogniser(): + """Gets keyboard input from msvcrt, the Microsoft Visual C++ Runtime""" + while True: + if msvcrt.kbhit(): + char = msvcrt.getwch() + _ev.set( + { + ord(char): f"{char.rstrip()}", + 13: "Key.enter", + 127: "Key.backspace", + 8: "Key.backspace", + 32: "Key.space", + 27: "Key.esc", + 3: "exit", + }[ord(char)] + ) + + else: import tty import termios import select @@ -1423,15 +1437,6 @@ def recogniser(): ) if ord(char) == 3: reset_terminal() - else: - from pynput.keyboard import Listener - - - def recogniser(): - """Gets keyboard input from pynput""" - while True: - with Listener(on_press=on_press) as listener: - listener.join() print("\033[?1049h") diff --git a/pokete_classes/audio.py b/pokete_classes/audio.py index ace03c0c..4fc252f5 100644 --- a/pokete_classes/audio.py +++ b/pokete_classes/audio.py @@ -1,6 +1,7 @@ """This manages audio playback""" import multiprocessing +from pathlib import Path try: from playsound import playsound except ModuleNotFoundError: @@ -8,13 +9,13 @@ from .settings import settings -MUSIC_PATH = __file__.replace("pokete_classes/audio.py", 'assets/music/') +MUSIC_PATH = Path(__file__).parents[1] / 'assets' / 'music' def audio_fn(song, play_audio): """plays a song in loop""" while play_audio: - playsound(MUSIC_PATH + song) + playsound(str(MUSIC_PATH / song)) class Audio: diff --git a/pokete_general_use_fns.py b/pokete_general_use_fns.py index 770c1e26..74cb9825 100644 --- a/pokete_general_use_fns.py +++ b/pokete_general_use_fns.py @@ -62,7 +62,6 @@ def print_help(path): --log : Enables logging --help : Shows this help --no_mods : Disables mods - --force_pynput : Forces the usage of pynput as a keyboard input backend Homepage: https://github.com/lxgr-linux/pokete @@ -82,14 +81,11 @@ def parse_args(args): Tuple of do_logging and load_mods""" do_logging = False load_mods = True - force_pynput = False for arg in args[1:]: if arg == "--log": do_logging = True elif arg == "--no_mods": load_mods = False - elif arg == "--force_pynput": - force_pynput = True elif arg == "--help": print_help(args[0]) sys.exit(0) @@ -97,7 +93,7 @@ def parse_args(args): print(f":: Error: '{arg}' is not a valid option! See '--help' for \ options.") sys.exit(1) - return do_logging, load_mods, force_pynput + return do_logging, load_mods if __name__ == "__main__":