Skip to content

Commit

Permalink
limit facing precision to 4 digits
Browse files Browse the repository at this point in the history
fix incorrect movement calculation
add correct parsing of double and float values
fix inverting x-axis and facing on copy to clipboard
refactoring

allow all file endings to be imported
  • Loading branch information
Leg0shii committed Apr 23, 2023
1 parent 86d702b commit e5b4489
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/main/java/de/legoshi/parkourcalculator/file/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FileHandler {
public static void saveInputs(List<InputData> inputs, Window window) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Input");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.csv)", "*.csv"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.csv)", "*.csv", "*"));
File file = fileChooser.showSaveDialog(window);
if (file != null) {
CSVUtils.saveTicksToCSV(inputs, file.getAbsolutePath());
Expand All @@ -21,7 +21,7 @@ public static void saveInputs(List<InputData> inputs, Window window) {
public static List<InputData> loadInputs(Window window) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Inputs");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.csv)", "*.csv"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.csv)", "*.csv", "*"));
File file = fileChooser.showOpenDialog(window);

if (file != null) {
Expand All @@ -34,8 +34,9 @@ public static List<InputData> loadInputs(Window window) {
public static void saveBlocks(List<BlockData> blocks, Window window) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Input");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.bcsv)", "*.bcsv"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.bcsv)", "*.bcsv", "*"));
File file = fileChooser.showSaveDialog(window);

if (file != null) {
CSVUtils.saveBlocksToCSV(blocks, file.getAbsolutePath());
}
Expand All @@ -44,7 +45,7 @@ public static void saveBlocks(List<BlockData> blocks, Window window) {
public static List<List<BlockData>> loadBlocks(Window window) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Inputs");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.bcsv)", "*.bcsv"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Input Files (*.bcsv)", "*.bcsv", "*"));
File file = fileChooser.showOpenDialog(window);

if (file != null) {
Expand All @@ -54,5 +55,4 @@ public static List<List<BlockData>> loadBlocks(Window window) {
return null;
}

// Add similar methods for saving and loading Block and Jump objects
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ private String setDecimals(double value) {
return parsedValue;
}

private String setDecimals(float value) {
String parsedValue = String.format("%.4f", value);
if (value == 0) parsedValue = ("" + parsedValue).replace("-", "");
parsedValue = parsedValue.replace(",", ".");
return parsedValue;
}

private Label getSpacer() {
return new Label(" ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public PlayerSettings(CoordinateScreen coordinateScreen, MovementEngine movement
this.xPosField.setText(replaceNegZero(ptiC.getPosition().x*(-1))+ "");
this.yPosField.setText(ptiC.getPosition().y + "");
this.zPosField.setText(ptiC.getPosition().z + "");
this.facingYaw.setText(replaceNegZero(ptiC.getFacing()) + "");
this.facingYaw.setText(replaceNegZero(ptiC.getFacing()*(-1)) + "");

Player player = movementEngine.player;
this.xVelField.setText(replaceNegZero(player.getStartVel().x*(-1)) + "");
Expand All @@ -117,11 +117,11 @@ public PlayerSettings(CoordinateScreen coordinateScreen, MovementEngine movement

Button copyButton = new Button("Copy to Clipboard");
copyButton.setOnAction(event -> {
double x = tryParseDouble(xPosField.getText())*(-1);
double x = tryParseDouble(xPosField.getText());
double y = tryParseDouble(yPosField.getText());
double z = tryParseDouble(zPosField.getText());
double yaw = tryParseDouble(facingYaw.getText());
double pitch = tryParseDouble(facingPitch.getText());
float yaw = tryParseFloat(facingYaw.getText());
float pitch = tryParseFloat(facingPitch.getText());

String tpCommand = "/tp " + x + " " + y + " " + z + " " + yaw + " " + pitch;
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Expand Down Expand Up @@ -207,6 +207,14 @@ private double tryParseDouble(String text) {
}
}

private float tryParseFloat(String text) {
try {
return Float.parseFloat(text);
} catch (NumberFormatException | NullPointerException e) {
return 0.0F;
}
}

private void syncPathAndScreen() {
positionVisualizer.update(null, null);
coordinateScreen.update(null, null);
Expand All @@ -219,7 +227,6 @@ private double getDouble(double oldVal, String text) {

private float getFloat(float oldVal, String text) {
Float d = NumberHelper.parseFloat(text);
System.out.println(d);
return d == null ? oldVal : d;
}

Expand All @@ -229,4 +236,10 @@ private String replaceNegZero(double val) {
return s;
}

private String replaceNegZero(float val) {
String s = val + "";
if (val == 0.0) s = s.replace("-", "");
return s;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void resetPlayer() {
this.position = this.startPos.copy();
this.velocity = this.startVel.copy();
YAW = startYAW;
GROUND = true;
GROUND = false;
WEB = false;
SPRINT = false;
SNEAK = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package de.legoshi.parkourcalculator.parkour.tick;

import javafx.scene.control.CheckBox;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public class InputTick {

public boolean W, A, S, D;
public boolean JUMP, SPRINT, SNEAK = false;

public float YAW = 0;

public InputTick() {
this.W = false;
this.A = false;
this.S = false;
this.D = false;
}
public boolean JUMP, SPRINT, SNEAK;
public float YAW;

public InputTick copy() {
InputTick inputTick = new InputTick();
Expand Down

0 comments on commit e5b4489

Please sign in to comment.