This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.py
66 lines (50 loc) · 1.72 KB
/
launcher.py
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
import subprocess
import os
def get_features_list(path_: str) -> list:
features = subprocess.run(
[path_, "--print-available-feature-flags"], stdout=subprocess.PIPE
).stdout.decode("utf-8")
features = features.split("\n")
returnlist = list()
for feature in features:
if feature.startswith("TRUE"):
feature = feature[5:]
if feature.startswith("FALSE"):
feature = feature[6:]
returnlist.append(feature)
return returnlist
def get_features_dict(path_: str) -> dict:
features = subprocess.run(
[path_, "--print-available-feature-flags"], stdout=subprocess.PIPE
).stdout.decode("utf-8")
features = features.split("\n")
returndict = dict()
for feature in features:
if feature.startswith("TRUE"):
feature = feature[5:]
returndict[feature] = True
if feature.startswith("FALSE"):
feature = feature[6:]
returndict[feature] = False
return returndict
def set_username(env, username: str = "meg"):
env["MCPI_USERNAME"] = username
return env
def set_render_distance(env, distance: str = "SHORT"):
if distance.upper() not in ["TINY", "SHORT", "NORMAL", "FAR"]:
raise Exception("Invalid render distance")
else:
env["MCPI_RENDER_DISTANCE"] = distance
return env
def set_hud(env, options: str = "fps,simple"):
env["GALLIUM_HUD"] = options
return env
def set_options(env, options: dict):
output = str()
for option in options:
if options[option]:
output += f"{option}|"
env["MCPI_FEATURE_FLAGS"] = output
return env
def run(env, path_: str):
return subprocess.Popen([path_], env=env, preexec_fn=os.setsid)