Skip to content

Commit

Permalink
Merge pull request #26 from German-Immersive-Railroading-Community/be…
Browse files Browse the repository at this point in the history
…taSelection

feature: Beta selection.

- Ability to start the Launcher with the `-eb` and `--enable-beta` startup parameters, which enable the beta area in the `OptionsScene`.
- Ability to select all currently open pull requests that are returned by the `beta.json` and select one to test.
- Ability to dynamically change the `servers.dat` file to include the test server to the corresponding pull request.
- Ability to start the game with the mod that should be tested instead of the original.
  • Loading branch information
Shirosaka authored Aug 27, 2021
2 parents b076cdf + de38612 commit ea1ae9a
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 16 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@
<id>repo2</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>

<dependency>
<groupId>com.github.Querz</groupId>
<artifactId>NBT</artifactId>
<version>6.1</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/troblecodings/launcher/LaunchSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
public class LaunchSystem {

public static final String DO_NOT_UPDATE = "--no-update";
public static final String[] ENABLE_BETA = new String[] { "-eb", "--enable-beta" };

public static void main(String[] args) {
FileUtil.readSettings();
Launcher.initializeLogger();

if(Arrays.stream(args).noneMatch(s -> s.equals(DO_NOT_UPDATE))) {
Launcher.getLogger().info("Checking for updates...");
StartupUtil.update();
} else {
Launcher.getLogger().info("Skipping updates!");
}

if(Arrays.stream(ENABLE_BETA).anyMatch(s -> Arrays.asList(args).contains(s))) {
Launcher.getLogger().info("Enabling beta features.");
Launcher.setBetaMode(true);
StartupUtil.refreshBetaJson();
}

Runtime.getRuntime().addShutdownHook(Launcher.SHUTDOWNHOOK);
FileUtil.init();
Launcher.launch(Launcher.class, args);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/troblecodings/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public static final void initializeLogger() {
LOGGER = LogManager.getLogger("GIRC");
LOGGER.info("Starting Launcher!");
}

private static boolean BETA_MODE = false;

public static void setBetaMode(boolean betaMode) {
if(BETA_MODE == betaMode)
return;

Launcher.getLogger().info("Changed beta mode: " + BETA_MODE + " → " + betaMode);
BETA_MODE = betaMode;
}

public static boolean getBetaMode() {
return BETA_MODE;
}

public static final Thread SHUTDOWNHOOK = new Thread(FileUtil::saveSettings);

Expand Down Expand Up @@ -152,7 +166,6 @@ public static void onError(Throwable e) {
LOGGER.error("Error found but was passed null!");
return;
} else if (e.getMessage() == null)

LOGGER.trace("", e);
else
LOGGER.trace(e.getMessage(), e);
Expand Down
61 changes: 54 additions & 7 deletions src/main/java/com/troblecodings/launcher/javafx/OptionsScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import com.troblecodings.launcher.Launcher;
import com.troblecodings.launcher.assets.Assets;
import com.troblecodings.launcher.util.AuthUtil;
import com.troblecodings.launcher.util.BetaInfo;
import com.troblecodings.launcher.util.FileUtil;
import com.troblecodings.launcher.util.StartupUtil;

import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
Expand All @@ -29,7 +31,8 @@

public class OptionsScene extends Scene {

private static StackPane stackpane = new StackPane();
private static final StackPane stackpane = new StackPane();
private static final ComboBox<BetaInfo> betaComboBox = new ComboBox<>();

public OptionsScene() {
super(stackpane);
Expand Down Expand Up @@ -93,7 +96,7 @@ public OptionsScene() {
// javaversion selection

final Label javaversion = new Label("Javaversion");
javaversion.setStyle("-fx-padding: 0px 0px 10px 0px;");
javaversion.setStyle("-fx-padding: 20px 0px 10px 0px;");

final TextField javaversionfield = new TextField(FileUtil.SETTINGS.javaPath);
javaversionfield.setEditable(false);
Expand Down Expand Up @@ -172,11 +175,55 @@ public OptionsScene() {
vbox.getChildren().addAll(ramlabel, ramcombobox, resolution, resolutioncombobox, baseDir, hbox, lar, logouthbox,
javaversion, javaversion1);

ImageView settingstrainview = new ImageView(Assets.getImage("train3.png"));
settingstrainview.setScaleX(-1);
settingstrainview.setTranslateX((-1280/1.75) + settingstrainview.getImage().getWidth());
settingstrainview.setTranslateY(360 - settingstrainview.getImage().getHeight());
stackpane.getChildren().add(settingstrainview);
if(Launcher.getBetaMode()) {
final Label betaLabel = new Label("Beta Version Selection");
betaLabel.setStyle("-fx-padding: 20px 0px 10px 0px");

final Button betaRefreshButton = new Button("Refresh");
betaRefreshButton.getStyleClass().add("optionButton");
betaRefreshButton.setOnAction(ev -> {
StartupUtil.setActiveBeta(null);
betaComboBox.getSelectionModel().clearSelection();
betaComboBox.getItems().clear();
betaComboBox.getItems().addAll(StartupUtil.getBetaVersions(true));
});

final Button betaClearButton = new Button("Clear");
betaClearButton.getStyleClass().add("optionButton");
betaClearButton.setOnAction(ev -> {
StartupUtil.setActiveBeta(null);
betaComboBox.getSelectionModel().clearSelection();
betaComboBox.getItems().clear();
});

betaComboBox.setEditable(true);
betaComboBox.setPrefWidth(vbox.getPrefWidth());
betaComboBox.getItems().addAll(StartupUtil.getBetaVersions(false));
betaComboBox.setOnAction(ev -> {
int index = betaComboBox.getSelectionModel().selectedIndexProperty().get();

if(index < 0)
return;

BetaInfo selectedInfo = betaComboBox.getItems().get(index);
StartupUtil.setActiveBeta(selectedInfo);
Launcher.getLogger().info("Selected beta: " + selectedInfo.toString());
});

final HBox betaHBox = new HBox(10);
betaHBox.setStyle("-fx-padding: 15px 0px 10px 0px");
betaHBox.setPrefWidth(hbox.getPrefWidth());
betaHBox.setAlignment(Pos.CENTER);
betaHBox.getChildren().addAll(betaRefreshButton, betaClearButton);

vbox.getChildren().addAll(betaLabel, betaComboBox, betaHBox);
}

ImageView settingsTrainView = new ImageView(Assets.getImage("train3.png"));
settingsTrainView.setScaleX(-1);
settingsTrainView.setTranslateX((-1280/1.75) + settingsTrainView.getImage().getWidth());
settingsTrainView.setTranslateY(360 - settingsTrainView.getImage().getHeight());
stackpane.getChildren().add(settingsTrainView);
}

}
46 changes: 46 additions & 0 deletions src/main/java/com/troblecodings/launcher/util/BetaInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.troblecodings.launcher.util;

public class BetaInfo {
private final String modName;
private final int prNum;
private final String prName;
private final String prDownload;
private final int prPort;

public BetaInfo(String modName, int prNum, String prName, String prDownload, int prPort) {
this.modName = modName;
this.prNum = prNum;
this.prName = prName;
this.prDownload = prDownload;
this.prPort = prPort;
}

public String getModName() {
return this.modName;
}

public int getPrNum() {
return this.prNum;
}

public String getPrName() {
return this.prName;
}

public String getPrDownload() {
return this.prDownload;
}

public int getPrPort() {
return this.prPort;
}

public String getJarFileName() {
return modName + "-" + prNum + ".jar";
}

@Override
public String toString() {
return modName + " - #" + prNum + ": " + prName;
}
}
Loading

0 comments on commit ea1ae9a

Please sign in to comment.