diff --git a/ReplayStudio b/ReplayStudio index 3895d953..ef307b46 160000 --- a/ReplayStudio +++ b/ReplayStudio @@ -1 +1 @@ -Subproject commit 3895d9535f204b0b8e42e5ee6981c92b873ccf70 +Subproject commit ef307b467895098c54345279485bde96579265db diff --git a/src/main/java/com/replaymod/simplepathing/ReplayModSimplePathing.java b/src/main/java/com/replaymod/simplepathing/ReplayModSimplePathing.java index 0e62bc68..c5fd59ab 100644 --- a/src/main/java/com/replaymod/simplepathing/ReplayModSimplePathing.java +++ b/src/main/java/com/replaymod/simplepathing/ReplayModSimplePathing.java @@ -8,7 +8,6 @@ import com.replaymod.pathing.properties.TimestampProperty; import com.replaymod.replay.events.ReplayOpenEvent; import com.replaymod.replaystudio.pathing.PathingRegistry; 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.Interpolator; import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator; @@ -97,19 +96,12 @@ public class ReplayModSimplePathing implements PathingRegistry { @Override public Interpolator deserializeInterpolator(JsonReader reader) throws IOException { - AbstractInterpolator interpolator; String type = reader.nextString(); switch (type) { case "linear": - interpolator = new LinearInterpolator(); - interpolator.registerProperty(TimestampProperty.PROPERTY); - interpolator.registerProperty(CameraProperties.POSITION); - interpolator.registerProperty(CameraProperties.ROTATION); - return interpolator; + return new LinearInterpolator(); case "cubic-spline": - interpolator = new CubicSplineInterpolator(); - interpolator.registerProperty(CameraProperties.POSITION); - interpolator.registerProperty(CameraProperties.ROTATION); + return new CubicSplineInterpolator(); default: throw new IOException("Unknown interpolation type: " + type); diff --git a/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java b/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java index 3b8c16a7..4d881166 100644 --- a/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java +++ b/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java @@ -12,8 +12,8 @@ import com.replaymod.replay.ReplayHandler; import com.replaymod.replay.camera.CameraEntity; import com.replaymod.replay.gui.overlay.GuiReplayOverlay; 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.Interpolator; import com.replaymod.replaystudio.pathing.interpolation.LinearInterpolator; import com.replaymod.replaystudio.pathing.path.Keyframe; import com.replaymod.replaystudio.pathing.path.Path; @@ -302,23 +302,8 @@ public class GuiPathing { private void preparePathsForPlayback() { Timeline timeline = mod.getCurrentTimeline(); - Path timePath = timeline.getPaths().get(TIME_PATH); - Path positionPath = timeline.getPaths().get(POSITION_PATH); - - // 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(); + timeline.getPaths().get(TIME_PATH).updateAll(); + timeline.getPaths().get(POSITION_PATH).updateAll(); } public void zoomTimeline(double factor) { @@ -357,7 +342,24 @@ public class GuiPathing { } UpdateKeyframeProperties updateChange = builder.done(); updateChange.apply(timeline); - timeline.pushChange(CombinedChange.createFromApplied(change, updateChange)); + // 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)); + } } else { timeline.pushChange(change); }