Skip to content
Snippets Groups Projects
Commit 74504e06 authored by Tran Peter's avatar Tran Peter
Browse files

refactor(Main): seperating main and start method as application won't start if exported to jar

parent 5ce47245
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!27Player can now place bombs that have a explosion radius that dont go through the wall.,!20Merge ui into development
package de.hdm_stuttgart.battlearena.Main;
import de.hdm_stuttgart.battlearena.Model.Sound.SoundManager;
import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Objects;
public class Driver extends Application {
private static final Logger log = LogManager.getLogger(Driver.class);
Rectangle2D screen = Screen.getPrimary().getVisualBounds();
InputHandler inputHandler = InputHandler.getInstance();
SoundManager soundManager = new SoundManager();
@Override
public void start(Stage stage) throws Exception {
// loading font in start() because CSS can't handle whitespace in folder names
Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/AmaticSC-Bold.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/Arthemis-mLA22.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/ShadowsIntoLight-Regular.ttf"), 50);
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/LoadingScreen.fxml")));
Scene scene = new Scene(root);
scene.setOnKeyPressed(inputHandler::handleKeyPress);
scene.setOnKeyReleased(inputHandler::handleKeyRelease);
stage.setTitle("BattleArena");
stage.getIcons().add(new Image("file:src/main/resources/textures/images/icon.png"));
stage.setScene(scene);
stage.minHeightProperty().setValue(400);
stage.minWidthProperty().setValue(600);
stage.setMaximized(true);
stage.setWidth(screen.getWidth());
stage.setHeight(screen.getHeight());
stage.initStyle(StageStyle.UNDECORATED);
scene.getStylesheets().add(Objects.requireNonNull(this.getClass().getResource("/styles/style.css")).toExternalForm());
stage.setScene(scene);
stage.setOnCloseRequest(event -> {
if (soundManager != null) {
soundManager.stopMusic();
}
});
stage.show();
log.debug("Project started successfully!");
// Exiting program if an exception occurs
// Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
// log.error(throwable.getMessage());
// System.exit(1);
// });
}
}
\ No newline at end of file
package de.hdm_stuttgart.battlearena.Main;
import de.hdm_stuttgart.battlearena.Model.Sound.MusicType;
import de.hdm_stuttgart.battlearena.Model.Sound.SFX;
import de.hdm_stuttgart.battlearena.Model.Sound.SoundManager;
import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Objects;
public class Main extends Application {
private static final Logger log = LogManager.getLogger(Main.class);
Rectangle2D screen = Screen.getPrimary().getVisualBounds();
InputHandler inputHandler = InputHandler.getInstance();
SoundManager soundManager = new SoundManager();
public class Main {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
// loading font in start() because CSS can't handle whitespace in folder names
Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/AmaticSC-Bold.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/Arthemis-mLA22.ttf"), 50);
Font.loadFont(getClass().getResourceAsStream("/fonts/ShadowsIntoLight-Regular.ttf"), 50);
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/LoadingScreen.fxml")));
Scene scene = new Scene(root);
scene.setOnKeyPressed(inputHandler::handleKeyPress);
scene.setOnKeyReleased(inputHandler::handleKeyRelease);
stage.setTitle("BattleArena");
stage.getIcons().add(new Image("file:src/main/resources/textures/images/icon.png"));
stage.setScene(scene);
stage.minHeightProperty().setValue(400);
stage.minWidthProperty().setValue(600);
stage.setMaximized(true);
stage.setWidth(screen.getWidth());
stage.setHeight(screen.getHeight());
stage.initStyle(StageStyle.UNDECORATED);
scene.getStylesheets().add(Objects.requireNonNull(this.getClass().getResource("/styles/style.css")).toExternalForm());
stage.setScene(scene);
stage.setOnCloseRequest(event -> {
if (soundManager != null) {
soundManager.stopMusic();
}
});
stage.show();
log.debug("Project started successfully!");
// Exiting program if an exception occurs
// Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
// log.error(throwable.getMessage());
// System.exit(1);
// });
Application.launch(Driver.class, args);
}
}
\ No newline at end of file
}
{
"playerName": "Player1",
"accountPassword": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"accountType": "ONLINE"
"accountType": "LOCAL"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment