Basic launcher

This commit is contained in:
leha-code 2022-03-04 20:43:14 -04:00
parent 711aefe243
commit 49b842941f
No known key found for this signature in database
GPG Key ID: 15227A6455DDF7EE
3 changed files with 37 additions and 11 deletions

View File

@ -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)

View File

@ -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__":

View File

@ -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.",
]