diff --git a/planet/launcher.py b/planet/launcher.py index 8a05e73..aa388c7 100644 --- a/planet/launcher.py +++ b/planet/launcher.py @@ -1,3 +1,4 @@ +import subprocess import os FEATURES = [ @@ -69,20 +70,20 @@ DEFAULT_FEATURES = { } -def set_username(env, username: str): +def set_username(env, username: str = "StevePi"): env["MCPI_USERNAME"] = username return env -def set_render_distance(env, distance: str): +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.upper() + env["MCPI_RENDER_DISTANCE"] = distance return env -def set_hud(env, options: str): +def set_hud(env, options: str = "fps,simple"): env["GALLIUM_HUD"] = options return env @@ -90,7 +91,11 @@ def set_hud(env, options: str): def set_options(env, options: dict = DEFAULT_FEATURES): output = str() for option in options: - output += f"{str(options[option]).upper()} {option}\n" + if options[option]: + output += f"{option}|" env["MCPI_FEATURE_FLAGS"] = output return env + +def run(env): + return subprocess.Popen(['/usr/bin/minecraft-pi-reborn-client'], env=env, preexec_fn=os.setsid) diff --git a/planet/main.py b/planet/main.py index a0f3d8d..9ccb9e4 100644 --- a/planet/main.py +++ b/planet/main.py @@ -28,6 +28,7 @@ import os import random from datetime import date import json +import subprocess from PyQt5.QtCore import * @@ -47,6 +48,10 @@ else: class Planet(QMainWindow): + + launchfeatures = dict() + env = os.environ.copy() + def __init__(self): super().__init__() @@ -111,6 +116,9 @@ class Planet(QMainWindow): self.showlauncher = QRadioButton("Hide Launcher") self.playbutton = QPushButton("Play") + + self.playbutton.setCheckable(True) + self.playbutton.clicked.connect(self.launch) layout.addWidget(namelabel, 0, 0, 2, 6) layout.addWidget(splashlabel, 2, 0, 1, 6) @@ -146,7 +154,9 @@ class Planet(QMainWindow): checkbox.setCheckState(Qt.Checked) else: checkbox.setCheckState(Qt.Unchecked) - + + checkbox.clicked.connect(self.set_features) + self.features[feature] = checkbox layout.addWidget(checkbox) @@ -197,10 +207,22 @@ class Planet(QMainWindow): widget.setLayout(fakelayout) return widget - - + + def set_features(self): + for feature in self.features: + if self.features[feature].isChecked(): + self.launchfeatures[feature] = True + else: + self.launchfeatures[feature] = False + def launch(self): - pass + self.env = launcher.set_username(self.env, self.usernameedit.text()) + self.env = launcher.set_options(self.env, self.launchfeatures) + self.env = launcher.set_render_distance(self.env, self.distancebox.currentText()) + + print(self.env) + + launcher.run(self.env) if __name__ == "__main__": diff --git a/planet/splashes.py b/planet/splashes.py index a854063..34d0dd2 100644 --- a/planet/splashes.py +++ b/planet/splashes.py @@ -9,6 +9,5 @@ SPLASHES = [ "I use Planet BTW", "Snowball", "Robo", - "If I could, I would. But I can't, so I shan't.", - "I make a launcher! I break the launcher! Everyone hates it! Everyone hates it?", + "If I could, I would. But I can't, so I shan't.", ]