Skip to content

Commit

Permalink
Merge pull request #15 from Chrisvenator/globally-show-bpm
Browse files Browse the repository at this point in the history
Globally show bpm
  • Loading branch information
Chrisvenator authored Aug 13, 2024
2 parents 76f16f9 + 7be6fd3 commit ed9726d
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ libs/*
/database/.idea/dataSources.xml
/database/.idea/modules.xml
/database/.idea/vcs.xml
/src/main/resources/All_Maps_Merged.json
/All_Maps_Merged.json
/OnsetGeneration/mp3Files/
/database/exported_schema.sql
config.json
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/DataManager/CreateAllNecessaryDIRsAndFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class CreateAllNecessaryDIRsAndFiles {
public static final Set<String> foldersToCopyOutOfJar = Set.of(
"OnsetGeneration",
"README",
"README.md",
"Patterns",
"dev",
"assets"
Expand All @@ -35,7 +35,7 @@ public static void createAllNecessaryDIRsAndFiles() {
System.out.println("Creating all necessary directories and files.");

createConfig();
if (DEFAULT_PATH.contains("Steam")) throw new RuntimeException("Hier ist der Fehler: " + DEFAULT_PATH);
// if (DEFAULT_PATH.contains("Steam")) throw new RuntimeException("Hier ist der Fehler: " + DEFAULT_PATH);

try {
extractSpecificFolders("./", foldersToCopyOutOfJar);
Expand All @@ -48,7 +48,7 @@ public static void createAllNecessaryDIRsAndFiles() {

public static void extractSpecificFolders(String destDir, Set<String> foldersToExtract) throws IOException {
// Get the path of the running JAR file
String jarPath = new File(CreateAllNecessaryDIRsAndFiles.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();
String jarPath = new File(CreateAllNecessaryDIRsAndFiles.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath().replaceAll("%20", " ");

// Open the JAR file as a stream
try (JarInputStream jarInputStream = new JarInputStream(Files.newInputStream(Paths.get(jarPath)))) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/DataManager/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import DataManager.Config.Configuration;
import DataManager.Records.PatMetadata;
import UserInterface.Elements.Buttons.ButtonTypes.GlobalButtons.Buttons.Common.DifficultyFileNameExtensionFilter;
import UserInterface.UserInterface;
import javafx.util.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -79,7 +80,8 @@ public class Parameters {
public static final Color darkModeForegroundColor = COLORS.darkModeForegroundColor;

//Note Generator settings:
public static final double BPM = MAP_GENERATOR.defaultBpm;
// public static double BPM = AUTOLOAD_DEFAULT_MAP_for_testing ? 1 : MAP_GENERATOR.defaultBpm;
public static double BPM = MAP_GENERATOR.defaultBpm;
public static final double PLACEMENT_PRECISION = MAP_GENERATOR.defaultPlacementPrecision; //Placement Precision
public static final boolean FIX_PLACEMENTS = MAP_GENERATOR.fixPlacements; //should the timings be fixed so that BeatSaver doesn't flag it as AI made?
public static final boolean SHOW_SPECTOGRAM_WHEN_GENERATING_ONSETS = MAP_GENERATOR.showSpectogramWhenGeneratingOnsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class FixSwingTimings {
public static List<Note> fixSwingTiming(List<Note> notes) {
if (bpm == -1) return notes;
// if (bpm == -1) return notes;
List<Note> newNotes = new ArrayList<Note>();

//TODO: Hier weitermachen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package MapGeneration.PatternGeneration.CommonMethods;

import java.util.function.Function;

import static DataManager.Parameters.logger;

public class Parser {
public static <T extends Number> T parseValue(String input, String loggerLogAs, Function<String, T> parser, T defaultValue) {
try {
T parsedValue = parser.apply(input);
logger.info("Current {}: {}", loggerLogAs, parsedValue);
System.out.println("Current " + loggerLogAs + ": " + parsedValue);

return parsedValue;
} catch (NumberFormatException ex) {
String errorMessage = loggerLogAs + ": " + input + " is not a number!";
logger.error(errorMessage);
System.err.println(errorMessage);
}

return defaultValue;
}
}
3 changes: 1 addition & 2 deletions src/main/java/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class Start {

/**
*********** Planned Features ***********
* SaveMap confirmation button
* Bei schnellen Sektionen abwechselndes Pattern machen mit gleichen Abständen
* lehnen
*****************************************
Expand All @@ -50,7 +49,7 @@ public static void main(String[] args) throws NoteNotValidException {
logger.info("Seed: {}", SEED);
logger.info("Setting Hibernate Logger to warning");

if (executedByJar && !new File("./congi.json").exists()) {
if (executedByJar && !new File("./config.json").exists()) {
logger.info("Found that the program is executed by a jar file.");
CreateAllNecessaryDIRsAndFiles.createAllNecessaryDIRsAndFiles();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
import UserInterface.Elements.Buttons.ButtonTypes.GlobalButtons.Buttons.*;
import UserInterface.Elements.Buttons.ButtonTypes.MapChecks.MapChecks;
import UserInterface.Elements.Buttons.MyButton;
import UserInterface.Elements.TextFields.GlobalTextFields.GlobalBPMField;
import UserInterface.Elements.TextFields.GlobalTextFields.GlobalSeedFrame;
import UserInterface.UserInterface;

public class GlobalButton extends MyButton {
public final GlobalBPMField globalBPMField;

public GlobalButton(UserInterface ui) {
//Create a quasi-button so that the other global buttons can inherit from it
super(new ButtonType("", -1, -1, 0, 0, false), ui);
init();
globalBPMField = new GlobalBPMField(ui);
// init();
}

private void init() {
public void init() {
this.addChild(new GlobalOpenMapButton(ui));
this.addChild(globalBPMField);
this.addChild(new GlobalConvertMP3ToMaps(ui));
this.addChild(new GlobalOpenFolder(ui));
this.addChild(new GlobalLoadPatterns(ui));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package UserInterface.Elements.Buttons.ButtonTypes.GlobalButtons.Buttons;

import BeatSaberObjects.Objects.BeatSaberMap;
import DataManager.FileManager;
import DataManager.Parameters;
import MapGeneration.PatternGeneration.CommonMethods.Parser;
import UserInterface.Elements.Buttons.ButtonTypes.GlobalButtons.Exceptions.WrongFileException;
import UserInterface.Elements.Buttons.ButtonTypes.GlobalButtons.GlobalButton;
import UserInterface.Elements.ElementTypes;
Expand All @@ -10,8 +12,10 @@
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static DataManager.Parameters.AUTOLOAD_DEFAULT_MAP_for_testing;
import static DataManager.Parameters.BPM;
import static DataManager.Parameters.DEFAULT_PATH_FOR_AUTOLOAD_MAP;
import static DataManager.Parameters.FILE_CHOOSER;
import static DataManager.Parameters.MAP_FILE_FORMAT;
Expand Down Expand Up @@ -69,6 +73,7 @@ public void onClick() {

//Change filePath because before, we set it to the parent dir and not the current (working) dir
filePath = path.getAbsolutePath();
extractAndSetGlobalBPM(path);
for (File f : files) {
System.out.println("Found file: " + f.getName());
loadMap(f);
Expand All @@ -78,7 +83,9 @@ public void onClick() {
logger.error("Wrong file type While loading difficulty: {}", path.getName());
throw new WrongFileException(path.getName(), "Wrong file type!");
} else loadMap(path);
extractAndSetGlobalBPM(path.getParentFile());
}

successfullyLoaded(FILE_CHOOSER.getSelectedFile().getAbsolutePath());
}
catch (WrongFileException e) {
Expand All @@ -90,19 +97,41 @@ public void onClick() {
}
}

private void loadMap(File path){
public void loadMap(File path){
ui.map.add(BeatSaberMap.newMapFromJSON(path.getAbsolutePath()));
Parameters.PARITY_ERRORS_LIST.put(path.getName(), new ArrayList<>());

logger.info("Successfully loaded: {}/{}", path.getParent(), path.getName());
System.out.println("Successfully loaded: " + path.getParent() + "/" + path.getName());

extractAndSetGlobalBPM(path);
}

private void extractAndSetGlobalBPM (File path){
File info = new File(path.getParentFile().getAbsolutePath() + "/info.dat");
if (!info.exists() || !info.isFile() || !info.canRead()) {return;}

List<String> infoFile = FileManager.readFile(info.getAbsolutePath());
String searchString = "\"_beatsPerMinute\": ";
for (String line : infoFile) {
if (line.contains(searchString)){
ui.globalButton.globalBPMField.setBPM(
Parser.parseValue(
line.substring(line.indexOf(searchString) + searchString.length(), line.lastIndexOf(",")),
"bpm according to info.at",
Double::parseDouble,
BPM
) // Parser
); //set bpm
}
}
}

private void errorWhileLoading(Exception e) {
logger.error("Error while loading Map. Map probably has the wrong format: {}", e.getMessage());
System.err.println("[ERROR]: Map probably has the wrong format: \n" + e);
ui.labelMapDiff.setText("There was an error while importing the map!");
ui.labelMapDiff.setBounds(100, 20, 300, 30);
ui.labelMapDiff.setBounds(60, 20, 300, 30);
this.setBounds(320, 20, 300, 30);
this.setBackground(Color.RED);
ui.mapSuccessfullyLoaded = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ else if (ui.map.size() == 1) {
}
}

//TODO: Es werden nur 3 von 4 gespeichert!
private boolean createBackup(String filePath) {
File f = new File(filePath);
if (!f.exists()) return true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/UserInterface/Elements/ElementTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ElementTypes {
// public static final ButtonType GLOBAL_SHOW_PATTERNS_BUTTON = new ButtonType("Show", 415, 75, 70, 20, true);

//Global Text Field Types
public static final TextFieldType GLOBAL_SEED_FRAME = new TextFieldType(String.valueOf(Parameters.SEED), 1000, 20, 100, 20, true);
public static final TextFieldType GLOBAL_SEED_FIELD = new TextFieldType(String.valueOf(Parameters.SEED), 1000, 20, 100, 20, true);
public static final TextFieldType GLOBAL_BPM_FIELD = new TextFieldType(String.valueOf(Parameters.BPM), 100, 50, 100, 20, true);
public static final SliderTypes GLOBAL_PATTERN_VARIANCE_SLIDER = new SliderTypes(JSlider.HORIZONTAL, 50, 70, 200, 50, true, -50, 50, 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package UserInterface.Elements.TextFields.GlobalTextFields;

import DataManager.Parameters;
import UserInterface.Elements.ElementTypes;
import UserInterface.Elements.TextFields.MyGlobalTextField;
import UserInterface.UserInterface;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

import static DataManager.Parameters.BPM;
import static DataManager.Parameters.logger;

public class GlobalBPMField extends MyGlobalTextField {

public GlobalBPMField(UserInterface ui) {
super(ElementTypes.GLOBAL_BPM_FIELD, ui);

JLabel label = new JLabel("BPM:");
label.setBounds(60, 50, 40, 20);
if (Parameters.DARK_MODE) label.setForeground(Color.white);
ui.add(label);

this.addKeyListener(new BPMKeyListener("BPM"));
logger.debug("GlobalBPMField initialized: {}", BPM);
}

public void setBPM(double bpm){
this.setText(bpm + "");
}

private class BPMKeyListener extends NumericKeyListener {
public BPMKeyListener(String name) {
super(name, 18, "abc");
}

@Override
public void keyReleased(KeyEvent e) {
super.setLabelText(GlobalBPMField.this.getText());

double value = getDoubleValue();
if (value >= 0) {
BPM = value;
setBPM(BPM);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,35 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import static DataManager.Parameters.SEED;
import static DataManager.Parameters.logger;

public class GlobalSeedFrame extends MyGlobalTextField {

public GlobalSeedFrame(UserInterface ui) {
super(ElementTypes.GLOBAL_SEED_FRAME, ui);
super(ElementTypes.GLOBAL_SEED_FIELD, ui);

JLabel seedLabel = new JLabel("Seed:");
seedLabel.setBounds(960, 17, 40, 20);
if (Parameters.DARK_MODE) seedLabel.setForeground(Color.white);
ui.add(seedLabel);

if (Parameters.DARK_MODE) setBackground(Color.black);
if (Parameters.DARK_MODE) setForeground(Color.white);

addKeyListener(new MyKeyListener());
this.addKeyListener(new SeedKeyListener("Seed"));
logger.debug("GlobalSeedFrame initialized: {}", SEED);
}

private class MyKeyListener implements KeyListener {
@Override
public void keyTyped(KeyEvent e) {
// Autogenerated. Not needed
}

@Override
public void keyPressed(KeyEvent e) {
// Autogenerated. Not needed
private class SeedKeyListener extends NumericKeyListener {
public SeedKeyListener(String name) {
super(name, 18, ElementTypes.GLOBAL_SEED_FIELD.value());
}

@Override
public void keyReleased(KeyEvent e) {
try {
if (GlobalSeedFrame.this.getText().length() >= 18) throw new IllegalArgumentException();
SEED = Long.parseLong(GlobalSeedFrame.this.getText().replace(" ", ""));
logger.info("Current Seed: {}", SEED);
System.out.println("Current Seed: " + SEED);
} catch (NumberFormatException ex) {
String errorMessage = "Seed is not a number!";
logger.error(errorMessage);
} catch (IllegalArgumentException ex) {
String errorMessage = "Seed is too long! It must be at most 18 digits long!";
logger.error(errorMessage);
}
super.setLabelText(GlobalSeedFrame.this.getText());

long value = getLongValue();
if (value >= 0) SEED = value;
}
}
}
Loading

0 comments on commit ed9726d

Please sign in to comment.