aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/module-info.java2
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/Driver.java16
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/DiffEditor.java11
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/devmenu/LevelEditor.java2
-rw-r--r--src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java64
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/GameOver.java6
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LeaderboardView.java6
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelSelector.java6
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelSurround.java6
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/MainMenu.java25
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/SettingsEditor.java6
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Difficulty.java14
-rw-r--r--src/main/java/net/sowgro/npehero/main/JSONFile.java73
-rw-r--r--src/main/java/net/sowgro/npehero/main/Leaderboard.java116
-rw-r--r--src/main/java/net/sowgro/npehero/main/Page.java9
15 files changed, 185 insertions, 177 deletions
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index dd166f8..09cc9e7 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -2,8 +2,8 @@ module net.sowgro.npehero {
requires javafx.controls;
requires javafx.fxml;
requires javafx.media;
- requires json.simple;
requires java.desktop;
+ requires com.fasterxml.jackson.databind;
exports net.sowgro.npehero;
} \ No newline at end of file
diff --git a/src/main/java/net/sowgro/npehero/Driver.java b/src/main/java/net/sowgro/npehero/Driver.java
index 1c6409a..fa36ee5 100755
--- a/src/main/java/net/sowgro/npehero/Driver.java
+++ b/src/main/java/net/sowgro/npehero/Driver.java
@@ -12,11 +12,8 @@ import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.util.Duration;
-import net.sowgro.npehero.main.Control;
+import net.sowgro.npehero.main.*;
import net.sowgro.npehero.gui.MainMenu;
-import net.sowgro.npehero.main.Levels;
-import net.sowgro.npehero.main.Settings;
-import net.sowgro.npehero.main.Sound;
import java.net.URL;
@@ -30,6 +27,8 @@ public class Driver extends Application
static ImageView backgroundImage = new ImageView();
static ImageView backgroundImage2 = new ImageView();
+ static Page currentPage = null;
+
/*
* starts javafx
*/
@@ -101,6 +100,15 @@ public class Driver extends Application
return (Pane) primaryPane.getContent();
}
+ public static void setMenu(Page p) {
+ if (currentPage != null) {
+ currentPage.onLeave();
+ }
+ currentPage = p;
+ setMenu(currentPage.getContent());
+ currentPage.onView();
+ }
+
/**
* Replaces the background image with a new one.
* @param image The image to set.
diff --git a/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java b/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
index de9aad8..f5c29bd 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/DiffEditor.java
@@ -84,10 +84,12 @@ public class DiffEditor extends Pane
HBox content = new HBox();
ScrollPane scroll = new ScrollPane(content);
+ scroll.setFitToWidth(true);
this.scroll = scroll;
scroll.getStyleClass().remove("scroll-pane");
scroll.getStyleClass().add("box");
- scroll.setPrefHeight(400);
+// scroll.setPrefHeight(400);
+ scroll.prefWidthProperty().bind(scroll.heightProperty().multiply(0.66));
Pane[] lanes = new Pane[5];
for (int i = 0; i < lanes.length; i++) {
@@ -95,6 +97,8 @@ public class DiffEditor extends Pane
}
content.getChildren().addAll(lanes);
+ content.setSpacing(5);
+ content.setAlignment(Pos.CENTER);
diff.notes.list.forEach(n -> lanes[n.lane].getChildren().add(drawNote(n)));
@@ -105,7 +109,10 @@ public class DiffEditor extends Pane
validNotes.setInvalid("This difficulty does not contain any notes!");
}
HBox notesLabel = new HBox(new Label("Notes"), validNotes);
- notePreview.getChildren().addAll(notesLabel, scroll, editNotes, oldEditNotes);
+ Pane scrollHolder = new Pane(scroll);
+ scroll.prefHeightProperty().bind(scrollHolder.heightProperty());
+ scrollHolder.setPrefHeight(400);
+ notePreview.getChildren().addAll(notesLabel, scrollHolder, editNotes, oldEditNotes);
notePreview.setSpacing(10);
VBox left = new VBox();
diff --git a/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java b/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
index eef42f5..7efcd05 100755
--- a/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/LevelEditor.java
@@ -34,7 +34,7 @@ public class LevelEditor extends Pane
TextField title = new TextField(level.title);
Text artistLabel = new Text("Artist");
- TextField artist = new TextField(level.title);
+ TextField artist = new TextField(level.artist);
Text descLabel = new Text("Description");
TextField desc = new TextField(level.desc);
diff --git a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
index 1e2874d..46d0235 100644
--- a/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
+++ b/src/main/java/net/sowgro/npehero/devmenu/NotesEditor2.java
@@ -23,14 +23,12 @@ import javafx.util.Duration;
import net.sowgro.npehero.Driver;
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.Sound;
+import net.sowgro.npehero.main.*;
import net.sowgro.npehero.main.Control;
import java.util.concurrent.atomic.AtomicInteger;
-public class NotesEditor2 extends Pane {
+public class NotesEditor2 extends Page {
Difficulty diff;
ScrollPane scroll = new ScrollPane();
Pane[] lanes;
@@ -38,15 +36,17 @@ public class NotesEditor2 extends Pane {
Polygon playhead;
ListProperty<Block> activeNotes = new SimpleListProperty<>(FXCollections.observableArrayList());
ListProperty<Note> noteList;
+ DiffEditor prev;
public NotesEditor2(Difficulty diff, DiffEditor prev) {
-
this.diff = diff;
noteList = diff.notes.deepCopyList();
-
m = new MediaPlayer(new Media(diff.level.song.toURI().toString()));
- Sound.stopSong();
+ this.prev = prev;
+ }
+ @Override
+ public Pane getContent() {
// Buttons
VBox actionBox = new VBox();
actionBox.setSpacing(10);
@@ -86,6 +86,7 @@ public class NotesEditor2 extends Pane {
lane.prefWidthProperty().bind(sizer.widthProperty());
}
Pane rulerLane = new Pane();
+ rulerLane.setManaged(false);
Pane playheadLane = new Pane();
playheadLane.setOnMouseClicked(e -> {
m.seek(new Duration(screenPosToSecond(e.getY()) * 1000));
@@ -123,9 +124,9 @@ public class NotesEditor2 extends Pane {
stackPane.getChildren().addAll(content, contentOverlay);
scroll.setContent(stackPane);
- scroll.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.35));
+// scroll.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.35));
scroll.setMinWidth(400);
- scroll.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
+// scroll.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
scroll.getStyleClass().remove("scroll-pane");
scroll.getStyleClass().add("box");
scroll.setPadding(new Insets(5));
@@ -139,10 +140,8 @@ public class NotesEditor2 extends Pane {
Button exit = new Button();
exit.setText("Cancel");
exit.setOnAction(_ -> {
- m.stop();
Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
- Sound.playSong(Sound.MENU_SONG);
});
Button save = new Button();
@@ -150,10 +149,8 @@ public class NotesEditor2 extends Pane {
save.setOnAction(_ -> {
diff.notes.list = noteList;
diff.notes.writeFile();
- m.stop();
Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(new DiffEditor(diff, prev.prev));
- Sound.playSong(Sound.MENU_SONG);
});
HBox buttons = new HBox(save, exit);
@@ -190,26 +187,26 @@ public class NotesEditor2 extends Pane {
centerBox.setMinWidth(400);
HBox rootBox = new HBox();
- rootBox.prefWidthProperty().bind(super.prefWidthProperty());
- rootBox.prefHeightProperty().bind(super.prefHeightProperty());
+// rootBox.prefWidthProperty().bind(super.prefWidthProperty());
+// rootBox.prefHeightProperty().bind(super.prefHeightProperty());
rootBox.getChildren().add(centerBox);
rootBox.setAlignment(Pos.CENTER);
// write notes on key press
rootBox.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
KeyCode k = e.getCode();
- if (k == Control.LANE0.getKey()) WriteNote(0);
- if (k == Control.LANE1.getKey()) WriteNote(1);
- if (k == Control.LANE2.getKey()) WriteNote(2);
- if (k == Control.LANE3.getKey()) WriteNote(3);
- if (k == Control.LANE4.getKey()) WriteNote(4);
- if (k == Control.NOTE_DOWN.getKey()) MoveNoteDown();
- if (k == Control.NOTE_UP.getKey()) MoveNoteUp();
- if (k == Control.DELETE_NOTE.getKey()) delNote.fire();
- if (k == Control.CLEAR_SELECTION.getKey()) clearSelect.fire();
- if (k == Control.SCROLL_LOCK.getKey()) scrollLock.fire();
- if (k == Control.PLAY_PAUSE.getKey()) play.fire();
- if (k == Control.SELECT_ALL.getKey()) selectAll.fire();
+ if (k == Control.LANE0.getKey()) { WriteNote(0); }
+ if (k == Control.LANE1.getKey()) { WriteNote(1); }
+ if (k == Control.LANE2.getKey()) { WriteNote(2); }
+ if (k == Control.LANE3.getKey()) { WriteNote(3); }
+ if (k == Control.LANE4.getKey()) { WriteNote(4); }
+ if (k == Control.NOTE_DOWN.getKey()) { MoveNoteDown(); }
+ if (k == Control.NOTE_UP.getKey()) { MoveNoteUp(); }
+ if (k == Control.DELETE_NOTE.getKey()) { delNote.fire(); }
+ if (k == Control.CLEAR_SELECTION.getKey()) { clearSelect.fire(); }
+ if (k == Control.SCROLL_LOCK.getKey()) { scrollLock.fire(); }
+ if (k == Control.PLAY_PAUSE.getKey()) { play.fire(); }
+ if (k == Control.SELECT_ALL.getKey()) { selectAll.fire(); }
e.consume();
});
@@ -293,7 +290,18 @@ public class NotesEditor2 extends Pane {
}
});
- super.getChildren().add(rootBox);
+ return rootBox;
+ }
+
+ @Override
+ public void onView() {
+ Sound.stopSong();
+ }
+
+ @Override
+ public void onLeave() {
+ m.stop();
+ Sound.playSong(Sound.MENU_SONG);
}
private Block drawBlock(Note n) {
diff --git a/src/main/java/net/sowgro/npehero/gui/GameOver.java b/src/main/java/net/sowgro/npehero/gui/GameOver.java
index da524dc..cd277e6 100755
--- a/src/main/java/net/sowgro/npehero/gui/GameOver.java
+++ b/src/main/java/net/sowgro/npehero/gui/GameOver.java
@@ -18,11 +18,7 @@ import net.sowgro.npehero.main.Sound;
public class GameOver 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 GameOver(Level level, Difficulty diff, Pane lastMenu, int score2)
{
Text topText = new Text();
diff --git a/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java b/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java
index 4741823..c769264 100755
--- a/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java
+++ b/src/main/java/net/sowgro/npehero/gui/LeaderboardView.java
@@ -17,11 +17,7 @@ import net.sowgro.npehero.main.Sound;
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 LeaderboardView(Level level, Difficulty diff, Pane prev)
{
//sets up table view: requires java bean getters, setters and constructors to work
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSelector.java b/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
index 3553267..eb08a99 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelSelector.java
@@ -15,11 +15,7 @@ import net.sowgro.npehero.main.Sound;
public class LevelSelector 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 LevelSelector()
{
//sets up table view: requires special getters, setters and constructors to work
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
index b864c08..2a0a51a 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
@@ -18,11 +18,7 @@ import net.sowgro.npehero.main.Sound;
public class LevelSurround 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 LevelSurround(Level level, Difficulty difficulty, Pane prev)
{
ScoreController sc = new ScoreController();
diff --git a/src/main/java/net/sowgro/npehero/gui/MainMenu.java b/src/main/java/net/sowgro/npehero/gui/MainMenu.java
index 2587f41..6511f22 100755
--- a/src/main/java/net/sowgro/npehero/gui/MainMenu.java
+++ b/src/main/java/net/sowgro/npehero/gui/MainMenu.java
@@ -10,18 +10,15 @@ 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.Page;
import net.sowgro.npehero.main.Sound;
-public class MainMenu 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 MainMenu()
- {
+public class MainMenu extends Page {
+
+ @Override
+ public Pane getContent() {
+
DropShadow dropShadow = new DropShadow();
dropShadow.setRadius(50.0);
dropShadow.setColor(Color.WHITE);
@@ -34,7 +31,7 @@ public class MainMenu extends Pane
Button play = new Button();
play.setText("Play");
- play.setOnAction(e -> {
+ play.setOnAction(_ -> {
Driver.setMenu(new LevelSelector());
Sound.playSfx(Sound.FORWARD);
});
@@ -47,14 +44,14 @@ public class MainMenu extends Pane
});
Button levelEdit = new Button("Level Editor");
- levelEdit.setOnAction(e -> {
+ levelEdit.setOnAction(_ -> {
Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new LevelList());
});
Button exit = new Button();
exit.setText("Quit");
- exit.setOnAction(e -> {
+ exit.setOnAction(_ -> {
Sound.playSfx(Sound.BACKWARD);
// Driver.quit();
// Platform.exit();
@@ -72,11 +69,9 @@ public class MainMenu extends Pane
centerBox.setSpacing(10);
VBox rootBox = new VBox();
- rootBox.prefWidthProperty().bind(super.prefWidthProperty());
- rootBox.prefHeightProperty().bind(super.prefHeightProperty());
rootBox.setAlignment(Pos.CENTER);
rootBox.getChildren().add(centerBox);
- super.getChildren().add(rootBox);
+ return rootBox;
}
}
diff --git a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
index 4dcd3dc..b00420a 100755
--- a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
+++ b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
@@ -16,11 +16,7 @@ import net.sowgro.npehero.main.Sound;
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 SettingsEditor()
{
Text musicText = new Text();
diff --git a/src/main/java/net/sowgro/npehero/main/Difficulty.java b/src/main/java/net/sowgro/npehero/main/Difficulty.java
index c6155bd..290461d 100755
--- a/src/main/java/net/sowgro/npehero/main/Difficulty.java
+++ b/src/main/java/net/sowgro/npehero/main/Difficulty.java
@@ -1,11 +1,7 @@
package net.sowgro.npehero.main;
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
-import java.security.spec.ECField;
-
-import org.json.simple.JSONObject;
public class Difficulty implements Comparable<Difficulty>
{
@@ -55,15 +51,13 @@ public class Difficulty implements Comparable<Difficulty>
}
public void validate() {
- isValid = true;
-
if (notes.list.isEmpty()) {
isValid = false;
}
- if (numBeats == 0) {
- isValid = false;
- }
+// if (numBeats == 0) {
+// isValid = false;
+// }
}
/**
@@ -86,4 +80,6 @@ public class Difficulty implements Comparable<Difficulty>
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
index ed76369..d06ca1f 100644
--- a/src/main/java/net/sowgro/npehero/main/JSONFile.java
+++ b/src/main/java/net/sowgro/npehero/main/JSONFile.java
@@ -1,8 +1,10 @@
package net.sowgro.npehero.main;
-import net.sowgro.npehero.Driver;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.*;
@@ -12,7 +14,9 @@ import java.io.*;
public class JSONFile {
private final File file;
- private JSONObject jsonObject = new JSONObject();
+ ObjectMapper objectMapper = new ObjectMapper();
+ ObjectNode writeNode = objectMapper.createObjectNode();
+ JsonNode readNode;
public JSONFile(File file) {
try {
@@ -24,18 +28,18 @@ public class JSONFile {
}
public String getString(String key, String def) {
- if (!jsonObject.containsKey(key)) {
+ if (!readNode.has(key)) {
return def;
}
- return jsonObject.get(key).toString();
+ return readNode.get(key).asText();
}
public int getInt(String key, int def) {
- if (!jsonObject.containsKey(key)) {
+ if (!readNode.has(key)) {
return def;
}
try {
- return Integer.parseInt(jsonObject.get(key).toString());
+ return Integer.parseInt(readNode.get(key).asText());
}
catch (NumberFormatException e) {
return def;
@@ -43,59 +47,62 @@ public class JSONFile {
}
public double getDouble(String key, double def) {
- if (jsonObject.containsKey(key)) {
- try {
- return Double.parseDouble(jsonObject.get(key).toString());
- }
- catch (NumberFormatException e) {
- return def;
- }
+ if (!readNode.has(key)) {
+ return def;
+ }
+ try {
+ return Double.parseDouble(readNode.get(key).asText());
}
- else {
+ catch (NumberFormatException e) {
return def;
}
}
public boolean getBoolean(String key, boolean def) {
- if (!jsonObject.containsKey(key)) {
+ if (!readNode.has(key)) {
return def;
}
try {
- return Boolean.parseBoolean(jsonObject.get(key).toString());
+ return Boolean.parseBoolean(readNode.get(key).asText());
}
catch (NumberFormatException e) {
return def;
}
}
- public void set(String key, Object value) {
+ public void set(String key, String value) {
if (value == null) {
return;
}
- jsonObject.put(key, value);
+ writeNode.put(key, value);
+ }
+
+ public void set(String key, int value) {
+ writeNode.put(key, value);
+ }
+
+ public void set(String key, double value) {
+ writeNode.put(key, value);
+ }
+
+ public void set(String key, boolean value) {
+ writeNode.put(key, value);
}
public boolean containsKey(String key) {
- return jsonObject.containsKey(key);
+ return writeNode.has(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;
+ if (file.length() == 0) {
+ readNode = objectMapper.createObjectNode();
+ return;
}
+ readNode = objectMapper.readTree(file);
}
public void write() throws IOException {
- FileWriter fileWriter = new FileWriter(file);
- jsonObject.writeJSONString(fileWriter);
- fileWriter.close();
+ objectMapper.writeValue(file, writeNode);
}
}
diff --git a/src/main/java/net/sowgro/npehero/main/Leaderboard.java b/src/main/java/net/sowgro/npehero/main/Leaderboard.java
index 6a6b0c2..eb4e5f5 100644
--- a/src/main/java/net/sowgro/npehero/main/Leaderboard.java
+++ b/src/main/java/net/sowgro/npehero/main/Leaderboard.java
@@ -1,10 +1,8 @@
package net.sowgro.npehero.main;
+import com.fasterxml.jackson.databind.JsonNode;
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;
@@ -35,62 +33,62 @@ public class Leaderboard {
/**
* 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;
- }
+// 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)
+// {
+// JsonNode obj = new ;
+// 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/Page.java b/src/main/java/net/sowgro/npehero/main/Page.java
new file mode 100644
index 0000000..beaf606
--- /dev/null
+++ b/src/main/java/net/sowgro/npehero/main/Page.java
@@ -0,0 +1,9 @@
+package net.sowgro.npehero.main;
+
+import javafx.scene.layout.Pane;
+
+public abstract class Page {
+ abstract public Pane getContent(); // must be implemented
+ public void onView() {} // can optionally be implemented
+ public void onLeave() {}
+}