Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/com/replaymod/simplepathing/gui/GuiEditKeyframe.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ timeSecField, new GuiLabel().setI18nText("replaymod.gui.seconds"),

protected boolean canSave() {
try {
long timeMin = timeMinField.getLong();
long timeSec = timeSecField.getLong();
long timeMSec = timeMSecField.getLong();
double timeMin = timeMinField.getDouble();
double timeSec = timeSecField.getDouble();
double timeMSec = timeMSecField.getDouble();

long newTime = (timeMin * 60 + timeSec) * 1000 + timeMSec;
long newTime = (long) ((timeMin * 60 + timeSec) * 1000 + timeMSec);

if (newTime < 0 || newTime > guiPathing.kt.getTimeline().getLengthMillis()) {
return false;
Expand All @@ -122,12 +122,12 @@ public GuiEditKeyframe(GuiPathing gui, SPPath path, long time, String type) {

title.setI18nText("replaymod.gui.editkeyframe.title." + type);
saveButton.onClick(() -> {
long timeMin = timeMinField.getLong();
long timeSec = timeSecField.getLong();
long timeMSec = timeMSecField.getLong();
double timeMin = timeMinField.getDouble();
double timeSec = timeSecField.getDouble();
double timeMSec = timeMSecField.getDouble();

Change change = save();
long newTime = (timeMin * 60 + timeSec) * 1000 + timeMSec;
long newTime = (long) ((timeMin * 60 + timeSec) * 1000 + timeMSec);
if (newTime != time) {
change = CombinedChange.createFromApplied(change,
gui.getMod().getCurrentTimeline().moveKeyframe(path, time, newTime));
Expand Down Expand Up @@ -213,9 +213,9 @@ public Time(GuiPathing gui, SPPath path, long keyframe) {
@Override
protected Change save() throws Expression.ExpressionException, ArithmeticException, NumberFormatException {

long timeMin = timestampMinField.getLong();
long timeSec = timestampSecField.getLong();
long timeMSec = timestampMSecField.getLong();
double timeMin = timestampMinField.getDouble();
double timeSec = timestampSecField.getDouble();
double timeMSec = timestampMSecField.getDouble();

int time = (int) ((timeMin * 60 + timeSec) * 1000 + timeMSec);

Expand All @@ -227,11 +227,11 @@ protected Change save() throws Expression.ExpressionException, ArithmeticExcepti
protected boolean canSave(){
try {

long timeMin = timestampMinField.getLong();
long timeSec = timestampSecField.getLong();
long timeMSec = timestampMSecField.getLong();
double timeMin = timestampMinField.getDouble();
double timeSec = timestampSecField.getDouble();
double timeMSec = timestampMSecField.getDouble();

long time = (timeMin * 60 + timeSec) * 1000 + timeMSec;
long time = (long) ((timeMin * 60 + timeSec) * 1000 + timeMSec);

if (time < 0) { //TODO add check to make sure time isn't longer than the replay
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.replaymod.simplepathing.gui;

import com.udojava.evalex.Expression;
import com.udojava.evalex.ExpressionSettings;
import de.johni0702.minecraft.gui.element.GuiTextField;
import de.johni0702.minecraft.gui.utils.Consumer;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor;

import java.math.BigDecimal;
import java.math.MathContext;

public class GuiExpressionField extends GuiTextField {

private Boolean expressionValid = null;
private int precision = 20;
private MathContext mathContext = new MathContext(20);

@Override
protected void onTextChanged(String from) {
Expand All @@ -21,7 +23,7 @@ protected void onTextChanged(String from) {

private boolean verify(){
try{
getExpression().setPrecision(precision).eval();
getExpression().eval();
setTextColor(ReadableColor.WHITE);
return expressionValid = true;
} catch (Expression.ExpressionException | ArithmeticException | NumberFormatException e){
Expand All @@ -38,20 +40,20 @@ public boolean isExpressionValid(){
}

public GuiExpressionField setPrecision(int precision) {
this.precision = precision;
this.mathContext = new MathContext(precision);
return this;
}

public Expression getExpression() {
return new Expression(getText());
return new Expression(getText(), mathContext);
}

public BigDecimal getBigDecimal() throws Expression.ExpressionException, ArithmeticException, NumberFormatException {
return getExpression().setPrecision(precision).eval();
return getExpression().eval();
}

public long getLong() throws Expression.ExpressionException, ArithmeticException, NumberFormatException {
return getBigDecimal().longValueExact();
return getBigDecimal().longValue();
}

public double getDouble() throws Expression.ExpressionException, ArithmeticException, NumberFormatException {
Expand Down