Skip to content

Commit

Permalink
added dark Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisvenator committed Aug 9, 2023
1 parent 10e22aa commit 7f4a473
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ When you click on Map creator you will then have a few options:<br>
| **`small jumps`**<br>Depending on the previous notes the blue or red note comes first | ![small jumps gif](./assets/small_jumps.gif) |
| **`normal jumps`**<br>Depending on the previous notes the blue or red note comes first | ![normal jumps gif](./assets/normal_jumps.gif) |
| **`big jumps`**<br>Depending on the previous notes the blue or red note comes first<br>*Currently broken D:* | ![big jumps gif](./assets/big-jumps.gif) |
| **`sequence`**<br>*Currently under construction* | ![sequence gif](./assets/sequence.gif) |
| **`sequence`**<br>*Currently under construction* | *to be added* |

<br>

Expand Down Expand Up @@ -145,7 +145,7 @@ TODO: Explain what load patterns does<br>
- [ ] more variation
- [ ] stacks
- [ ] Better music onsets
- [ ] Dark Mode
- [x] Dark Mode
- [x] Finish README.MD
- [x] FIX BIG JUMPS
- [ ] add V3 support
3 changes: 3 additions & 0 deletions config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaultPath:C:/Program Files/Steam/steamapps/common/Beat Saber/Beat Saber_Data/CustomWIPLevels
verbose:false //It is not recommended to change this except for debugging purposes.
dark-mode:false
Empty file added input.txt
Empty file.
Binary file added lib/gson-2.10.1.jar
Binary file not shown.
35 changes: 22 additions & 13 deletions src/CreateAllNecessaryDIRsAndFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.nio.file.Paths;

public class CreateAllNecessaryDIRsAndFiles {
public static boolean main() {
public static void createAllNecessaryDIRsAndFiles() {
//Checking if the directories exist.
//If yes, then don't create them again
File f1 = new File("./PatternTemplates");
File f2 = new File("./PreMadePatterns");
if (f1.exists() && f1.isDirectory() && f2.exists() && f2.isDirectory()) {
return true;
return;
}

String[] templateFilesToCopy = {
Expand All @@ -24,28 +24,39 @@ public static boolean main() {
"README.md"
};

String config = "defaultPath:C:/Program Files/Steam/steamapps/common/Beat Saber/Beat Saber_Data/CustomWIPLevels\nverbose:false //It is not recommended to change this except for debugging purposes.";
FileManager.overwriteFile("./config.txt", config);

return createDirectories() && extractFilesFromJar(templateFilesToCopy, "./") && extractFilesFromJar(preMadePatternsFilesToCopy, "./");
createConfigFile();
createDirectories();

extractFilesFromJar(templateFilesToCopy);
extractFilesFromJar(preMadePatternsFilesToCopy);

}

public static boolean createDirectories() {
private static void createConfigFile() {
String config = """
defaultPath:C:/Program Files/Steam/steamapps/common/Beat Saber/Beat Saber_Data/CustomWIPLevels
verbose:false //It is not recommended to change this except for debugging purposes.
dark-mode:false""";
FileManager.overwriteFile("./config.txt", config);
}

public static void createDirectories() {
try {
Files.createDirectories(Paths.get("./PatternTemplates"));
Files.createDirectories(Paths.get("./PreMadePatterns"));
Files.createDirectories(Paths.get("./OnsetGeneration"));
Files.createDirectories(Paths.get("./OnsetGeneration/mp3Files"));
Files.createDirectories(Paths.get("./OnsetGeneration/output"));
} catch (IOException e) {
return false;
System.err.println("There has been an Exception while creating the files:\n");
e.printStackTrace();
}

return true;
}


private static boolean extractFilesFromJar(String[] filesToCopy, String destinationDir) {
private static void extractFilesFromJar(String[] filesToCopy) {
// Get the current ClassLoader
ClassLoader classLoader = CreateAllNecessaryDIRsAndFiles.class.getClassLoader();

Expand All @@ -57,7 +68,7 @@ private static boolean extractFilesFromJar(String[] filesToCopy, String destinat

if (inputStream != null) {
// Create the destination file path
String destinationPath = destinationDir + fileToCopy;
String destinationPath = "./" + fileToCopy;

// Create parent directories if they don't exist
File destinationFile = new File(destinationPath);
Expand All @@ -78,14 +89,12 @@ private static boolean extractFilesFromJar(String[] filesToCopy, String destinat
System.out.println("File copied: " + destinationPath);
} else {
System.out.println("File not found in the JAR: " + fileToCopy);
return false;
return;
}
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}

}
23 changes: 15 additions & 8 deletions src/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class UserInterface extends JFrame {
//config.txt:
private boolean verbose = true; //For debugging purposes. It prints EVERYTHING
private String DEFAULT_PATH = "C:/Program Files/Steam/steamapps/common/Beat Saber/Beat Saber_Data/CustomWIPLevels";
private boolean darkMode = false;

private final JLabel labelMapDiff;
private final JButton openMapButton;
Expand All @@ -29,7 +30,7 @@ public class UserInterface extends JFrame {
private final PrintStream ERROR_PRINT_STREAM = new PrintStream(OUTPUT_STREAM);

public static void main(String[] args) {
CreateAllNecessaryDIRsAndFiles.main();
CreateAllNecessaryDIRsAndFiles.createAllNecessaryDIRsAndFiles();

UserInterface ui = new UserInterface();
ui.setVisible(true);
Expand All @@ -44,11 +45,14 @@ public UserInterface() {
setTitle("Beat Kenja");
setSize(1200, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (darkMode) getContentPane().setBackground(Color.darkGray);
if (darkMode) getContentPane().setForeground(Color.white);
setLayout(null);


labelMapDiff = new JLabel("Choose map difficulty file: ");
labelMapDiff.setBounds(50, 20, 200, 30);
if (darkMode) labelMapDiff.setForeground(Color.white);
add(labelMapDiff);

//Load Patterns from file
Expand All @@ -73,7 +77,7 @@ public UserInterface() {
//Status Bar:
statusCheck = new TextArea("config: \nverbose: " + verbose + "\npath: " + DEFAULT_PATH + "\n");
statusCheck.setBounds(50, 235, 1090, 510);
statusCheck.setBackground(Color.WHITE);
statusCheck.setBackground(darkMode ? Color.gray : Color.WHITE);
statusCheck.setEditable(false);
add(statusCheck);

Expand Down Expand Up @@ -383,14 +387,14 @@ public UserInterface() {
} catch (InterruptedException ex) {
ex.printStackTrace();
}
calculateNewMap.stop();
calculateNewMap.interrupt();
throw new IllegalArgumentException("Took too long lol");
});

try {
watchForInfiniteLoop.start();
calculateNewMap.start();
watchForInfiniteLoop.stop();
watchForInfiniteLoop.interrupt();
} catch (IllegalArgumentException ex) {
statusCheck.setText(statusCheck.getText() + "\nThere was an error while creating. Please try again!");
}
Expand All @@ -417,14 +421,14 @@ public UserInterface() {
} catch (InterruptedException ex) {
ex.printStackTrace();
}
calculateNewMap.stop();
calculateNewMap.interrupt();
throw new IllegalArgumentException("Took too long lol");
});

try {
watchForInfiniteLoop.start();
calculateNewMap.start();
watchForInfiniteLoop.stop();
watchForInfiniteLoop.interrupt();
} catch (IllegalArgumentException ex) {
statusCheck.setText(statusCheck.getText() + "\nThere was an error while creating. Please try again!");
}
Expand Down Expand Up @@ -477,14 +481,14 @@ public UserInterface() {

private void convertMp3ToMap() {
try {
statusCheck.setBackground(Color.GRAY);
statusCheck.setBackground(darkMode ? Color.darkGray : Color.gray);
openSongButton.setText("In Progress...");
statusCheck.setText(statusCheck.getText() + "\nINFO: Converting all Songs from OnsetGeneration/mp3Files/ to timing maps.\nThis might take a while if there are a lot of songs.\n");
statusCheck.setText(statusCheck.getText() + "You can always check the progress when heading to \"OnsetGeneration/output/\"\n");
Thread.sleep(1000);
BatchWavToMaps.generateOnsets("./OnsetGeneration/mp3Files/", "./OnsetGeneration/output/", true);
statusCheck.setText(statusCheck.getText() + "\nSuccessfully created Map. You can find your map in \"OnsetGeneration/output/\"\n\n");
statusCheck.setBackground(Color.WHITE);
statusCheck.setBackground(darkMode ? Color.gray : Color.WHITE);
openSongButton.setText("Convert MP3s to timing maps");
} catch (Exception e) {
System.err.println("ERROR: Something went wrong during conversion. Is it the right file extension?\n" + e);
Expand Down Expand Up @@ -526,6 +530,7 @@ public void loadPatterns() {
loadPatternButton.addActionListener(action -> {

JFileChooser fileChooser = new JFileChooser(DEFAULT_PATH);
if (darkMode) fileChooser.setForeground(Color.white);
int option = fileChooser.showOpenDialog(this);

if (option == JFileChooser.APPROVE_OPTION) {
Expand All @@ -552,6 +557,7 @@ public void loadPatterns() {

public void loadMap() {
JFileChooser fileChooser = new JFileChooser(DEFAULT_PATH);
if (darkMode) fileChooser.setForeground(Color.white);
int option = fileChooser.showOpenDialog(this);

if (option == JFileChooser.APPROVE_OPTION) {
Expand Down Expand Up @@ -610,6 +616,7 @@ public void readConfig() {
String[] splits = s.split(":");
if (s.contains("verbose")) verbose = splits[1].contains("true");
if (s.contains("defaultPath")) DEFAULT_PATH = splits[1] + ":" + splits[2];
if (s.contains("dark-mode")) darkMode = splits[1].contains("true");
}
}
}
Expand Down

0 comments on commit 7f4a473

Please sign in to comment.