Skip to content

Commit

Permalink
Merge pull request #214 from lxgr-linux/213-audio-not-working-on-windows
Browse files Browse the repository at this point in the history
Switched music paths to ensure windows compatibility
  • Loading branch information
lxgr-linux authored Jul 23, 2022
2 parents e6fea3a + 0e48d4b commit 9e6db99
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 76 deletions.
5 changes: 2 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
57 changes: 13 additions & 44 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.

Expand Down
43 changes: 24 additions & 19 deletions pokete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions pokete_classes/audio.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"""This manages audio playback"""

import multiprocessing
from pathlib import Path
try:
from playsound import playsound
except ModuleNotFoundError:
from .dummy_playsound import playsound
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:
Expand Down
6 changes: 1 addition & 5 deletions pokete_general_use_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,22 +81,19 @@ 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)
else:
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__":
Expand Down

0 comments on commit 9e6db99

Please sign in to comment.