This repository was archived by the owner on Nov 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.py
More file actions
executable file
·120 lines (102 loc) · 4.84 KB
/
Copy pathplay.py
File metadata and controls
executable file
·120 lines (102 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
#
# Play a game.
#
import raehutils
import sys, os, argparse, logging
class PlayPy(raehutils.RaehBaseClass):
ERR_MATCH = 1
def __init__(self):
retroarch_cores_dir = os.environ.get("HOME") + "/.config/retroarch/cores"
games_dir = os.environ.get("HOME") + "/media/games-local"
self.games = {
"tome4": {
"name": "Tales of Maj'Eyal",
"cmd": ["tome4"]
},
"pokemon-emerald-jp": {
"name": "Pokemon Emerald (JP)",
"cmd": ["retroarch","-L",retroarch_cores_dir+"/vbam_libretro.so",games_dir+"/gba/official/Pocket Monsters - Emerald (Japan).gba"]
},
"melee": {
"name": "Super Smash Bros. Melee (20XX) [UFC]",
"cmd": [os.environ.get("HOME")+"/media/games-etc/platforms/pc/emulators/wii/faster-melee-v5.8.7-ucf-v0.73/dolphin-emu"]
},
"melee-no-ufc": {
"name": "Super Smash Bros. Melee (20XX)",
"cmd": [os.environ.get("HOME")+"/media/games-etc/platforms/pc/emulators/wii/faster-melee-v5.8.7/dolphin-emu"]
},
"melee-smashladder": {
"name": "Super Smash Bros. Melee [Netplay/Smashladder]",
"cmd": [os.environ.get("HOME")+"/media/games-etc/platforms/pc/emulators/wii/faster-melee-v5.9-fresh/dolphin-emu"]
},
"melee-uk-melee": {
"name": "Super Smash Bros. Melee [Netplay/UK Melee]",
"cmd": [os.environ.get("HOME")+"/media/games-etc/platforms/pc/emulators/wii/faster-melee-v5.8.7-fresh-uk-melee-ucf-v0.73/dolphin-emu"]
},
"retroarch": {
"name": "RetroArch (general)",
"cmd": ["retroarch"]
},
"mario-and-luigi-rpg": {
"name": "Mario & Luigi RPG (JP)",
"cmd": ["retroarch","-L",retroarch_cores_dir+"/vbam_libretro.so",games_dir+"/gba/official/mario-and-luigi-rpg-jp/1283 - Mario and Luigi RPG (J)(Rising Sun).gba"]
},
"elite-nes-pal": {
"name": "Elite (NES) (PAL)",
"cmd": ["retroarch","-L",retroarch_cores_dir+"/fceumm_libretro.so",games_dir+"/nes/official/elite/elite-pal.nes"]
},
}
self.workspace_num = "10"
## CLI-related {{{
def _parse_args(self):
self.parser = argparse.ArgumentParser(description="Play a game.")
self.parser.add_argument("-v", "--verbose", help="be verbose", action="count", default=0)
self.parser.add_argument("-q", "--quiet", help="be quiet (overrides -v)", action="count", default=0)
self.parser.add_argument("game", help="unique string of game to play")
self.args = self.parser.parse_args()
self._parse_verbosity()
## }}}
def main(self):
"""Main entrypoint after program initialisation."""
# get all possible matches
matches = [k for k, v in self.games.items() if k.startswith(self.args.game)]
if len(matches) < 1:
self.fail("no matching games for query: {}".format(self.args.game), PlayPy.ERR_MATCH)
if len(matches) > 1:
# if we found an exact match, override
exact_match = list(filter(lambda x: x == self.args.game, matches))
if len(exact_match) == 1:
matches = exact_match
else:
self.fail("query matches multiple games with no exact match: {}".format(", ".join(matches), PlayPy.ERR_MATCH))
game = self.games[matches[0]]
self.logger.info("matched game: {}".format(game["name"]))
self.logger.info("game cmd: {}".format(" ".join(game["cmd"])))
self.start_game(game)
def start_game(self, game):
"""Start a game."""
self.switch_workspace(self.workspace_num)
self.run_game_cmd(game["cmd"])
#self.float_game_window()
def switch_workspace(self, workspace_num):
"""Switch i3 workspace to the given worksapce."""
cmd_switch_workspace = ["i3-msg", "workspace", workspace_num]
raehutils.get_shell(cmd_switch_workspace)
# sleep a TINY bit (Dolphin comes up before we switch, somehow??)
#raehutils.get_shell(["sleep", "0.1"])
def float_game_window(self):
"""Float the game window (i3)."""
cmd_float_window = ["i3-msg", "floating", "enable"]
# sleep for a bit first to wait for the window to come up
raehutils.get_shell(["sleep", "1"])
raehutils.get_shell(cmd_float_window)
def run_game_cmd(self, cmd):
"""Run a shell command to start a game and detach."""
raehutils.run_shell_detached(cmd)
# alternative: don't detach, return return code
# maybe useful as a switch
#return raehutils.drop_to_shell(cmd)
if __name__ == "__main__":
program = PlayPy()
program.run()