Add common pathing code and SimplePathing module
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.pathing.change.Change;
|
||||
import com.replaymod.pathing.property.AbstractProperty;
|
||||
import com.replaymod.pathing.property.AbstractPropertyGroup;
|
||||
import com.replaymod.pathing.property.PropertyPart;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import lombok.NonNull;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Properties for camera positioning.
|
||||
*/
|
||||
public class CameraProperties extends AbstractPropertyGroup {
|
||||
public static final CameraProperties GROUP = new CameraProperties();
|
||||
public static final Position POSITION = new Position();
|
||||
public static final Rotation ROTATION = new Rotation();
|
||||
private CameraProperties() {
|
||||
super("camera", "replaymod.gui.camera");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Callable<ListenableFuture<Change>>> getSetter() {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
public static class Position extends AbstractProperty<Triple<Double, Double, Double>> {
|
||||
public final PropertyPart<Triple<Double, Double, Double>>
|
||||
X = new PropertyParts.ForDoubleTriple(this, true, PropertyParts.TripleElement.LEFT),
|
||||
Y = new PropertyParts.ForDoubleTriple(this, true, PropertyParts.TripleElement.MIDDLE),
|
||||
Z = new PropertyParts.ForDoubleTriple(this, true, PropertyParts.TripleElement.RIGHT);
|
||||
|
||||
private Position() {
|
||||
super("position", "replaymod.gui.position", GROUP, Triple.of(0d, 0d, 0d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Triple<Double, Double, Double>>> getParts() {
|
||||
return Arrays.asList(X, Y, Z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Triple<Double, Double, Double> value, @NonNull ReplayHandler replayHandler) {
|
||||
replayHandler.getCameraEntity().setCameraPosition(value.getLeft(), value.getMiddle(), value.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Triple<Double, Double, Double> value) throws IOException {
|
||||
writer.beginArray().value(value.getLeft()).value(value.getMiddle()).value(value.getRight()).endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Double, Double, Double> fromJson(JsonReader reader) throws IOException {
|
||||
reader.beginArray();
|
||||
try {
|
||||
return Triple.of(reader.nextDouble(), reader.nextDouble(), reader.nextDouble());
|
||||
} finally {
|
||||
reader.endArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Rotation extends AbstractProperty<Triple<Float, Float, Float>> {
|
||||
public final PropertyPart<Triple<Float, Float, Float>>
|
||||
YAW = new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.LEFT),
|
||||
PITCH = new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.MIDDLE),
|
||||
ROLL = new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.RIGHT);
|
||||
|
||||
private Rotation() {
|
||||
super("rotation", "replaymod.gui.rotation", GROUP, Triple.of(0f, 0f, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Triple<Float, Float, Float>>> getParts() {
|
||||
return Arrays.asList(YAW, PITCH, ROLL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Triple<Float, Float, Float> value, @NonNull ReplayHandler replayHandler) {
|
||||
replayHandler.getCameraEntity().setCameraRotation(value.getLeft(), value.getMiddle(), value.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Triple<Float, Float, Float> value) throws IOException {
|
||||
writer.beginArray().value(value.getLeft()).value(value.getMiddle()).value(value.getRight()).endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> fromJson(JsonReader reader) throws IOException {
|
||||
reader.beginArray();
|
||||
try {
|
||||
return Triple.of((float) reader.nextDouble(), (float) reader.nextDouble(), (float) reader.nextDouble());
|
||||
} finally {
|
||||
reader.endArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.replaymod.pathing.property.AbstractPropertyPart;
|
||||
import com.replaymod.pathing.property.Property;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
public class PropertyParts {
|
||||
private PropertyParts(){}
|
||||
|
||||
public static class ForInteger extends AbstractPropertyPart<Integer> {
|
||||
public ForInteger(Property<Integer> property, boolean interpolatable) {
|
||||
super(property, interpolatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(Integer value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer fromDouble(Integer value, double d) {
|
||||
return (int) Math.round(d);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ForDoubleTriple extends AbstractPropertyPart<Triple<Double, Double, Double>> {
|
||||
private final TripleElement element;
|
||||
public ForDoubleTriple(Property<Triple<Double, Double, Double>> property, boolean interpolatable, TripleElement element) {
|
||||
super(property, interpolatable);
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(Triple<Double, Double, Double> value) {
|
||||
switch (element) {
|
||||
case LEFT: return value.getLeft();
|
||||
case MIDDLE: return value.getMiddle();
|
||||
case RIGHT: return value.getRight();
|
||||
}
|
||||
throw new AssertionError(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Double, Double, Double> fromDouble(Triple<Double, Double, Double> value, double d) {
|
||||
switch (element) {
|
||||
case LEFT: return Triple.of(d, value.getMiddle(), value.getRight());
|
||||
case MIDDLE: return Triple.of(value.getLeft(), d, value.getRight());
|
||||
case RIGHT: return Triple.of(value.getLeft(), value.getMiddle(), d);
|
||||
}
|
||||
throw new AssertionError(element);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ForFloatTriple extends AbstractPropertyPart<Triple<Float, Float, Float>> {
|
||||
private final TripleElement element;
|
||||
public ForFloatTriple(Property<Triple<Float, Float, Float>> property, boolean interpolatable, TripleElement element) {
|
||||
super(property, interpolatable);
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(Triple<Float, Float, Float> value) {
|
||||
switch (element) {
|
||||
case LEFT: return value.getLeft();
|
||||
case MIDDLE: return value.getMiddle();
|
||||
case RIGHT: return value.getRight();
|
||||
}
|
||||
throw new AssertionError(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> fromDouble(Triple<Float, Float, Float> value, double d) {
|
||||
switch (element) {
|
||||
case LEFT: return Triple.of((float) d, value.getMiddle(), value.getRight());
|
||||
case MIDDLE: return Triple.of(value.getLeft(), (float) d, value.getRight());
|
||||
case RIGHT: return Triple.of(value.getLeft(), value.getMiddle(), (float) d);
|
||||
}
|
||||
throw new AssertionError(element);
|
||||
}
|
||||
}
|
||||
|
||||
public enum TripleElement {
|
||||
LEFT, MIDDLE, RIGHT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.pathing.property.AbstractProperty;
|
||||
import com.replaymod.pathing.property.PropertyPart;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.ReplaySender;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Property for the time in the replay.
|
||||
*/
|
||||
public class TimestampProperty extends AbstractProperty<Integer> {
|
||||
public static final TimestampProperty PROPERTY = new TimestampProperty();
|
||||
public final PropertyPart<Integer> TIME = new PropertyParts.ForInteger(this, true);
|
||||
private TimestampProperty() {
|
||||
super("timestamp", "replaymod.gui.editkeyframe.timestamp", null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Integer>> getParts() {
|
||||
return Collections.singletonList(TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Integer value, @NonNull ReplayHandler replayHandler) {
|
||||
ReplaySender replaySender = replayHandler.getReplaySender();
|
||||
if (replaySender.isAsyncMode()) {
|
||||
replaySender.jumpToTime(value);
|
||||
} else {
|
||||
replaySender.sendPacketsTill(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Integer value) throws IOException {
|
||||
writer.value(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer fromJson(JsonReader reader) throws IOException {
|
||||
return reader.nextInt();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user