Include interpolator properties when serializing

Remove serialization requirement for Change classes
This commit is contained in:
johni0702
2016-07-31 13:52:53 +02:00
parent 68c5d8583a
commit de6e05d0f8
3 changed files with 24 additions and 30 deletions

View File

@@ -8,7 +8,6 @@ import com.replaymod.pathing.properties.TimestampProperty;
import com.replaymod.replay.events.ReplayOpenEvent; import com.replaymod.replay.events.ReplayOpenEvent;
import com.replaymod.replaystudio.pathing.PathingRegistry; import com.replaymod.replaystudio.pathing.PathingRegistry;
import com.replaymod.replaystudio.pathing.impl.TimelineImpl; import com.replaymod.replaystudio.pathing.impl.TimelineImpl;
import com.replaymod.replaystudio.pathing.interpolation.AbstractInterpolator;
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator; import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
import com.replaymod.replaystudio.pathing.interpolation.Interpolator; import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator; import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
@@ -97,19 +96,12 @@ public class ReplayModSimplePathing implements PathingRegistry {
@Override @Override
public Interpolator deserializeInterpolator(JsonReader reader) throws IOException { public Interpolator deserializeInterpolator(JsonReader reader) throws IOException {
AbstractInterpolator interpolator;
String type = reader.nextString(); String type = reader.nextString();
switch (type) { switch (type) {
case "linear": case "linear":
interpolator = new LinearInterpolator(); return new LinearInterpolator();
interpolator.registerProperty(TimestampProperty.PROPERTY);
interpolator.registerProperty(CameraProperties.POSITION);
interpolator.registerProperty(CameraProperties.ROTATION);
return interpolator;
case "cubic-spline": case "cubic-spline":
interpolator = new CubicSplineInterpolator(); return new CubicSplineInterpolator();
interpolator.registerProperty(CameraProperties.POSITION);
interpolator.registerProperty(CameraProperties.ROTATION);
default: default:
throw new IOException("Unknown interpolation type: " + type); throw new IOException("Unknown interpolation type: " + type);

View File

@@ -12,8 +12,8 @@ import com.replaymod.replay.ReplayHandler;
import com.replaymod.replay.camera.CameraEntity; import com.replaymod.replay.camera.CameraEntity;
import com.replaymod.replay.gui.overlay.GuiReplayOverlay; import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
import com.replaymod.replaystudio.pathing.change.*; import com.replaymod.replaystudio.pathing.change.*;
import com.replaymod.replaystudio.pathing.interpolation.AbstractInterpolator;
import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator; import com.replaymod.replaystudio.pathing.interpolation.CubicSplineInterpolator;
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator; import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator;
import com.replaymod.replaystudio.pathing.path.Keyframe; import com.replaymod.replaystudio.pathing.path.Keyframe;
import com.replaymod.replaystudio.pathing.path.Path; import com.replaymod.replaystudio.pathing.path.Path;
@@ -302,23 +302,8 @@ public class GuiPathing {
private void preparePathsForPlayback() { private void preparePathsForPlayback() {
Timeline timeline = mod.getCurrentTimeline(); Timeline timeline = mod.getCurrentTimeline();
Path timePath = timeline.getPaths().get(TIME_PATH); timeline.getPaths().get(TIME_PATH).updateAll();
Path positionPath = timeline.getPaths().get(POSITION_PATH); timeline.getPaths().get(POSITION_PATH).updateAll();
// TODO Change interpolator via Change class
AbstractInterpolator interpolator = new LinearInterpolator();
interpolator.registerProperty(TimestampProperty.PROPERTY);
for (PathSegment segment : timePath.getSegments()) {
segment.setInterpolator(interpolator);
}
interpolator = new CubicSplineInterpolator();
interpolator.registerProperty(CameraProperties.POSITION);
interpolator.registerProperty(CameraProperties.ROTATION);
for (PathSegment segment : positionPath.getSegments()) {
segment.setInterpolator(interpolator);
}
timePath.updateAll();
positionPath.updateAll();
} }
public void zoomTimeline(double factor) { public void zoomTimeline(double factor) {
@@ -357,7 +342,24 @@ public class GuiPathing {
} }
UpdateKeyframeProperties updateChange = builder.done(); UpdateKeyframeProperties updateChange = builder.done();
updateChange.apply(timeline); updateChange.apply(timeline);
// If this new keyframe formed the first segment, then create and set the appropriate interpolator
if (path.getSegments().size() == 1) {
PathSegment segment = path.getSegments().iterator().next();
Interpolator interpolator;
if (isTime) {
interpolator = new LinearInterpolator();
interpolator.registerProperty(TimestampProperty.PROPERTY);
} else {
interpolator = new CubicSplineInterpolator();
interpolator.registerProperty(CameraProperties.POSITION);
interpolator.registerProperty(CameraProperties.ROTATION);
}
SetInterpolator setInterpolator = SetInterpolator.create(segment, interpolator);
setInterpolator.apply(timeline);
timeline.pushChange(CombinedChange.createFromApplied(change, updateChange, setInterpolator));
} else {
timeline.pushChange(CombinedChange.createFromApplied(change, updateChange)); timeline.pushChange(CombinedChange.createFromApplied(change, updateChange));
}
} else { } else {
timeline.pushChange(change); timeline.pushChange(change);
} }