2022-04-15 11:34:38 +00:00
|
|
|
"""
|
|
|
|
Copyright (C) 2022 Alexey Pavlov
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
2022-03-05 00:43:14 +00:00
|
|
|
import subprocess
|
2022-03-02 01:39:02 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
2022-03-12 23:18:20 +00:00
|
|
|
def get_features_list(path_: str) -> list:
|
2022-03-12 01:14:27 +00:00
|
|
|
features = subprocess.run(
|
2022-03-14 13:18:58 +00:00
|
|
|
[path_, "--print-available-feature-flags"], stdout=subprocess.PIPE
|
2022-03-12 01:14:27 +00:00
|
|
|
).stdout.decode("utf-8")
|
2022-03-10 01:17:29 +00:00
|
|
|
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)
|
2022-03-12 01:14:27 +00:00
|
|
|
|
2022-03-10 01:17:29 +00:00
|
|
|
return returnlist
|
2022-03-12 01:14:27 +00:00
|
|
|
|
2022-03-10 01:17:29 +00:00
|
|
|
|
2022-03-12 23:18:20 +00:00
|
|
|
def get_features_dict(path_: str) -> dict:
|
2022-03-12 01:14:27 +00:00
|
|
|
features = subprocess.run(
|
2022-03-14 13:18:58 +00:00
|
|
|
[path_, "--print-available-feature-flags"], stdout=subprocess.PIPE
|
2022-03-12 01:14:27 +00:00
|
|
|
).stdout.decode("utf-8")
|
2022-03-10 01:17:29 +00:00
|
|
|
features = features.split("\n")
|
|
|
|
returndict = dict()
|
|
|
|
for feature in features:
|
|
|
|
if feature.startswith("TRUE"):
|
|
|
|
feature = feature[5:]
|
2022-03-12 01:14:27 +00:00
|
|
|
returndict[feature] = True
|
2022-03-10 01:17:29 +00:00
|
|
|
if feature.startswith("FALSE"):
|
|
|
|
feature = feature[6:]
|
|
|
|
returndict[feature] = False
|
|
|
|
return returndict
|
2022-03-02 01:39:02 +00:00
|
|
|
|
|
|
|
|
2022-03-12 01:14:27 +00:00
|
|
|
def set_username(env, username: str = "StevePi"):
|
2022-03-04 01:13:35 +00:00
|
|
|
env["MCPI_USERNAME"] = username
|
|
|
|
return env
|
2022-03-02 01:39:02 +00:00
|
|
|
|
|
|
|
|
2022-03-12 01:14:27 +00:00
|
|
|
def set_render_distance(env, distance: str = "SHORT"):
|
2022-03-02 01:39:02 +00:00
|
|
|
if distance.upper() not in ["TINY", "SHORT", "NORMAL", "FAR"]:
|
|
|
|
raise Exception("Invalid render distance")
|
|
|
|
else:
|
2022-03-05 00:43:14 +00:00
|
|
|
env["MCPI_RENDER_DISTANCE"] = distance
|
2022-03-04 01:13:35 +00:00
|
|
|
return env
|
2022-03-02 01:39:02 +00:00
|
|
|
|
|
|
|
|
2022-03-12 01:14:27 +00:00
|
|
|
def set_hud(env, options: str = "fps,simple"):
|
2022-03-04 01:13:35 +00:00
|
|
|
env["GALLIUM_HUD"] = options
|
|
|
|
return env
|
2022-03-02 01:39:02 +00:00
|
|
|
|
|
|
|
|
2022-03-10 01:17:29 +00:00
|
|
|
def set_options(env, options: dict):
|
2022-03-02 01:39:02 +00:00
|
|
|
output = str()
|
|
|
|
for option in options:
|
2022-03-05 00:43:14 +00:00
|
|
|
if options[option]:
|
|
|
|
output += f"{option}|"
|
2022-03-02 01:39:02 +00:00
|
|
|
|
2022-03-04 01:13:35 +00:00
|
|
|
env["MCPI_FEATURE_FLAGS"] = output
|
|
|
|
return env
|
2022-03-12 01:14:27 +00:00
|
|
|
|
|
|
|
|
2022-03-14 13:18:58 +00:00
|
|
|
def run(env, path_: str):
|
|
|
|
return subprocess.Popen([path_], env=env, preexec_fn=os.setsid)
|