Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/main/java/com/github/codestorm/bounceverse/Bounceverse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.codestorm.bounceverse;

import com.almasb.fxgl.app.GameApplication;
import com.github.codestorm.bounceverse.core.*;
import com.almasb.fxgl.app.GameSettings;
import com.github.codestorm.bounceverse.core.settings.GameSettingsManager;
import com.github.codestorm.bounceverse.core.settings.LaunchOptionsManager;
import com.github.codestorm.bounceverse.core.systems.*;
import com.github.codestorm.bounceverse.typing.exceptions.BounceverseException;
import java.io.IOException;
Expand All @@ -19,27 +21,32 @@
*/
public final class Bounceverse extends GameApplication {
public static void main(String[] args) {
LaunchOptions.load(args);
LaunchOptionsManager.load(args);
launch(args);
}

@Override
protected void initSettings(com.almasb.fxgl.app.GameSettings settings) {
protected void initSettings(GameSettings settings) {
try {
SettingsManager.load(settings);
GameSettingsManager.loadTo(settings);
} catch (IOException e) {
throw new BounceverseException(e);
}
}

@Override
protected void initGame() {
GameSystem.getInstance().apply();
protected void initInput() {
InputSystem.getInstance().apply();
}

@Override
protected void initInput() {
InputSystem.getInstance().apply();
protected void onPreInit() {
AppEventSystem.getInstance().apply();
}

@Override
protected void initGame() {
GameSystem.getInstance().apply();
}

@Override
Expand Down

This file was deleted.

106 changes: 0 additions & 106 deletions src/main/java/com/github/codestorm/bounceverse/core/UserSetting.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.github.codestorm.bounceverse.core.settings;

import com.almasb.fxgl.app.ApplicationMode;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.app.ReadOnlyGameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.github.codestorm.bounceverse.Utilities;
import com.github.codestorm.bounceverse.factory.SceneFactory;
import java.io.IOException;

/**
*
*
* <h1>{@link GameSettingsManager}</h1>
*
* Trình quản lý việc loadTo {@link GameSettings}. <br>
*
* @see UserSettingsManager
*/
public final class GameSettingsManager {
private GameSettingsManager() {}

/**
* Tải các settings từ file đã thiết lập vào CTDL. <br>
* <b>Chú ý: Cần loadTo {@link LaunchOptionsManager#load(String...)} trước khi tải.</b>
*
* @param settings Nơi tải vào
* @throws IOException if an error occurred when reading from the input stream.
*/
public static void loadTo(GameSettings settings) throws IOException {
final var gameSettings = Utilities.IO.loadProperties("/settings.properties");

// ? General
settings.setTitle(gameSettings.getProperty("general.name"));
settings.setVersion(gameSettings.getProperty("general.version"));
settings.setCredits(Utilities.IO.readTextFile("credits.txt"));
settings.setApplicationMode(
Boolean.parseBoolean(gameSettings.getProperty("general.devMode"))
? ApplicationMode.DEVELOPER
: (LaunchOptionsManager.getOptions().debug())
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential NullPointerException if LaunchOptionsManager.getOptions() returns null. This can occur if GameSettingsManager.loadTo() is called before LaunchOptionsManager.load() is invoked. Although the documentation mentions this requirement, consider adding a null check or initializing with a default LaunchOptions value to make the code more robust.

Suggested change
: (LaunchOptionsManager.getOptions().debug())
: (LaunchOptionsManager.getOptions() != null && LaunchOptionsManager.getOptions().debug())

Copilot uses AI. Check for mistakes.
? ApplicationMode.DEBUG
: ApplicationMode.RELEASE);

// ? Display
settings.setWidth(Integer.parseInt(gameSettings.getProperty("logic.width")));
settings.setHeight(Integer.parseInt(gameSettings.getProperty("logic.height")));
Comment on lines +45 to +46
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential uncaught 'java.lang.NumberFormatException'.

Suggested change
settings.setWidth(Integer.parseInt(gameSettings.getProperty("logic.width")));
settings.setHeight(Integer.parseInt(gameSettings.getProperty("logic.height")));
try {
settings.setWidth(Integer.parseInt(gameSettings.getProperty("logic.width")));
} catch (NumberFormatException e) {
System.err.println("Invalid value for logic.width: " + gameSettings.getProperty("logic.width") + ". Using default width 800.");
settings.setWidth(800);
}
try {
settings.setHeight(Integer.parseInt(gameSettings.getProperty("logic.height")));
} catch (NumberFormatException e) {
System.err.println("Invalid value for logic.height: " + gameSettings.getProperty("logic.height") + ". Using default height 600.");
settings.setHeight(600);
}

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +46
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential uncaught 'java.lang.NumberFormatException'.

Suggested change
settings.setWidth(Integer.parseInt(gameSettings.getProperty("logic.width")));
settings.setHeight(Integer.parseInt(gameSettings.getProperty("logic.height")));
try {
settings.setWidth(Integer.parseInt(gameSettings.getProperty("logic.width")));
} catch (NumberFormatException e) {
System.err.println("Invalid value for logic.width: " + gameSettings.getProperty("logic.width") + ". Using default width 800.");
settings.setWidth(800);
}
try {
settings.setHeight(Integer.parseInt(gameSettings.getProperty("logic.height")));
} catch (NumberFormatException e) {
System.err.println("Invalid value for logic.height: " + gameSettings.getProperty("logic.height") + ". Using default height 600.");
settings.setHeight(600);
}

Copilot uses AI. Check for mistakes.
settings.setFullScreenAllowed(true);

// ? In-game
settings.setSceneFactory(new SceneFactory());
settings.setMainMenuEnabled(true);
settings.setIntroEnabled(true);
}

/**
* Lây settings trong game.
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Lây' to 'Lấy'.

Suggested change
* Lây settings trong game.
* Lấy settings trong game.

Copilot uses AI. Check for mistakes.
*
* @return Settings trong game (Read-only)
*/
public static ReadOnlyGameSettings get() {
return FXGL.getSettings();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.github.codestorm.bounceverse.core;
package com.github.codestorm.bounceverse.core.settings;

import com.github.codestorm.bounceverse.Utilities;
import com.github.codestorm.bounceverse.typing.records.LaunchOptions;

/**
*
*
* <h1>{@link LaunchOptions}</h1>
* <h1>{@link LaunchOptionsManager}</h1>
*
* Các tùy chọn khi khởi động được áp dụng trong game. <br>
* Sử dụng {@link #load(String...)} để tải các options.
*/
public final class LaunchOptions {
private static boolean debug = false;
public final class LaunchOptionsManager {
private static LaunchOptions options;

private LaunchOptions() {}
private LaunchOptionsManager() {}

/**
* Tải các launch options từ Command-line Arguments.
Expand All @@ -23,10 +24,10 @@ private LaunchOptions() {}
public static void load(String... args) {
final var map = Utilities.IO.parseArgs(args, null, null);

debug = Boolean.parseBoolean(map.getOrDefault("debug", "false"));
options = new LaunchOptions(Boolean.parseBoolean(map.getOrDefault("debug", "false")));
}

public static boolean isDebug() {
return debug;
public static LaunchOptions getOptions() {
return options;
}
}
Loading
Loading