aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/Driver.java71
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/DiffEditor.java8
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/DiffList.java16
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/LevelEditor.java24
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/LevelList.java26
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/NotesEditor.java8
-rw-r--r--src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java12
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gameplay/ScoreController.java (renamed from src/main/java/net/sowgro/npehero/main/ScoreController.java)8
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gameplay/SongPlayer.java20
-rw-r--r--src/main/java/net/sowgro/npehero/gui/ControlEditor.java38
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/GameOver.java14
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LeaderboardView.java (renamed from src/main/java/net/sowgro/npehero/gui/Leaderboard.java)10
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelDetails.java16
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelSelector.java12
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelSurround.java31
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/MainMenu.java14
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/SettingsEditor.java (renamed from src/main/java/net/sowgro/npehero/gui/Settings.java)26
-rw-r--r--src/main/java/net/sowgro/npehero/main/Control.java39
-rw-r--r--src/main/java/net/sowgro/npehero/main/Difficulties.java81
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Difficulty.java259
-rw-r--r--src/main/java/net/sowgro/npehero/main/JSONFile.java101
-rw-r--r--src/main/java/net/sowgro/npehero/main/Leaderboard.java96
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Level.java281
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/LevelController.java87
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Levels.java74
-rw-r--r--src/main/java/net/sowgro/npehero/main/Notes.java5
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Settings.java48
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/SettingsController.java57
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Sound.java (renamed from src/main/java/net/sowgro/npehero/main/SoundController.java)27
-rwxr-xr-xsrc/main/resources/net/sowgro/npehero/style.css15
30 files changed, 729 insertions, 795 deletions
diff --git a/src/main/java/net/sowgro/npehero/Driver.java b/src/main/java/net/sowgro/npehero/Driver.java
index 2a1bdc3..1c6409a 100755
--- a/src/main/java/net/sowgro/npehero/Driver.java
+++ b/src/main/java/net/sowgro/npehero/Driver.java
@@ -1,33 +1,34 @@
package net.sowgro.npehero;
+import javafx.animation.*;
import javafx.application.Application;
-import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
-import javafx.scene.layout.Background;
-import javafx.scene.layout.BackgroundImage;
-import javafx.scene.layout.BackgroundPosition;
-import javafx.scene.layout.BackgroundRepeat;
-import javafx.scene.layout.BackgroundSize;
-import javafx.scene.layout.Pane;
+import javafx.scene.layout.*;
import javafx.stage.Stage;
+import javafx.util.Duration;
import net.sowgro.npehero.main.Control;
import net.sowgro.npehero.gui.MainMenu;
-import net.sowgro.npehero.main.LevelController;
-import net.sowgro.npehero.main.SettingsController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Levels;
+import net.sowgro.npehero.main.Settings;
+import net.sowgro.npehero.main.Sound;
import java.net.URL;
public class Driver extends Application
{
+ public static final Image MENU_BACKGROUND = new Image(Driver.class.getResource("mountains.png").toExternalForm());;
+
public static Stage primaryStage;
static ScrollPane primaryPane = new ScrollPane();
+ static ImageView backgroundImage = new ImageView();
+ static ImageView backgroundImage2 = new ImageView();
/*
* starts javafx
@@ -44,13 +45,20 @@ public class Driver extends Application
@Override
public void start(Stage newPrimaryStage)
{
- SettingsController.read();
- LevelController.readData();
+ Settings.read();
+ Levels.readData();
Control.readFromFile();
primaryStage = newPrimaryStage;
- Scene primaryScene = new Scene(primaryPane, 800,600);
+ StackPane root = new StackPane(backgroundImage2, backgroundImage, primaryPane);
+ Scene primaryScene = new Scene(root, 800,600);
+
+// Cant figure out how to center this
+ backgroundImage.fitHeightProperty().bind(primaryScene.heightProperty());
+ backgroundImage2.fitHeightProperty().bind(primaryScene.heightProperty());
+ backgroundImage.setPreserveRatio(true);
+ backgroundImage2.setPreserveRatio(true);
primaryScene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
@@ -62,7 +70,7 @@ public class Driver extends Application
setMenu(new MainMenu());
setMenuBackground();
- SoundController.playSong(SoundController.MENUSONG);
+ Sound.playSong(Sound.MENU_SONG);
primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> { //full screen stuff
if (KeyCode.F11.equals(event.getCode())) {
@@ -94,23 +102,38 @@ public class Driver extends Application
}
/**
- * replaces the background image with a new one
- * @param image the url of the image to set
+ * Replaces the background image with a new one.
+ * @param image The image to set.
*/
public static void setBackground(Image image) //replaces background with a new one
{
- primaryPane.setBackground(new Background(
- new BackgroundImage(
- image,
- BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT,
- new BackgroundPosition(Side.LEFT, 0, true, Side.BOTTOM, 0, true),
- new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, false, true)
- )));
+ // TODO center on screen
+ if (image == backgroundImage.getImage()) {
+ return;
+ }
+ backgroundImage2.setImage(image);
+ FadeTransition ft = new FadeTransition(Duration.seconds(0.2), backgroundImage);
+ ft.setInterpolator(Interpolator.EASE_BOTH);
+ ft.setFromValue(1.0);
+ ft.setToValue(0.0);
+ ft.setOnFinished(_ -> {
+ backgroundImage.setImage(image);
+ });
+
+ ScaleTransition st = new ScaleTransition(Duration.seconds(0.2), backgroundImage2);
+ st.setInterpolator(Interpolator.EASE_BOTH);
+ st.setFromX(1.05);
+ st.setFromY(1.05);
+ st.setToX(1.0);
+ st.setToY(1.0);
+
+ ParallelTransition pt = new ParallelTransition(ft, st);
+ pt.play();
}
public static void setMenuBackground()
{
- setBackground(new Image(Driver.class.getResource("mountains.png").toExternalForm()));
+ setBackground(MENU_BACKGROUND);
}
public static URL getResource(String fileName) {
diff --git a/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java b/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
index 84abf6f..4d2fc4e 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
@@ -15,7 +15,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Note;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class DiffEditor extends Pane
{
@@ -58,7 +58,7 @@ public class DiffEditor extends Pane
});
Button editScores = new Button("Clear leaderboard");
- editScores.setOnAction(e -> diff.getLeaderboard().clear());
+ editScores.setOnAction(e -> diff.leaderboard.entries.clear());
Button playLevel = new Button("Play level");
playLevel.setOnAction(e -> Driver.setMenu(new LevelSurround(diff.level, diff, this)));
@@ -69,7 +69,7 @@ public class DiffEditor extends Pane
// diff.bpm = Double.parseDouble(bpm.getText());
// diff.numBeats = Integer.parseInt(numBeats.getText());
diff.priority = Integer.parseInt(priority.getText());
- diff.writeMetadata();
+ diff.write();
});
HBox content = new HBox();
@@ -103,7 +103,7 @@ public class DiffEditor extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
diff --git a/src/main/java/net/sowgro/npehero/devmenu/DiffList.java b/src/main/java/net/sowgro/npehero/devmenu/DiffList.java
index 6345c2b..7c5a435 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/DiffList.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/DiffList.java
@@ -11,7 +11,7 @@ import javafx.scene.layout.VBox;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class DiffList extends Pane
{
@@ -31,10 +31,10 @@ public class DiffList extends Pane
diffs.getColumns().add(titleCol);
diffs.getColumns().add(validCol);
- titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getTitle()));
- validCol.setCellValueFactory(data -> new ReadOnlyBooleanWrapper(data.getValue().isValid()));
+ titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title));
+ validCol.setCellValueFactory(data -> new ReadOnlyBooleanWrapper(data.getValue().isValid));
- diffs.setItems(level.getDiffList());
+ diffs.setItems(level.difficulties.list);
diffs.setRowFactory( _ -> {
TableRow<Difficulty> row = new TableRow<>();
@@ -57,14 +57,14 @@ public class DiffList extends Pane
edit.disableProperty().bind(diffs.getSelectionModel().selectedItemProperty().isNull());
Button remove = new Button("Delete");
- remove.setOnAction(e -> level.removeDiff(diffs.getSelectionModel().getSelectedItem()));
+ remove.setOnAction(e -> level.difficulties.remove(diffs.getSelectionModel().getSelectedItem()));
remove.setDisable(true);
remove.disableProperty().bind(diffs.getSelectionModel().selectedItemProperty().isNull());
Button refresh = new Button("Refresh");
refresh.setOnAction(e -> {
level.readData();
- diffs.setItems(level.getDiffList());
+ diffs.setItems(level.difficulties.list);
});
ToggleButton create = new ToggleButton("Create");
@@ -92,7 +92,7 @@ public class DiffList extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
@@ -117,7 +117,7 @@ public class DiffList extends Pane
});
newLevelButton.setOnAction(_ -> {
- level.addDiff(newLevelEntry.getText());
+ level.difficulties.add(newLevelEntry.getText());
newLevelEntry.clear();
refresh.fire();
sidebar.getChildren().clear();
diff --git a/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java b/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
index 411c15d..3a7561e 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
@@ -15,7 +15,7 @@ import javafx.stage.FileChooser.ExtensionFilter;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class LevelEditor extends Pane
{
@@ -32,16 +32,16 @@ public class LevelEditor extends Pane
{
Text folderNameLabel = new Text("Folder name");
TextField folderName = new TextField();
- if (level.thisDir != null) {
- folderName.setText(level.thisDir.getName());
+ if (level.dir != null) {
+ folderName.setText(level.dir.getName());
folderName.setDisable(true);
}
Text titleLabel = new Text("Title");
- TextField title = new TextField(level.getTitle());
+ TextField title = new TextField(level.title);
Text artistLabel = new Text("Artist");
- TextField artist = new TextField(level.getArtist());
+ TextField artist = new TextField(level.title);
Text descLabel = new Text("Description");
TextField desc = new TextField(level.desc);
@@ -93,7 +93,7 @@ public class LevelEditor extends Pane
diffCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title));
validCol.setCellValueFactory(data -> new ReadOnlyBooleanWrapper(data.getValue().isValid));
- diffList.setItems(level.getDiffList());
+ diffList.setItems(level.difficulties.list);
diffList.setRowFactory( _ -> {
TableRow<Difficulty> row = new TableRow<>();
@@ -106,12 +106,6 @@ public class LevelEditor extends Pane
return row ;
});
- TextField newDiff = new TextField("new");
- Button newDiffButton = new Button("add");
- newDiffButton.setOnAction(e -> level.addDiff(newDiff.getText()));
- HBox newDiffBox = new HBox();
- newDiffBox.getChildren().addAll(newDiff,newDiffButton);
-
Button newDiffs = new Button("Edit difficulties");
newDiffs.setOnAction(_ -> Driver.setMenu(new DiffList(level, this)));
@@ -119,8 +113,8 @@ public class LevelEditor extends Pane
Button save = new Button("Save");
save.setOnAction(e -> { //assigns fields to values
- level.setTitle(title.getText());
- level.setArtist(artist.getText());
+ level.title = title.getText();
+ level.artist = artist.getText();
level.desc = desc.getText();
level.colors[0] = colorsPickers[0].getValue();
level.colors[1] = colorsPickers[1].getValue();
@@ -158,7 +152,7 @@ public class LevelEditor extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
diff --git a/src/main/java/net/sowgro/npehero/devmenu/LevelList.java b/src/main/java/net/sowgro/npehero/devmenu/LevelList.java
index 61b9d47..92ede43 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/LevelList.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/LevelList.java
@@ -11,8 +11,8 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import net.sowgro.npehero.gui.MainMenu;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.LevelController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Levels;
+import net.sowgro.npehero.main.Sound;
public class LevelList extends Pane
{
@@ -34,11 +34,11 @@ public class LevelList extends Pane
levels.getColumns().add(artistCol);
levels.getColumns().add(validCol);
- titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getTitle()));
- artistCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getArtist()));
- validCol.setCellValueFactory(data -> new ReadOnlyBooleanWrapper(data.getValue().isValid()));
+ titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title));
+ artistCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().artist));
+ validCol.setCellValueFactory(data -> new ReadOnlyBooleanWrapper(data.getValue().isValid));
- levels.setItems(LevelController.getLevelList());
+ levels.setItems(Levels.list);
levels.setRowFactory( _ -> {
TableRow<Level> row = new TableRow<>();
@@ -50,9 +50,7 @@ public class LevelList extends Pane
});
return row ;
});
-
- levels.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.35));
- levels.setMinWidth(400);
+ levels.setPrefWidth(600);
levels.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
Button edit = new Button("Edit");
@@ -61,14 +59,14 @@ public class LevelList extends Pane
edit.disableProperty().bind(levels.getSelectionModel().selectedItemProperty().isNull());
Button remove = new Button("Delete");
- remove.setOnAction(e -> LevelController.removeLevel(levels.getSelectionModel().getSelectedItem()));
+ remove.setOnAction(e -> Levels.remove(levels.getSelectionModel().getSelectedItem()));
remove.setDisable(true);
remove.disableProperty().bind(levels.getSelectionModel().selectedItemProperty().isNull());
Button refresh = new Button("Refresh");
refresh.setOnAction(e -> {
- LevelController.readData();
- levels.setItems(LevelController.getLevelList());
+ Levels.readData();
+ levels.setItems(Levels.list);
});
ToggleButton create = new ToggleButton("Create");
@@ -96,7 +94,7 @@ public class LevelList extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(new MainMenu());
});
@@ -122,7 +120,7 @@ public class LevelList extends Pane
});
newLevelButton.setOnAction(_ -> {
- LevelController.addLevel(newLevelEntry.getText());
+ Levels.add(newLevelEntry.getText());
newLevelEntry.clear();
refresh.fire();
sidebar.getChildren().clear();
diff --git a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor.java b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor.java
index 985b2d0..5a606dc 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor.java
@@ -17,7 +17,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.main.Control;
import net.sowgro.npehero.main.Difficulty;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class NotesEditor extends Pane
{
@@ -48,7 +48,7 @@ public class NotesEditor extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
@@ -102,7 +102,7 @@ public class NotesEditor extends Pane
private void start()
{
- SoundController.playSong(new Media(diff.level.song.toString()));
+ Sound.playSong(new Media(diff.level.song.toString()));
timer = new Timer(diff.bpm);
help.setText(t2);
}
@@ -111,7 +111,7 @@ public class NotesEditor extends Pane
{
try
{
- SoundController.endSong();
+ Sound.stopSong();
diff.numBeats = (int)Double.parseDouble(timer.toString());
timer = null;
writer.close();
diff --git a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
index cd76801..1e2874d 100644
--- a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
@@ -25,7 +25,7 @@ import net.sowgro.npehero.gameplay.Block;
import net.sowgro.npehero.gameplay.Target;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Note;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
import net.sowgro.npehero.main.Control;
import java.util.concurrent.atomic.AtomicInteger;
@@ -45,7 +45,7 @@ public class NotesEditor2 extends Pane {
noteList = diff.notes.deepCopyList();
m = new MediaPlayer(new Media(diff.level.song.toURI().toString()));
- SoundController.endSong();
+ Sound.stopSong();
// Buttons
VBox actionBox = new VBox();
@@ -140,9 +140,9 @@ public class NotesEditor2 extends Pane {
exit.setText("Cancel");
exit.setOnAction(_ -> {
m.stop();
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
- SoundController.playSong(SoundController.MENUSONG);
+ Sound.playSong(Sound.MENU_SONG);
});
Button save = new Button();
@@ -151,9 +151,9 @@ public class NotesEditor2 extends Pane {
diff.notes.list = noteList;
diff.notes.writeFile();
m.stop();
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(new DiffEditor(diff, prev.prev));
- SoundController.playSong(SoundController.MENUSONG);
+ Sound.playSong(Sound.MENU_SONG);
});
HBox buttons = new HBox(save, exit);
diff --git a/src/main/java/net/sowgro/npehero/main/ScoreController.java b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java
index 205201c..1865a56 100755
--- a/src/main/java/net/sowgro/npehero/main/ScoreController.java
+++ b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java
@@ -1,8 +1,8 @@
-package net.sowgro.npehero.main;
+package net.sowgro.npehero.gameplay;
-import net.sowgro.npehero.Driver;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
+import net.sowgro.npehero.main.Sound;
public class ScoreController{
@@ -39,7 +39,7 @@ public class ScoreController{
*/
public void miss(boolean muted) {
if (!muted) {
- SoundController.playSfx(SoundController.MISS);
+ Sound.playSfx(Sound.MISS);
}
combo = 0;
comboMultiplier = 1;
@@ -52,7 +52,7 @@ public class ScoreController{
* Increments the combo by one
*/
private void combo() {
- SoundController.playSfx(SoundController.HIT);
+ Sound.playSfx(Sound.HIT);
combo++;
if (combo == 2) {
diff --git a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java
index dc74b30..b025c06 100755
--- a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java
+++ b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java
@@ -10,6 +10,7 @@ import java.util.Queue;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
+import javafx.event.EventHandler;
import javafx.scene.input.KeyEvent;
import javafx.scene.media.Media;
import net.sowgro.npehero.Driver;
@@ -26,8 +27,7 @@ import javafx.animation.*;
import javafx.util.*;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.ScoreController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
//hi aidan here are some objects you can use
@@ -47,6 +47,8 @@ public class SongPlayer extends Pane {
private Double bpm; //initializes the bpm of the song, to be read in from a metadata file later
private int songLength; //initializes the length of the song in terms of the song's bpm, to be read in later
+ private EventHandler<KeyEvent> eventHandler;
+
private File song;
private boolean songIsPlaying = false;
private boolean missMute = false;
@@ -100,7 +102,7 @@ public class SongPlayer extends Pane {
}
public SongPlayer(Level lvl, Difficulty d, Pane p, ScoreController cntrl) {
- SoundController.endSong();
+ Sound.stopSong();
song = lvl.song;
if (lvl.background != null) {
@@ -134,7 +136,7 @@ public class SongPlayer extends Pane {
genButton(jButton);
genButton(kButton);
- Driver.primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
+ eventHandler = e -> {
/**
* The keyboard detection for the game: when a key is pressed it
* calls the checkNote() method for the corresponding lane
@@ -164,7 +166,8 @@ public class SongPlayer extends Pane {
e.consume();
//prints the user's current score and combo, for debugging purposes
//System.out.println("Score: " + scoreCounter.getScore() + "\nCombo: " + scoreCounter.getCombo() + "\n");
- });
+ };
+ Driver.primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, eventHandler);
buttonBox.setAlignment(Pos.CENTER); //puts the buttons in the center of the screen
buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton); //places the buttons in the correct row order
@@ -255,7 +258,7 @@ public class SongPlayer extends Pane {
}
if (!songIsPlaying && timer.time() > 0.0) {
songIsPlaying = true;
- SoundController.playSong(new Media(song.toURI().toString()));
+ Sound.playSong(new Media(song.toURI().toString()));
}
}
};
@@ -273,9 +276,10 @@ public class SongPlayer extends Pane {
* @throws UnsupportedAudioFileException
*/
public void cancel() {
+ Driver.primaryStage.removeEventFilter(KeyEvent.KEY_PRESSED, eventHandler);
missMute = true;
- SoundController.endSong();
- SoundController.playSong(SoundController.MENUSONG);
+ Sound.stopSong();
+ Sound.playSong(Sound.MENU_SONG);
Driver.setMenuBackground();
gameLoop.stop();
}
diff --git a/src/main/java/net/sowgro/npehero/gui/ControlEditor.java b/src/main/java/net/sowgro/npehero/gui/ControlEditor.java
index ecd2fab..b620b17 100644
--- a/src/main/java/net/sowgro/npehero/gui/ControlEditor.java
+++ b/src/main/java/net/sowgro/npehero/gui/ControlEditor.java
@@ -1,24 +1,15 @@
package net.sowgro.npehero.gui;
-import javafx.beans.InvalidationListener;
-import javafx.beans.binding.DoubleBinding;
-import javafx.beans.property.Property;
-import javafx.beans.property.ReadOnlyObjectWrapper;
-import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
-import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
-import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
-import javafx.scene.paint.Color;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Control;
-import net.sowgro.npehero.main.SoundController;
-import org.w3c.dom.events.Event;
+import net.sowgro.npehero.main.Sound;
import java.util.List;
import java.util.Map;
@@ -36,15 +27,34 @@ public class ControlEditor extends Pane {
controls.setHgap(40);
- scrollPane.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.35));
- scrollPane.setMinWidth(400);
+// Pane dummy1 = new Pane();
+// Pane dummy2 = new Pane();
+// Pane dummy3 = new Pane();
+// controls.add(dummy1, 0, 0);
+// controls.add(dummy2, 1, 0);
+// controls.add(dummy3, 2, 0);
+//
+// Runnable r = () -> {
+// var vpw = scrollPane.getViewportBounds().getWidth();
+// var itemswidth = dummy1.getWidth() + dummy2.getWidth() + dummy3.getWidth();
+// var out = ((vpw - itemswidth) / 2) -10;
+// if (out < 10) {
+// controls.setHgap(10);
+// }
+// else {
+// controls.setHgap(out);
+// }
+// };
+// scrollPane.viewportBoundsProperty().addListener((_, _, _) -> r.run());
+
+ scrollPane.setPrefWidth(700);
scrollPane.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
- Driver.setMenu(new Settings());
+ Sound.playSfx(Sound.BACKWARD);
+ Driver.setMenu(new SettingsEditor());
});
VBox centerBox = new VBox();
diff --git a/src/main/java/net/sowgro/npehero/gui/GameOver.java b/src/main/java/net/sowgro/npehero/gui/GameOver.java
index b75ec43..da524dc 100755
--- a/src/main/java/net/sowgro/npehero/gui/GameOver.java
+++ b/src/main/java/net/sowgro/npehero/gui/GameOver.java
@@ -14,7 +14,7 @@ import javafx.scene.text.Text;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class GameOver extends Pane
{
@@ -30,11 +30,11 @@ public class GameOver extends Pane
topText.getStyleClass().add("t11");
Text levelName = new Text();
- levelName.setText(level.getTitle());
+ levelName.setText(level.title);
levelName.getStyleClass().add("t2");
Text levelArtist = new Text();
- levelArtist.setText(level.getArtist()+" - "+diff.title);
+ levelArtist.setText(level.artist+" - "+diff.title);
levelArtist.getStyleClass().add("t3");
VBox levelDetailsBox = new VBox();
@@ -72,10 +72,10 @@ public class GameOver extends Pane
save.setOnAction(new EventHandler<ActionEvent>() { //this is the same as the "e ->" thing but it allows more than one line to be added
@Override
public void handle(ActionEvent event) {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
save.setDisable(true);
name.setDisable(true);
- diff.addToLeaderboard(name.getText(), score2);
+ diff.leaderboard.add(name.getText(), score2);
}
});
@@ -93,14 +93,14 @@ public class GameOver extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(lastMenu);
});
Button replay = new Button();
replay.setText("Replay");
replay.setOnAction(e -> {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new LevelSurround(level, diff, lastMenu));
});
diff --git a/src/main/java/net/sowgro/npehero/gui/Leaderboard.java b/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java
index 842e46d..4741823 100755
--- a/src/main/java/net/sowgro/npehero/gui/Leaderboard.java
+++ b/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java
@@ -13,16 +13,16 @@ import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.LeaderboardEntry;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
-public class Leaderboard extends Pane
+public class LeaderboardView extends Pane
{
/*
* this class is a layout class, most of its purpose is to place UI elements like Buttons within Panes like VBoxes.
* the creation of these UI elements are mostly not commented due to their repetitive and self explanatory nature.
* style classes are defined in the style.css file.
*/
- public Leaderboard(Level level, Difficulty diff, Pane prev)
+ public LeaderboardView(Level level, Difficulty diff, Pane prev)
{
//sets up table view: requires java bean getters, setters and constructors to work
TableView<LeaderboardEntry> scores = new TableView<LeaderboardEntry>();
@@ -39,7 +39,7 @@ public class Leaderboard extends Pane
scoreCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getScore() + ""));
dateCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getDate()));
- scores.setItems(diff.getLeaderboard());
+ scores.setItems(diff.leaderboard.entries);
scores.getStyleClass().add("unselectable");
@@ -52,7 +52,7 @@ public class Leaderboard extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelDetails.java b/src/main/java/net/sowgro/npehero/gui/LevelDetails.java
index e5b6bdc..df5529e 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelDetails.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelDetails.java
@@ -17,7 +17,7 @@ import javafx.scene.text.TextFlow;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class LevelDetails extends VBox
{
@@ -66,11 +66,11 @@ public class LevelDetails extends VBox
detailsScroll.getStyleClass().remove("scroll-pane");
Text title = new Text();
- title.setText(level.getTitle());
+ title.setText(level.title);
title.getStyleClass().add("t1");
Text artist = new Text();
- artist.setText(level.getArtist());
+ artist.setText(level.artist);
artist.getStyleClass().add("t2");
Text desc = new Text();
@@ -86,26 +86,26 @@ public class LevelDetails extends VBox
FlowPane diffSelector = new FlowPane();
diffSelector.setAlignment(Pos.CENTER);
ToggleGroup diffToggleGroup = new ToggleGroup(); //allows only one to be selected at a time
- for (Difficulty diff : level.getValidDiffList()) //adds a button for each diff
+ for (Difficulty diff : level.difficulties.validList) //adds a button for each diff
{
RadioButton temp = new RadioButton();
temp.getStyleClass().remove("radio-button"); //makes the buttons not look like a radio button and instead a normal button
temp.getStyleClass().add("button");
temp.setText(diff.title);
- temp.setUserData(diff); //allows the data and text to be seperate
+ temp.setUserData(diff); //allows the data and text to be separate
diffToggleGroup.getToggles().add(temp);
diffSelector.getChildren().add(temp);
}
play.disableProperty().bind(diffToggleGroup.selectedToggleProperty().isNull()); //disables play button when no difficulty is selected
play.setOnAction(e -> {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new LevelSurround(level, (Difficulty)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu()));
});
leaderboard.disableProperty().bind(diffToggleGroup.selectedToggleProperty().isNull());
leaderboard.setOnAction(e -> {
- SoundController.playSfx(SoundController.FORWARD);
- Driver.setMenu(new Leaderboard(level, (Difficulty)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu()));
+ Sound.playSfx(Sound.FORWARD);
+ Driver.setMenu(new LeaderboardView(level, (Difficulty)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu()));
});
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSelector.java b/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
index eb31754..3553267 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
@@ -10,8 +10,8 @@ import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.LevelController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Levels;
+import net.sowgro.npehero.main.Sound;
public class LevelSelector extends Pane
{
@@ -31,10 +31,10 @@ public class LevelSelector extends Pane
levels.getColumns().add(titleCol);
levels.getColumns().add(artistCol);
- titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getTitle()));
- artistCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getArtist()));
+ titleCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title));
+ artistCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().artist));
- levels.setItems(LevelController.getValidLevelList());
+ levels.setItems(Levels.validList);
levels.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.25));
levels.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
@@ -45,7 +45,7 @@ public class LevelSelector extends Pane
exit.setText("Back");
exit.setOnAction(e -> {
Driver.setMenu(new MainMenu());
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
});
VBox leftBox = new VBox();
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
index aca93bc..b864c08 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
@@ -13,8 +13,8 @@ import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Level;
-import net.sowgro.npehero.main.ScoreController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.gameplay.ScoreController;
+import net.sowgro.npehero.main.Sound;
public class LevelSurround extends Pane
{
@@ -32,7 +32,7 @@ public class LevelSurround extends Pane
exit.setText("Back");
exit.setOnAction(e -> {
Driver.setMenu(prev);
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
game.cancel();
});
@@ -42,11 +42,11 @@ public class LevelSurround extends Pane
buttonBox.setSpacing(10);
Text title = new Text();
- title.setText(level.getTitle());
+ title.setText(level.title);
title.getStyleClass().add("t2");
Text artist = new Text();
- artist.setText(level.getArtist()+" - "+difficulty.title);
+ artist.setText(level.artist+" - "+difficulty.title);
artist.getStyleClass().add("t3");
VBox titleTextBox = new VBox();
@@ -125,27 +125,6 @@ public class LevelSurround extends Pane
root.prefWidthProperty().bind(super.prefWidthProperty());
root.prefHeightProperty().bind(super.prefHeightProperty());
- //for debug menu
- Button addScore = new Button();
- addScore.setText(level.getTitle() + " addscore");
- addScore.setOnAction(e -> sc.setScore(sc.getScore()+1));
-// Driver.debug.addButton(addScore);
-
- Button addCombo = new Button();
- addCombo.setText(level.getTitle() + " addcombo");
- addCombo.setOnAction(e -> sc.setCombo(sc.getCombo()+1));
-// Driver.debug.addButton(addCombo);
-
- Button printD = new Button();
- printD.setText(level.getTitle() + " print debug");
- printD.setOnAction(e -> sc.print());
-// Driver.debug.addButton(printD);
-
- Button testfinish = new Button();
- testfinish.setText(level.getTitle() + "launch game end");
- testfinish.setOnAction(e -> Driver.setMenu(new GameOver(level, difficulty, prev, sc.getScore())));
-// Driver.debug.addButton(testfinish);
-
game.start();
}
} \ No newline at end of file
diff --git a/src/main/java/net/sowgro/npehero/gui/MainMenu.java b/src/main/java/net/sowgro/npehero/gui/MainMenu.java
index 2b1d2ac..2587f41 100755
--- a/src/main/java/net/sowgro/npehero/gui/MainMenu.java
+++ b/src/main/java/net/sowgro/npehero/gui/MainMenu.java
@@ -1,7 +1,5 @@
package net.sowgro.npehero.gui;
-import javafx.application.Application;
-import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.effect.BlurType;
@@ -12,7 +10,7 @@ import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.devmenu.LevelList;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Sound;
public class MainMenu extends Pane
@@ -38,26 +36,26 @@ public class MainMenu extends Pane
play.setText("Play");
play.setOnAction(e -> {
Driver.setMenu(new LevelSelector());
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
});
Button settings = new Button();
settings.setText("Settings");
settings.setOnAction(_ -> {
- Driver.setMenu(new Settings());
- SoundController.playSfx(SoundController.FORWARD);
+ Driver.setMenu(new SettingsEditor());
+ Sound.playSfx(Sound.FORWARD);
});
Button levelEdit = new Button("Level Editor");
levelEdit.setOnAction(e -> {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new LevelList());
});
Button exit = new Button();
exit.setText("Quit");
exit.setOnAction(e -> {
- SoundController.playSfx(SoundController.BACKWARD);
+ Sound.playSfx(Sound.BACKWARD);
// Driver.quit();
// Platform.exit();
System.exit(0);
diff --git a/src/main/java/net/sowgro/npehero/gui/Settings.java b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
index cc6815c..4dcd3dc 100755
--- a/src/main/java/net/sowgro/npehero/gui/Settings.java
+++ b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
@@ -3,6 +3,7 @@ package net.sowgro.npehero.gui;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
@@ -10,29 +11,32 @@ import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.Driver;
-import net.sowgro.npehero.main.SettingsController;
-import net.sowgro.npehero.main.SoundController;
+import net.sowgro.npehero.main.Settings;
+import net.sowgro.npehero.main.Sound;
-public class Settings extends Pane
+public class SettingsEditor extends Pane
{
/*
* this class is a layout class, most of its purpose is to place UI elements like Buttons within Panes like VBoxes.
* the creation of these UI elements are mostly not commented due to their repetitive and self explanatory nature.
* style classes are defined in the style.css file.
*/
- public Settings()
+ public SettingsEditor()
{
Text musicText = new Text();
musicText.setText("Music Volume");
musicText.getStyleClass().add("t3");
Slider musicSlider = new Slider();
- musicSlider.valueProperty().bindBidirectional(SettingsController.musicVol);
+ musicSlider.valueProperty().bindBidirectional(Settings.musicVol);
musicSlider.setMin(0.0);
musicSlider.setMax(1.0);
+ CheckBox enableMenuMusic = new CheckBox("Enable Menu Music");
+ enableMenuMusic.selectedProperty().bindBidirectional(Settings.enableMenuMusic);
+
VBox musicBox = new VBox();
- musicBox.getChildren().addAll(musicText, musicSlider);
+ musicBox.getChildren().addAll(musicText, musicSlider, enableMenuMusic);
musicBox.getStyleClass().add("box");
musicBox.setPadding(new Insets(10));
@@ -42,7 +46,7 @@ public class Settings extends Pane
SFXText.getStyleClass().add("t3");
Slider SFXSlider = new Slider();
- SFXSlider.valueProperty().bindBidirectional(SettingsController.effectsVol);
+ SFXSlider.valueProperty().bindBidirectional(Settings.effectsVol);
SFXSlider.setMin(0.0);
SFXSlider.setMax(1.0);
@@ -59,7 +63,7 @@ public class Settings extends Pane
Button fullscreen = new Button();
fullscreen.setText("Toggle (F11)");
fullscreen.setOnAction(e -> {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
Driver.primaryStage.setFullScreen(!Driver.primaryStage.isFullScreen());
});
@@ -75,7 +79,7 @@ public class Settings extends Pane
Button controlsButton = new Button();
controlsButton.setText("Edit");
controlsButton.setOnAction(_ -> {
- SoundController.playSfx(SoundController.FORWARD);
+ Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new ControlEditor());
});
@@ -87,8 +91,8 @@ public class Settings extends Pane
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
- SettingsController.write();
- SoundController.playSfx(SoundController.BACKWARD);
+ Settings.save();
+ Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(new MainMenu());
});
diff --git a/src/main/java/net/sowgro/npehero/main/Control.java b/src/main/java/net/sowgro/npehero/main/Control.java
index 2ec8a61..2a12f5a 100644
--- a/src/main/java/net/sowgro/npehero/main/Control.java
+++ b/src/main/java/net/sowgro/npehero/main/Control.java
@@ -3,8 +3,6 @@ package net.sowgro.npehero.main;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.input.KeyCode;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
import java.io.*;
import java.util.*;
@@ -38,7 +36,7 @@ public enum Control {
entry("Legacy Editor", List.of(LEGACY_PRINT, LEGACY_STOP))
);
- private static final String fileName = "controls.json";
+ private static final JSONFile jsonFile = new JSONFile(new File("controls.json"));
Control(String label, KeyCode key) {
this.label = label;
@@ -80,37 +78,30 @@ public enum Control {
}
public static void writeToFile() {
+ for (Control control : Control.values()) {
+ jsonFile.set(control.toString(), control.getKey().toString());
+ }
+
try {
- File file = new File(fileName);
- FileWriter fileWriter = new FileWriter(file);
- JSONObject jsonObject = new JSONObject();
- for (Control control : Control.values()) {
- jsonObject.put(control.toString(), control.getKey().toString());
- }
- jsonObject.writeJSONString(fileWriter);
- fileWriter.flush();
+ jsonFile.write();
}
catch (IOException e) {
- e.printStackTrace();
+ System.err.println("Error writing to controls.json");
}
}
public static void readFromFile() {
- File file = new File(fileName);
- JSONParser jsonParser = new JSONParser();
-
try {
- FileReader reader = new FileReader(file);
- Object obj = jsonParser.parse(reader);
- JSONObject jsonObject = (JSONObject)(obj);
- for (Control control : Control.values()) {
- if (jsonObject.containsKey(control.toString())) {
- control.setKey(KeyCode.valueOf((String) jsonObject.get(control.toString())));
- }
- }
+ jsonFile.read();
}
catch (Exception e) {
- e.printStackTrace();
+ System.err.println("Error reading from controls.json");
+ }
+
+ for (Control control : Control.values()) {
+ if (jsonFile.containsKey(control.toString())) {
+ control.setKey(KeyCode.valueOf(jsonFile.getString(control.toString(), null)));
+ }
}
}
diff --git a/src/main/java/net/sowgro/npehero/main/Difficulties.java b/src/main/java/net/sowgro/npehero/main/Difficulties.java
new file mode 100644
index 0000000..83137a7
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/Difficulties.java
@@ -0,0 +1,81 @@
+package net.sowgro.npehero.main;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ListChangeListener;
+import javafx.collections.ObservableList;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+public class Difficulties {
+
+ public ObservableList<Difficulty> list = FXCollections.observableArrayList();
+ public ObservableList<Difficulty> validList = FXCollections.observableArrayList();
+ {
+ list.addListener((ListChangeListener<? super Difficulty>) e -> {
+ validList.clear();
+ for (Difficulty difficulty : list) {
+ if (difficulty.isValid) {
+ validList.add(difficulty);
+ }
+ }
+ });
+ }
+ Level level;
+
+ public Difficulties(Level level) {
+ this.level = level;
+ }
+
+ public void read() {
+ for(File cur: level.dir.listFiles()) //iterates through all files/folders in /levels/LEVEL
+ {
+ if (cur.isDirectory()) //all subfolders within a level folder are difficulties
+ {
+ Difficulty diff = new Difficulty(cur,level);
+ diff.readData();
+ list.add(diff);
+ }
+ }
+ }
+
+ /**
+ * Removes the difficaulty from the filesystem then reloads the level
+ * @param diff: the difficulty to be removed
+ */
+ public void remove(Difficulty diff)
+ {
+ File hold = diff.thisDir;
+ try {
+ Files.walk(hold.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ list.remove(diff);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Adds a difficulty by creating a directory and required files
+ * @param text: the name of the directory and default title
+ */
+ public void add(String text)
+ {
+ File diffDir = new File(level.dir, text);
+ diffDir.mkdirs();
+ Difficulty temp = new Difficulty(diffDir,level);
+ temp.title = text;
+ list.add(temp);
+ }
+
+
+
+
+
+
+}
diff --git a/src/main/java/net/sowgro/npehero/main/Difficulty.java b/src/main/java/net/sowgro/npehero/main/Difficulty.java
index 2c99702..c6155bd 100755
--- a/src/main/java/net/sowgro/npehero/main/Difficulty.java
+++ b/src/main/java/net/sowgro/npehero/main/Difficulty.java
@@ -2,271 +2,86 @@ package net.sowgro.npehero.main;
import java.io.File;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
-import java.time.LocalDate;
+import java.security.spec.ECField;
-import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
public class Difficulty implements Comparable<Difficulty>
{
public File thisDir;
+ public Level level;
+
public String title = "Unnamed";
- private ObservableList<LeaderboardEntry> leaderboard = FXCollections.observableArrayList();
- public Notes notes;
public Double bpm = 0.0;
public int numBeats;
- public Level level;
- public boolean isValid = false;
public int priority = 0;
+
+ public Leaderboard leaderboard;
+ public Notes notes;
+
+ public boolean isValid = true;
+
+ private final JSONFile metadataYaml;
/**
* Creates a new Difficulty and gives it a file path
* @param newDir: The file path of the Difficulty
*/
- public Difficulty(File newDir, Level level)
- {
+ public Difficulty(File newDir, Level level) {
thisDir = newDir;
this.level = level;
+ metadataYaml = new JSONFile(new File(thisDir, "metadata.json"));
}
- public void readData()
- {
- boolean isValid1 = true;
- if (new File(thisDir, "metadata.json").exists())
- {
- if (!parseMetadata())
- {
- isValid1 = false;
- }
- }
- else
- {
- System.err.println(thisDir+" is missing metadata.json");
- isValid1 = false;
- }
-
- if (new File(thisDir, "leaderboard.json").exists())
- {
- if (!parseLeaderboard())
- {
- isValid1 = false;
- }
+ public void readData() {
+ try {
+ metadataYaml.read();
}
- else
- {
- System.err.println(thisDir+" is missing leaderboard.json");
- isValid1 = false;
+ catch (Exception e) {
+ System.err.println(level.title + "/" + title + ": Failed to read metadata.json");
}
- File notesFile = new File(thisDir, "notes.txt");
- if (notesFile.exists())
- {
- notes = new Notes(notesFile, this);
- }
- else
- {
- System.err.println(thisDir+" is missing notes.txt");
- isValid1 = false;
- }
+ title = metadataYaml.getString("title", title);
+ bpm = metadataYaml.getDouble("bpm", bpm);
+ numBeats = metadataYaml.getInt("numBeats", numBeats);
+ priority = metadataYaml.getInt("priority", priority);
- if (bpm == 0.0)
- {
- System.err.println(thisDir+" is missing a bpm");
- isValid1 = false;
- }
+ notes = new Notes(new File(thisDir, "notes.txt"), this);
+ leaderboard = new Leaderboard(new File(thisDir, "leaderboard.json"));
- if (numBeats == 0)
- {
- System.err.println(thisDir+" is missing the number of beats");
- isValid1 = false;
- }
+ validate();
- isValid = isValid1;
}
- /**
- * Reads in json metadata and assigns values to variables
- */
- public boolean parseMetadata()
- {
- boolean isValid = true;
- File file = new File(thisDir, "metadata.json");
- JSONParser jsonParser = new JSONParser(); //parser to read the file
-
- try(FileReader reader = new FileReader(file))
- {
- Object obj = jsonParser.parse(reader);
- JSONObject diffStuff = (JSONObject)(obj); //converts read object to a JSONObject
-
- if (diffStuff.containsKey("title"))
- {
- title = (String) diffStuff.get("title");
- }
- else
- {
- System.err.println(file+" is missing properety title");
- isValid = false;
- }
-
- if (diffStuff.containsKey("bpm"))
- {
- bpm = Double.parseDouble(diffStuff.get("bpm")+"");
- }
- else
- {
- System.err.println(file+" is missing properety bpm");
- isValid = false;
- }
+ public void validate() {
+ isValid = true;
- if (diffStuff.containsKey("numBeats"))
- {
- numBeats = Integer.parseInt(diffStuff.get("numBeats")+"");
- }
- else
- {
- System.err.println(file+" is missing properety numBeats");
- isValid = false;
- }
-
- if (diffStuff.containsKey("priority"))
- {
- priority = Integer.parseInt(diffStuff.get("priority")+"");
-
- }
- else
- {
- System.err.println(file+" is missing properety priority");
- isValid = false;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
+ if (notes.list.isEmpty()) {
isValid = false;
}
- return isValid;
- }
- /**
- * Writes metadata to json file
- */
- public void writeMetadata()
- {
- FileWriter fileWriter;
- try
- {
- File file = new File(thisDir, "metadata.json");
- fileWriter = new FileWriter(file);
- JSONObject obj = new JSONObject();
- obj.put("title", title);
- obj.put("bpm", bpm);
- obj.put("numBeats", numBeats);
- obj.put("priority", priority);
- obj.writeJSONString(fileWriter);
- fileWriter.flush();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * Reads in json leaderboard and assigns populates list with leaderboardEntries
- */
- public boolean parseLeaderboard()
- {
- boolean isValid = true;
- File file = new File(thisDir, "leaderboard.json");
- JSONParser jsonParser = new JSONParser(); //parser to read the file
-
- try(FileReader reader = new FileReader(file))
- {
- Object obj = jsonParser.parse(reader);
-
- JSONArray leaderboardStuff = (JSONArray)(obj); //converts read object to a JSONArray
-
- for (Object cur: leaderboardStuff)
- {
- JSONObject cur2 = (JSONObject) cur;
-
- String name = (String) cur2.get("name");
- int score = Integer.parseInt(""+cur2.get("score"));
- String date = (String) cur2.get("date");
- leaderboard.add(new LeaderboardEntry(name, score, date));
- }
- }
- catch (Exception e)
- {
+ if (numBeats == 0) {
isValid = false;
- e.printStackTrace();
}
- return isValid;
}
/**
- * Writes leaderboard to json file
+ * Writes metadata to json file
*/
- public void writeLeaderboard()
- {
- FileWriter fileWriter;
- try
- {
- File file = new File(thisDir, "leaderboard.json");
- fileWriter = new FileWriter(file);
- //write the settings JSONObject instance to the file
- JSONArray jsonArray = new JSONArray();
- for (LeaderboardEntry cur: leaderboard)
- {
- JSONObject obj = new JSONObject();
- obj.put("name", cur.getName());
- obj.put("score", cur.getScore());
- obj.put("date",cur.getDate());
- jsonArray.add(obj);
- }
- jsonArray.writeJSONString(fileWriter);
- fileWriter.flush();
-
+ public void write() {
+ metadataYaml.set("title", title);
+ metadataYaml.set("numBeats", numBeats);
+ metadataYaml.set("priority", priority);
+
+ try {
+ metadataYaml.write();
}
catch (IOException e) {
- e.printStackTrace();
+ System.err.println(level.title + "/" + title + ": Failed to write metadata.json");
}
}
- /**
- * Adds new leaderboardEntry to list and updates json file
- * @param name: the players name
- * @param score the players score
- */
- public void addToLeaderboard(String name, int score)
- {
- leaderboard.add(new LeaderboardEntry(name, score, ""+LocalDate.now())); //do not delete this tho its not a placeholder
- writeLeaderboard();
- }
-
- public ObservableList<LeaderboardEntry> getLeaderboard()
- {
- return leaderboard;
- }
-
- public String toString()
- {
- return title;
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- public String getTitle() {
- return title;
- }
-
@Override
public int compareTo(Difficulty d) {
return priority - d.priority;
diff --git a/src/main/java/net/sowgro/npehero/main/JSONFile.java b/src/main/java/net/sowgro/npehero/main/JSONFile.java
new file mode 100644
index 0000000..ed76369
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/JSONFile.java
@@ -0,0 +1,101 @@
+package net.sowgro.npehero.main;
+
+import net.sowgro.npehero.Driver;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
+import java.io.*;
+
+/**
+ * An ergonomic JSON API wrapper inspired by the Bukkit YAML API
+ */
+public class JSONFile {
+
+ private final File file;
+ private JSONObject jsonObject = new JSONObject();
+
+ public JSONFile(File file) {
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ this.file = file;
+ }
+
+ public String getString(String key, String def) {
+ if (!jsonObject.containsKey(key)) {
+ return def;
+ }
+ return jsonObject.get(key).toString();
+ }
+
+ public int getInt(String key, int def) {
+ if (!jsonObject.containsKey(key)) {
+ return def;
+ }
+ try {
+ return Integer.parseInt(jsonObject.get(key).toString());
+ }
+ catch (NumberFormatException e) {
+ return def;
+ }
+ }
+
+ public double getDouble(String key, double def) {
+ if (jsonObject.containsKey(key)) {
+ try {
+ return Double.parseDouble(jsonObject.get(key).toString());
+ }
+ catch (NumberFormatException e) {
+ return def;
+ }
+ }
+ else {
+ return def;
+ }
+ }
+
+ public boolean getBoolean(String key, boolean def) {
+ if (!jsonObject.containsKey(key)) {
+ return def;
+ }
+ try {
+ return Boolean.parseBoolean(jsonObject.get(key).toString());
+ }
+ catch (NumberFormatException e) {
+ return def;
+ }
+ }
+
+ public void set(String key, Object value) {
+ if (value == null) {
+ return;
+ }
+ jsonObject.put(key, value);
+ }
+
+ public boolean containsKey(String key) {
+ return jsonObject.containsKey(key);
+ }
+
+ public void read() throws Exception {
+ try {
+ if (file.length() == 0) {
+ return;
+ }
+ FileReader fileReader = new FileReader(file);
+ jsonObject = (JSONObject) new JSONParser().parse(fileReader);
+ }
+ catch (Exception e) {
+ throw e;
+ }
+ }
+
+ public void write() throws IOException {
+ FileWriter fileWriter = new FileWriter(file);
+ jsonObject.writeJSONString(fileWriter);
+ fileWriter.close();
+ }
+
+}
diff --git a/src/main/java/net/sowgro/npehero/main/Leaderboard.java b/src/main/java/net/sowgro/npehero/main/Leaderboard.java
new file mode 100644
index 0000000..6a6b0c2
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/Leaderboard.java
@@ -0,0 +1,96 @@
+package net.sowgro.npehero.main;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.time.LocalDate;
+
+public class Leaderboard {
+
+ public ObservableList<LeaderboardEntry> entries = FXCollections.observableArrayList();
+// private final JSONFile jsonFile;
+ private File file;
+
+ public Leaderboard(File file) {
+// jsonFile = new JSONFile(file);
+ this.file = file;
+ }
+
+ /**
+ * Adds new leaderboardEntry to list and updates json file
+ * @param name: The players name
+ * @param score The players score
+ */
+ public void add(String name, int score) {
+ new LeaderboardEntry(name, score, ""+ LocalDate.now());
+ }
+
+ /**
+ * Writes leaderboard to json file
+ */
+ public void save()
+ {
+ FileWriter fileWriter;
+ try
+ {
+ fileWriter = new FileWriter(file);
+ //write the settings JSONObject instance to the file
+ JSONArray jsonArray = new JSONArray();
+ for (LeaderboardEntry cur: entries)
+ {
+ JSONObject obj = new JSONObject();
+ obj.put("name", cur.getName());
+ obj.put("score", cur.getScore());
+ obj.put("date",cur.getDate());
+ jsonArray.add(obj);
+ }
+ jsonArray.writeJSONString(fileWriter);
+ fileWriter.flush();
+
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Reads in json leaderboard and assigns populates list with leaderboardEntries
+ */
+ public boolean parseLeaderboard()
+ {
+ boolean isValid = true;
+ JSONParser jsonParser = new JSONParser(); //parser to read the file
+
+ try(FileReader reader = new FileReader(file))
+ {
+ Object obj = jsonParser.parse(reader);
+
+ JSONArray leaderboardStuff = (JSONArray)(obj); //converts read object to a JSONArray
+
+ for (Object cur: leaderboardStuff)
+ {
+ JSONObject cur2 = (JSONObject) cur;
+
+ String name = (String) cur2.get("name");
+ int score = Integer.parseInt(""+cur2.get("score"));
+ String date = (String) cur2.get("date");
+ entries.add(new LeaderboardEntry(name, score, date));
+ }
+ }
+ catch (Exception e)
+ {
+ isValid = false;
+ e.printStackTrace();
+ }
+ return isValid;
+ }
+
+
+}
diff --git a/src/main/java/net/sowgro/npehero/main/Level.java b/src/main/java/net/sowgro/npehero/main/Level.java
index ef264ff..dd96815 100755
--- a/src/main/java/net/sowgro/npehero/main/Level.java
+++ b/src/main/java/net/sowgro/npehero/main/Level.java
@@ -1,243 +1,118 @@
package net.sowgro.npehero.main;
import java.io.File;
-import java.util.Collections;
-import java.util.Comparator;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
-import java.io.FileWriter;
-import java.io.FileReader;
+
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
public class Level
{
- public File thisDir;
- private String title = "Unnamed";
- private String artist = "Unknown";
- private ObservableList<Difficulty> diffList;
- private ObservableList<Difficulty> validDiffList;
- private boolean isValid;
+ public File dir;
- public Image preview; //optional
+ public String title = "Unnamed";
+ public String artist = "Unknown";
public String desc;
- public Image background; //optional
public Color[] colors = {Color.RED,Color.BLUE,Color.GREEN,Color.PURPLE,Color.YELLOW};//optional, have default colors
+
+ public Image preview; //optional
+ public Image background; //optional
public File song;
+ public Difficulties difficulties;
+
+ public boolean isValid = true;
+
+ private JSONFile metadataJson;
+
/**
* Creates a new level and gives it a file path
* @param newDir: The path of the Level
*/
public Level(File newDir)
{
- thisDir = newDir;
+ dir = newDir;
+ metadataJson = new JSONFile(new File(dir, "metadata.json"));
+ difficulties = new Difficulties(this);
+ difficulties.read();
+ readData();
}
- public void readData()
- {
- boolean isValid1 = true;
- if (new File(thisDir, "metadata.json").exists())
- {
- if (!parseMetadata())
- {
- System.err.println(new File(thisDir, "metadata.json")+" contains error(s)");
- isValid1 = false;
- }
- }
- else
- {
- System.err.println(thisDir+" is missing metadata.json");
- isValid1 = false;
- }
-
- if (new File(thisDir, "song.wav").exists())
- {
- song = new File(thisDir,"song.wav");
- }
- else
- {
- System.err.println(thisDir+" is missing song.wav");
- isValid1 = false;
- }
+ public void readData() {
- if (new File(thisDir, "background.png").exists())
- {
- background = new Image(new File(thisDir,"background.png").toURI().toString());
+ if (new File(dir, "song.wav").exists()) {
+ song = new File(dir,"song.wav");
}
- if (new File(thisDir, "preview.png").exists())
- {
- preview = new Image(new File(thisDir,"preview.png").toURI().toString());
+ if (new File(dir, "background.png").exists()) {
+ background = new Image(new File(dir,"background.png").toURI().toString());
}
- diffList = FXCollections.observableArrayList();
- validDiffList = FXCollections.observableArrayList();
- for(File cur: thisDir.listFiles()) //iterates through all files/folders in /levels/LEVEL
- {
- if (cur.isDirectory()) //all subfolders within a level folder are difficulties
- {
- Difficulty diff = new Difficulty(cur,this);
- diff.readData();
- if (diff.isValid)
- {
- diffList.add(diff);
- validDiffList.add(diff);
- }
- else
- {
- diffList.add(diff);
- }
- }
- }
- if (validDiffList.size() == 0)
- {
- System.err.println(thisDir+" contains no valid difficulties");
- isValid1 = false;
+ if (new File(dir, "preview.png").exists()) {
+ preview = new Image(new File(dir,"preview.png").toURI().toString());
}
- Collections.sort(validDiffList);
- Collections.sort(diffList);
- isValid = isValid1;
+ parseMetadata();
+ validate();
}
- /**
- * Reads in json metadata and assigns values to variables
- */
- public boolean parseMetadata()
- {
- boolean isValid = true;
- JSONParser jsonParser = new JSONParser(); //parser to read the file
- File file = new File(thisDir, "metadata.json");
- try(FileReader reader = new FileReader(file))
- {
- Object obj = jsonParser.parse(reader);
- JSONObject levelStuff = new JSONObject();
- levelStuff = (JSONObject)(obj); //converts read object to a JSONObject
-
- if (levelStuff.containsKey("title"))
- {
- title = (String) levelStuff.get("title");
- }
- else
- {
- System.err.println(file+" is missing properety title");
- isValid = false;
- }
-
- if (levelStuff.containsKey("artist"))
- {
- artist = (String)(levelStuff.get("artist"));
- }
- else
- {
- System.err.println(file+" is missing properety aritst");
- isValid = false;
- }
-
- if (levelStuff.containsKey("desc"))
- {
- desc = (String) levelStuff.get("desc");
- }
-
- if(( levelStuff).containsKey("color1")) //check for custom colors in a hexadecimal format (zach was lazy for not checking all five colors but i will forgive him)
- {
- colors = new Color[5];
+ public void validate() {
+ if (song == null) {
+ System.err.println(dir +" is missing song.wav");
+ }
- colors[0] = Color.web((String)(levelStuff.get("color1"))); //read in all the custom colors
- colors[1] = Color.web((String)(levelStuff.get("color2")));
- colors[2] = Color.web((String)(levelStuff.get("color3")));
- colors[3] = Color.web((String)(levelStuff.get("color4")));
- colors[4] = Color.web((String)(levelStuff.get("color5")));
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
+ if (difficulties.validList.isEmpty()) {
+ System.err.println(dir +" contains no valid difficulties");
isValid = false;
- }
- return isValid;
- }
-
- /**
- * Writes metadata to json file
- */
- public void writeMetadata()
- {
- FileWriter fileWriter;
- try
- {
- fileWriter = new FileWriter(new File(thisDir, "metadata.json"));
- JSONObject obj = new JSONObject();
- obj.put("title", title);
- obj.put("artist", artist);
- if (desc != null)
- {
- obj.put("desc", desc);
- }
- obj.put("color1",colors[0].toString());
- obj.put("color2",colors[1].toString());
- obj.put("color3",colors[2].toString());
- obj.put("color4",colors[3].toString());
- obj.put("color5",colors[4].toString());
- obj.writeJSONString(fileWriter);
- fileWriter.flush();
- }
- catch (IOException e) {
- e.printStackTrace();
}
}
/**
- * Adds a difficulty by creating a directory and required files
- * @param text: the name of the directory and default title
+ * Reads in json metadata and assigns values to variables
*/
- public void addDiff(String text)
+ public void parseMetadata()
{
- File diffDir = new File(thisDir, text);
- diffDir.mkdirs();
- File metadataDir = new File(diffDir, "metadata.json");
- File leaderboardDir = new File(diffDir, "leaderboard.json");
- File notesDir = new File(diffDir, "notes.txt");
try {
- metadataDir.createNewFile();
- leaderboardDir.createNewFile();
- notesDir.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
+ metadataJson.read();
}
- Difficulty temp = new Difficulty(diffDir,this);
- temp.title = text;
- temp.writeMetadata();
- temp.writeLeaderboard();
- readData();
+ catch (Exception e) {
+ // TODO
+ }
+ title = metadataJson.getString("title", title);
+ artist = metadataJson.getString("artist", artist);
+ desc = metadataJson.getString("desc", desc);
+ colors[0] = Color.web(metadataJson.getString("color1", colors[0].toString()));
+ colors[1] = Color.web(metadataJson.getString("color2", colors[1].toString()));
+ colors[2] = Color.web(metadataJson.getString("color3", colors[2].toString()));
+ colors[3] = Color.web(metadataJson.getString("color4", colors[3].toString()));
+ colors[4] = Color.web(metadataJson.getString("color5", colors[4].toString()));
}
/**
- * Removes the difficaulty from the filesystem then reloads the level
- * @param diff: the difficulty to be removed
+ * Writes metadata to json file
*/
- public void removeDiff(Difficulty diff)
+ public void writeMetadata()
{
- File hold = diff.thisDir;
+ metadataJson.set("title", title);
+ metadataJson.set("artist", artist);
+ metadataJson.set("desc", desc);
+ metadataJson.set("color1",colors[0].toString());
+ metadataJson.set("color2",colors[1].toString());
+ metadataJson.set("color3",colors[2].toString());
+ metadataJson.set("color4",colors[3].toString());
+ metadataJson.set("color5",colors[4].toString());
try {
- Files.walk(hold.toPath())
- .sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
- } catch (IOException e) {
- e.printStackTrace();
+ metadataJson.write();
+ }
+ catch (IOException e) {
+ // TODO
}
- readData();
}
+
/**
* Copies a file into the level directory
* @param newFile: the file to be copied
@@ -246,40 +121,10 @@ public class Level
public void addFile(File newFile, String name)
{
try {
- Files.copy(newFile.toPath(), new File(thisDir, name).toPath(), StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(newFile.toPath(), new File(dir, name).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
readData();
}
-
- public ObservableList<Difficulty> getDiffList() {
- return diffList;
- }
-
- public ObservableList<Difficulty> getValidDiffList() {
- return validDiffList;
- }
-
- public String getTitle()
- {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getArtist()
- {
- return artist;
- }
-
- public void setArtist(String artist) {
- this.artist = artist;
- }
-
- public boolean isValid() {
- return isValid;
- }
}
diff --git a/src/main/java/net/sowgro/npehero/main/LevelController.java b/src/main/java/net/sowgro/npehero/main/LevelController.java
deleted file mode 100755
index 8205716..0000000
--- a/src/main/java/net/sowgro/npehero/main/LevelController.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package net.sowgro.npehero.main;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Comparator;
-
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-
-public class LevelController
-{
- private static File thisDir = new File("levels");
- private static ObservableList<Level> levelList;
- private static ObservableList<Level> validLevelList;
-
- /**
- * Reads contents of folder and creates cooresponding levels
- */
- public static void readData()
- {
- levelList = FXCollections.observableArrayList();
- validLevelList = FXCollections.observableArrayList();
- for (File cur: thisDir.listFiles()) //iterates through all files/folders in levels
- {
- Level level = new Level(cur);
- level.readData();
- levelList.add(level);
- if (level.isValid())
- {
- validLevelList.add(level);
- }
- }
- }
-
- /**
- * Adds a level to the list by creating a directory and required files
- * @param text: the name of the directory and default title
- */
- public static void addLevel(String text)
- {
- File levelDir = new File(thisDir,text);
- levelDir.mkdirs();
- File metadataDir = new File(levelDir, "metadata.json");
- try
- {
- metadataDir.createNewFile();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- Level temp = new Level(levelDir);
- temp.setTitle(text);
- temp.writeMetadata();
- readData();
- }
-
- /**
- * Removes level from the filesystem then reloads this levelController
- * @param level: the level to be removed
- */
- public static void removeLevel(Level level)
- {
- File hold = level.thisDir;
- levelList.remove(level);
-
- try {
- Files.walk(hold.toPath())
- .sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
- } catch (IOException e) {
- e.printStackTrace();
- }
- readData();
- }
-
- public static ObservableList<Level> getLevelList() {
- return levelList;
- }
-
- public static ObservableList<Level> getValidLevelList() {
- return validLevelList;
- }
-} \ No newline at end of file
diff --git a/src/main/java/net/sowgro/npehero/main/Levels.java b/src/main/java/net/sowgro/npehero/main/Levels.java
new file mode 100755
index 0000000..fff7387
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/Levels.java
@@ -0,0 +1,74 @@
+package net.sowgro.npehero.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ListChangeListener;
+import javafx.collections.ObservableList;
+
+public class Levels
+{
+ private static final File dir = new File("levels");
+ public static ObservableList<Level> list = FXCollections.observableArrayList();
+ public static ObservableList<Level> validList = FXCollections.observableArrayList();
+ static {
+ list.addListener((ListChangeListener<? super Level>) e -> {
+ validList.clear();
+ for (Level level : list) {
+ if (level.isValid) {
+ validList.add(level);
+ }
+ }
+ });
+ }
+
+ /**
+ * Reads contents of folder and creates cooresponding levels
+ */
+ public static void readData()
+ {
+ for (File cur: dir.listFiles()) //iterates through all files/folders in levels
+ {
+ Level level = new Level(cur);
+ level.readData();
+ list.add(level);
+ }
+ }
+
+ /**
+ * Adds a level to the list by creating a directory and required files
+ * @param text: the name of the directory and default title
+ */
+ public static void add(String text)
+ {
+ File levelDir = new File(dir,text);
+ levelDir.mkdirs();
+ Level temp = new Level(levelDir);
+ temp.title = text;
+ list.add(temp);
+ }
+
+ /**
+ * Removes level from the filesystem then reloads this levelController
+ * @param level: the level to be removed
+ */
+ public static void remove(Level level)
+ {
+ File hold = level.dir;
+ list.remove(level);
+
+ try {
+ Files.walk(hold.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ list.remove(level);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/net/sowgro/npehero/main/Notes.java b/src/main/java/net/sowgro/npehero/main/Notes.java
index 543d6f9..62a602e 100644
--- a/src/main/java/net/sowgro/npehero/main/Notes.java
+++ b/src/main/java/net/sowgro/npehero/main/Notes.java
@@ -15,6 +15,11 @@ public class Notes {
public ListProperty<Note> list = new SimpleListProperty<>(FXCollections.observableArrayList());
public Notes(File f, Difficulty diff) {
+ try {
+ f.createNewFile();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
this.file = f;
this.diff = diff;
readFile();
diff --git a/src/main/java/net/sowgro/npehero/main/Settings.java b/src/main/java/net/sowgro/npehero/main/Settings.java
new file mode 100755
index 0000000..cd3448c
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/Settings.java
@@ -0,0 +1,48 @@
+package net.sowgro.npehero.main;
+
+import java.io.File;
+import java.io.IOException;
+
+import javafx.beans.property.SimpleBooleanProperty;
+import javafx.beans.property.SimpleDoubleProperty;
+
+public class Settings
+{
+ public static SimpleDoubleProperty effectsVol = new SimpleDoubleProperty(1);
+ public static SimpleDoubleProperty musicVol = new SimpleDoubleProperty(1);
+ public static SimpleBooleanProperty enableMenuMusic = new SimpleBooleanProperty(true);
+
+ private static final JSONFile jsonFile = new JSONFile(new File("settings.json"));
+
+ /**
+ * Reads json data from settings.json
+ */
+ public static void read()
+ {
+ try {
+ jsonFile.read();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Error reading settings.json");
+ }
+ effectsVol.set(jsonFile.getDouble("effectsVol", 1));
+ musicVol.set(jsonFile.getDouble("musicVol", 1));
+ enableMenuMusic.set(jsonFile.getBoolean("enableMenuMusic", true));
+ }
+
+ /**
+ * Writes json data to settings.json
+ */
+ public static void save()
+ {
+ jsonFile.set("effectsVol", effectsVol.get());
+ jsonFile.set("musicVol", musicVol.get());
+ jsonFile.set("enableMenuMusic", enableMenuMusic.get());
+ try {
+ jsonFile.write();
+ }
+ catch (IOException e) {
+ System.out.println("Error writing settings.json");
+ }
+ }
+}
diff --git a/src/main/java/net/sowgro/npehero/main/SettingsController.java b/src/main/java/net/sowgro/npehero/main/SettingsController.java
deleted file mode 100755
index 5ea0ac9..0000000
--- a/src/main/java/net/sowgro/npehero/main/SettingsController.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package net.sowgro.npehero.main;
-
-import java.io.FileWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import javafx.beans.property.SimpleDoubleProperty;
-
-public class SettingsController
-{
- public static SimpleDoubleProperty effectsVol = new SimpleDoubleProperty(1);
- public static SimpleDoubleProperty musicVol = new SimpleDoubleProperty(1);
- private static File file = new File("settings.json");
-
- /**
- * reads json data from settings.json
- */
- public static void read()
- {
- JSONParser jsonParser = new JSONParser(); //parser to read the file
- try(FileReader reader = new FileReader(file))
- {
- Object obj = jsonParser.parse(reader);
- JSONObject settings = new JSONObject();
- settings = (JSONObject)(obj); //converts read object to a JSONObject
-
- effectsVol.set(Double.parseDouble(settings.get("effectsVol")+""));
- musicVol.set(Double.parseDouble(settings.get("musicVol")+""));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * writes json data to settings.json
- */
- public static void write()
- {
- FileWriter fileWriter;
- try
- {
- fileWriter = new FileWriter(file);
- JSONObject obj = new JSONObject();
- obj.put("musicVol", musicVol.getValue());
- obj.put("effectsVol", effectsVol.getValue());
- obj.writeJSONString(fileWriter);
- fileWriter.flush();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/src/main/java/net/sowgro/npehero/main/SoundController.java b/src/main/java/net/sowgro/npehero/main/Sound.java
index e27221e..088eab6 100755
--- a/src/main/java/net/sowgro/npehero/main/SoundController.java
+++ b/src/main/java/net/sowgro/npehero/main/Sound.java
@@ -1,18 +1,15 @@
package net.sowgro.npehero.main;
-import java.io.File;
-import java.util.HashMap;
-
import javafx.scene.media.AudioClip;
import net.sowgro.npehero.Driver;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
-public class SoundController
+public class Sound
{
public static MediaPlayer songMediaPlayer;
- public static final Media MENUSONG = new Media(Driver.getResource("fairyfountain.wav").toString());
+ public static final Media MENU_SONG = new Media(Driver.getResource("fairyfountain.wav").toString());
public static final AudioClip HIT = new AudioClip(Driver.getResource("hit.wav").toString());
public static final AudioClip MISS = new AudioClip(Driver.getResource("miss.wav").toString());
@@ -21,23 +18,25 @@ public class SoundController
/**
* plays the song that is passed in.
- * @param song the song to play
+ * @param song The song to play.
*/
public static void playSong(Media song)
{
- if (songMediaPlayer != null)
- {
+ if (songMediaPlayer != null) {
songMediaPlayer.stop();
}
songMediaPlayer = new MediaPlayer(song);
- songMediaPlayer.volumeProperty().bind(SettingsController.musicVol);
+ if (song == MENU_SONG) {
+ songMediaPlayer.muteProperty().bind(Settings.enableMenuMusic.not());
+ }
+ songMediaPlayer.volumeProperty().bind(Settings.musicVol);
songMediaPlayer.play();
}
/**
- * stops the currently playing song
+ * Stops the currently playing song.
*/
- public static void endSong()
+ public static void stopSong()
{
if (songMediaPlayer != null)
{
@@ -46,12 +45,12 @@ public class SoundController
}
/**
- * plays a sound effect
- * @param clip the sound to play
+ * Plays a sound effect.
+ * @param clip The sound effect to play.
*/
public static void playSfx(AudioClip clip)
{
- clip.volumeProperty().bind(SettingsController.effectsVol);
+ clip.volumeProperty().bind(Settings.effectsVol);
clip.play();
}
} \ No newline at end of file
diff --git a/src/main/resources/net/sowgro/npehero/style.css b/src/main/resources/net/sowgro/npehero/style.css
index b0a0209..1637c4a 100755
--- a/src/main/resources/net/sowgro/npehero/style.css
+++ b/src/main/resources/net/sowgro/npehero/style.css
@@ -1,9 +1,12 @@
@import url('https://fonts.googleapis.com/css2?family=Space+Mono&display=swap');
+@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
+@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap');
/* global */
-.root{
+.root {
-fx-font-family: "space mono";
+ -fx-font-weight: 400;
-fx-font-size: 20;
}
@@ -16,6 +19,7 @@ Button, TextField, RadioButton, ToggleButton, ColorPicker {
-fx-border-radius: 5;
-fx-font-size: 25;
-fx-background-radius: 5;
+ /*-fx-font-weight: 800;*/
}
Button:hover, TextField:hover, RadioButton:hover, ToggleButton:hover, ColorPicker:hover {
@@ -237,6 +241,15 @@ Slider:focused .thumb{
-fx-text-fill: #a8a8a8;
}
+CheckBox {
+ -fx-text-fill: white;
+}
+
+CheckBox:selected > .box {
+ -fx-background-color: white;
+ -fx-text-fill: black;
+}
+
/* debug */
.debug {