This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Implements User Settings #23
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
src/main/java/com/github/codestorm/bounceverse/core/SettingsManager.java
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
src/main/java/com/github/codestorm/bounceverse/core/UserSetting.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/codestorm/bounceverse/core/settings/GameSettingsManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? 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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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); | |
| } |
Comment on lines
+45
to
+46
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
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
AI
Nov 4, 2025
There was a problem hiding this comment.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.